Пример #1
0
    public static void Load()
    {
        if (File.Exists(Application.persistentDataPath + Path.DirectorySeparatorChar + "savedata.upc"))                                     // If exist any savedata
        {
            BinaryFormatter bf   = new BinaryFormatter();                                                                                   // Serialization work
            FileStream      file = File.Open(Application.persistentDataPath + Path.DirectorySeparatorChar + "savedata.upc", FileMode.Open); // Open the file savegame.gd in unity's path by default -> you can put any extension
            // 1. Search the file in the path
            // 2. Cast the binary file to our class
            // 3. Put it in our list
            Serialization.savedGames = (List <DataGame>)bf.Deserialize(file);
            file.Close();

            // Set the last saved datagame
            GameManager.SetDataGame(savedGames[savedGames.Count - 1]);
            Sc_Global.SetDataGame(savedGames[savedGames.Count - 1]);
            BehaviourObjects.SetDataGame(savedGames[savedGames.Count - 1]);
        }
    }