Ejemplo n.º 1
0
    /// <summary>
    /// Loads the player's statistics from a file called savegame.sp.
    /// </summary>
    public static PlayerData LoadGame()
    {
        string path = Application.persistentDataPath + "/savegame.sp";

        if (File.Exists(path))
        {
            BinaryFormatter formatter = new BinaryFormatter();
            FileStream      stream    = new FileStream(path, FileMode.Open);
            PlayerData      data      = (PlayerData)formatter.Deserialize(stream);
            stream.Close();

            //load the setting in from the file
            GameGlobals.LoadPlayer(data.playerLevel, data.currentXp, data.xpLeft);
            return(data);
        }
        else
        {
            Debug.Log("File not found.");
            return(null);
        }
    }