Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
splines from .txt files
#8
Try something like this (not tested, but may work):

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).
Reply


Messages In This Thread
splines from .txt files - by Lila - 04-30-2014, 01:18 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  New User Looking for Advice on Choosing Curvy Splines ravigupta 1 300 08-21-2026, 09:45 PM
Last Post: _Aka_
  Connections Between Opposing Splines lockiidraws 1 1,028 12-04-2025, 02:14 PM
Last Post: _Aka_
  Spawn at start/ end of splines rickgplus 4 3,607 03-21-2025, 12:34 PM
Last Post: _Aka_
  Any performance 'hacks' for scene with lots of splines rickgplus 1 2,227 03-18-2025, 10:11 PM
Last Post: _Aka_

Forum Jump: