Browse Source

Tidied up save/load methods.

master
chrisgregan 11 years ago
parent
commit
1835d9401e
  1. 11
      Assets/Fungus/Scripts/Game.cs
  2. 2
      Assets/Fungus/Scripts/GameController.cs
  3. 2
      Assets/Fungus/Scripts/SceneLoader.cs
  4. 5
      Assets/Fungus/Scripts/Variables.cs

11
Assets/Fungus/Scripts/Game.cs

@ -186,19 +186,18 @@ namespace Fungus
} }
/** /**
* Save the current game state to persistant storage. * Save the current game variables to persistant storage.
* Only the values, string table and current scene are stored. * Store the currently loaded scene name so that Game.LoadGame() can automatically move to the appropriate scene.
* @param saveName The name of the saved game data.
*/ */
[Obsolete("Use Variables.Save() instead.")] public void SaveGame()
public void SaveGame(string saveName)
{ {
SetString("_scene", Application.loadedLevelName);
Variables.Save(); Variables.Save();
} }
/** /**
* Loads the current game state from persistant storage. * Loads the current game state from persistant storage.
* This will cause the scene specified in the "Fungus.Scene" string to be loaded. * This will cause the scene specified in the "_scene" string to be loaded.
* Each scene in your game should contain the necessary code to restore the current game state based on saved data. * Each scene in your game should contain the necessary code to restore the current game state based on saved data.
* @param saveName The name of the saved game data. * @param saveName The name of the saved game data.
*/ */

2
Assets/Fungus/Scripts/GameController.cs

@ -101,7 +101,7 @@ namespace Fungus
{ {
CommandQueue commandQueue = Game.GetInstance().commandQueue; CommandQueue commandQueue = Game.GetInstance().commandQueue;
commandQueue.AddCommand(new Command.Call(delegate { commandQueue.AddCommand(new Command.Call(delegate {
Variables.Save(); Game.GetInstance().SaveGame();
})); }));
} }

2
Assets/Fungus/Scripts/SceneLoader.cs

@ -82,7 +82,7 @@ namespace Fungus
Game game = Game.GetInstance(); Game game = Game.GetInstance();
if (game != null) if (game != null)
{ {
Variables.Save(); Game.Save();
} }
} }

5
Assets/Fungus/Scripts/Variables.cs

@ -22,12 +22,11 @@ namespace Fungus
} }
/** /**
* Save the variable state to persistent storage. * Save the variables state to persistent storage.
* The currently loaded scene name is stored so that Game.LoadGame() will automatically move to the appropriate scene.
*/ */
static public void Save() static public void Save()
{ {
SetString("_scene", Application.loadedLevelName);
PlayerPrefs.Save(); PlayerPrefs.Save();
} }

Loading…
Cancel
Save