05-22-2014, 02:30 PM
Try something like this (not tested, but may work):
Also, a good idea is to name and capitalize classes properly (almost everyone would name "readTXT" ReadTxt, or even better something like FileToSpline, which is more descriptive).
Code:
public class readTXT : MonoBehaviour {
public CurvySpline Spline;
public TextAsset track;
public void ReadPoints()
{
Spline.Clear();
string[] dataLines = track.text.Split('\n');
List<Vector3>Points= new List<Vector3>();
int lineNum = 0;
foreach (string line in dataLines)
{
string[] vec3string=line.Split(' ');
Points.Add(new Vector3(float.Parse(vec3string[0]),float.Parse(vec3string[1]),float.Parse(vec3string[2])));
}
Spline.Add(Points);
}
}
[CustomEditor( typeof( readTXT ) )]
public class Read : Editor
{
public readTXT Target { get { return target as readTXT;}}
public override void OnInspectorGUI()
{
base.OnInspectorGUI ();
EditorGUILayout.LabelField ( "Spine Reader" );
if( GUILayout.Button ( "READ!"))
Target.ReadPoints();
}
}
Also, a good idea is to name and capitalize classes properly (almost everyone would name "readTXT" ReadTxt, or even better something like FileToSpline, which is more descriptive).