Einfache Möglichkeit, einige Transformationen in eine Textdatei in Unity3d zu schreiben und zu lesen?
Dies ist ausschließlich in Unity3D, ich habe ein Array von 100Transform
,
Ich möchte diese in eine Datei auf dem PC-Desktop schreiben und später lesen.
Erwägen ..
// write to desktop...
string s = "";
for ( int i=0; i< sendMe.Length; ++i )
{
Transform tt = sendMe[i].transform;
s = s +tt.position.x +"," +tt.position.x +"," ...etc... "\n";
}
string d = System.Environment.GetFolderPath(
System.Environment.SpecialFolder.DesktopDirectory);
string path = System.IO.Path.Combine(d, "happyData.txt" );
System.IO.File.Delete(path);
System.IO.File.WriteAllText(path,s);
return;
.. und dann lesen Sie es auf ähnliche Weise, indem Sie das Textformat manuell analysieren. Etwas wie..
public ReadTrackFromDesktopFile()
{
GetSplineGetReady("development");
string tt = File.ReadAllText( .. path as above);
List<string> ts = new List<string>(
tt.Split(new string[] { "\r","\n" },
StringSplitOptions.RemoveEmptyEntries) );
foreach (string t in ts)
{
string[] parts = t.Split(',');
Vector3 pos = new Vector3(parts[0],parts[1],parts[2]);
Quaternion rot = new Quaternion(parts[3],parts[4],parts[5],parts[6]);
GetSplineOneNode(pos, rot);
}
GetSplineFinalise();
}
Aber das scheint naiv. Was ist der "einfache Unity-Weg", um dies zu tun?