示例#1
0
 public static void Reset()
 {
     BinaryFormatter bf = new BinaryFormatter();
     FileStream file = File.Create(Path.Combine(Application.persistentDataPath, filename));
     HighScoresData data = new HighScoresData();
     data.turns = new int[] { 0, 0, 0 };
     data.coins = new int[] { 0, 0, 0 };
     bf.Serialize(file, data);
     file.Close();
 }
示例#2
0
    public void Load()
    {
        if (File.Exists(Application.persistentDataPath + "/highscore.hs"))
        {
            BinaryFormatter bf   = new BinaryFormatter();
            FileStream      file = File.Open(Application.persistentDataPath + "/highscore.hs", FileMode.Open);

            HighScoresData data = (HighScoresData)bf.Deserialize(file);
            file.Close();

            Highscore = data.Highscore;
        }
        else
        {
            Highscore = 0;
        }
    }
示例#3
0
    public static HighScoresData Load()
    {
        if (File.Exists(SAVE_FILE_ABSOLUTE_PATH))
        {
            BinaryFormatter formatter = new BinaryFormatter();
            FileStream      stream    = new FileStream(SAVE_FILE_ABSOLUTE_PATH, FileMode.Open);

            HighScoresData scoreData = formatter.Deserialize(stream) as HighScoresData;
            stream.Close();

            return(scoreData);
        }
        else
        {
            Debug.Log("High scores save file: " + SAVE_FILE_ABSOLUTE_PATH + "  not found!");
            return(null);
        }
    }
示例#4
0
 static HighScoresData Load()
 {
     //No file exists
     if(File.Exists(Path.Combine(Application.persistentDataPath,filename)) == false){
         HighScoresData h = new HighScoresData();
         h.turns = new int[] { 0, 0, 0 };
         h.coins = new int[] { 0, 0, 0 };
         return h;
     }
     else
     {
         try
         {
             BinaryFormatter bf = new BinaryFormatter();
             FileStream file = File.Open(Path.Combine(Application.persistentDataPath, filename), FileMode.Open);
             HighScoresData h = bf.Deserialize(file) as HighScoresData;
             file.Close();
             return h;
         }
         catch (Exception e)
         {
             Debug.Log(e.Message);
             HighScoresData h = new HighScoresData();
             h.coins = new int[] { 0, 0, 0 };
             h.turns = new int[] { 0, 0, 0 };
             return h;
         }
     }
 }
示例#5
0
 static void Save(HighScoresData data)
 {
     BinaryFormatter bf = new BinaryFormatter();
     FileStream file = File.Create(Path.Combine(Application.persistentDataPath,filename));
     bf.Serialize(file, data);
     file.Close();
 }