コード例 #1
0
    //Save our high scores to the data class, then serialise it.
    public void Save(string playerName)
    {
        data = new HighSaveData();

        saveToData();

        string fileName = Application.persistentDataPath + "/HighScores.gd";

        Debug.Log(fileName);

        BinaryFormatter bf   = new BinaryFormatter();
        FileStream      file = File.Create(fileName);

        bf.Serialize(file, data);
        file.Close();
    }
コード例 #2
0
    //Deserialise and load the file.
    public bool Load()
    {
        data = new HighSaveData();

        string fileName = Application.persistentDataPath + "/HighScores.gd";

        if (File.Exists(fileName))
        {
            BinaryFormatter bf   = new BinaryFormatter();
            FileStream      file = File.Open(fileName, FileMode.Open);
            data = (HighSaveData)bf.Deserialize(file);
            file.Close();
            loadFromData();
            return(true);
        }
        return(false);
    }