Пример #1
0
    public static SongClass LoadSongData(string _songName)
    {
        string path = Application.persistentDataPath + "/songRecord/" + _songName + ".rec";

        if (File.Exists(path))
        {
            BinaryFormatter formatter = new BinaryFormatter();
            FileStream      stream    = new FileStream(path, FileMode.Open,
                                                       FileAccess.Read,
                                                       FileShare.Read);
            stream.Position = 0;

            SongClass data = new SongClass();

            stream.Seek(0, SeekOrigin.Begin);

            data = formatter.Deserialize(stream) as SongClass;
            stream.Close();


            return(data);
        }
        else
        {
            Debug.Log("Load Error");
            return(null);
        }
    }
Пример #2
0
    public static void SaveSongData(SongClass song)
    {
        BinaryFormatter formatter = new BinaryFormatter();

        string path = Application.persistentDataPath + "/songRecord";

        if (!Directory.Exists(path))
        {
            Directory.CreateDirectory(path);
        }
        path += "/" + song.SongName + ".rec";
        //string path = Application.persistentDataPath + "/songRecord/" +song.SongName+ ".rec";

        FileStream stream = new FileStream(path,
                                           FileMode.Create,
                                           FileAccess.Write, FileShare.None);

        SongClass data = new SongClass(song);

        stream.Seek(0, SeekOrigin.Begin);

        formatter.Serialize(stream, data);
        stream.Close();
        stream.Dispose();
    }
Пример #3
0
 public SongClass(SongClass _song)
 {
     SongName       = _song.SongName;
     BestScore      = _song.BestScore;
     BestPercentage = _song.BestPercentage;
     SongFilePath   = _song.SongFilePath;
 }