Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
splines from .txt files
#10
Ok, that's the problem when writing code out of the head without testing it. Spline.Add() takes an array only, so instead of a list you could use an array, though I prefer lists when timing isn't critical due to ease of use. It turns out that you can solve your problem with incredible few lines of code. Note that Unity features a TextAsset that I'm using here (it's the easiest way to read a string from a file in Unity and you can drag&drop them from the project window):


Code:
public void ReadFile()
{
if (mSpline && File)
{
mSpline.Clear();
string lines = File.text.Split('\n');
List<Vector3> Points = new List<Vector3>;();

foreach (var line in lines)
{
string coords = line.Split(' ');
Points.Add(new Vector3(float.Parse(coords[0]), float.Parse(coords[1]), float.Parse(coords[2])));
}

mSpline.Add(Points.ToArray());
}
}

I've attached the script, it's editor script and a textfile with your data in the package. Just create an empty GameObject, drag&drop SplineFromFile to it, select the textfile and hit the button.

Cheers
Jake

 

 

 

 

 


Attached Files
.zip   SplineFromFile.zip (Size: 2.89 KB / Downloads: 10)
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
Information New free asset: Converter For Unity Splines _Aka_ 5 19 04-25-2024, 11:11 AM
Last Post: _Aka_
  snap to the curve created by the curvy splines segment points ShiroeYamamoto 3 11 04-02-2024, 02:24 PM
Last Post: _Aka_
Bug Changing spline connection in inspector causes splines to revert to defaults lacota 3 6 03-18-2024, 07:55 PM
Last Post: _Aka_
  Using Unity's SplineContainer in Curvy Splines dlees9191 3 15 02-26-2024, 09:49 AM
Last Post: _Aka_

Forum Jump: