Ejemplo n.º 1
0
    public static Track LoadTrack(string name)
    {
        BinaryFormatter bf   = new BinaryFormatter();
        FileStream      file = File.Open(Application.persistentDataPath + "/Tracks/" + name + ".trk", FileMode.Open);

        try
        {
            SaveableTrack saveableTrack = (SaveableTrack)bf.Deserialize(file);
            file.Close();
            Texture2D tex = new Texture2D(saveableTrack.texWidth, saveableTrack.texHeight, TextureFormat.ARGB32, false);
            tex.LoadImage(saveableTrack.texture);
            tex.Apply();
            List <Vector3> trackpoints = new List <Vector3>();
            for (int i = 0; i < saveableTrack.trackPoints.Length; i++)
            {
                trackpoints.Add(saveableTrack.trackPoints[i].GetVector3());
            }

            Track track = new Track(saveableTrack.name, tex, trackpoints);
            file.Close();
            return(track);
        }
        catch (System.Exception e)
        {
            file.Close();
            Debug.Log(e);
            return(null);
        }
    }
Ejemplo n.º 2
0
 public static bool SaveTrack(Track track)
 {
     try
     {
         SaveableTrack   saveableTrack = new SaveableTrack(track.trackName, track.texture, track.trackPoints);
         BinaryFormatter bf            = new BinaryFormatter();
         Directory.CreateDirectory(Application.persistentDataPath + "/Tracks/");
         FileStream file = File.Create(Application.persistentDataPath + "/Tracks/" + saveableTrack.name + ".trk");
         bf.Serialize(file, saveableTrack);
         file.Close();
         return(true);
     }
     catch (System.Exception e)
     {
         Debug.Log(e);
         return(false);
     }
 }