PixelCrushers.DialogueSystem.GameSaver Class Reference

Allows you to save and load games to PlayerPrefs without writing any scripts. More...

Inheritance diagram for PixelCrushers.DialogueSystem.GameSaver:
Collaboration diagram for PixelCrushers.DialogueSystem.GameSaver:

Public Types

enum  FunctionOnUse { FunctionOnUse.None, FunctionOnUse.Save, FunctionOnUse.Load, FunctionOnUse.Restart }
 

Public Member Functions

void Awake ()
 
void OnUse ()
 Upon receiving an "OnUse" message, this method saves, loads, or does nothing, based on the value of functionOnUse. More...
 
void SaveGame (int slot)
 Saves the game under the PlayerPrefs key, adding the slot number to support multiple save game slots. More...
 
void SaveGame ()
 Saves the game in default slot 0. More...
 
void LoadGame (int slot)
 Loads the game from the data saved under the PlayerPrefs key. More...
 
void LoadGame ()
 Loads the game from default slot 0. More...
 
void SaveGame (string slotString)
 Saves the game using a string parameter for the slot number. More...
 
void LoadGame (string slotString)
 Loads the game using a string parameter for the slot number. More...
 
void RestartGame ()
 Restarts the game. More...
 
void Record ()
 Records the state of the game. More...
 
void Apply ()
 Applies the recorded state of the game to the current scene. More...
 

Public Attributes

string playerPrefsKey = "savedgame"
 The root of the PlayerPrefs key where the game will be saved and loaded. More...
 
int slot = 0
 The default slot. More...
 
FunctionOnUse functionOnUse = FunctionOnUse.None
 The function (save or load) to perform when receiving the "OnUse" message. More...
 
bool includeAllItemData = false
 If true, saved-game data will include all item fields. More...
 
bool includeLocationData = false
 If true, saved-game data will include all location fields. More...
 
bool includeSimStatus = false
 If true, saved-game data will include the offered/spoken status of all dialogue entries. More...
 
string startingLevel = string.Empty
 The starting level to use when restarting the game. More...
 
bool dontDestroyOnLoad = false
 If true, this game object isn't destroyed when you load a new level. More...
 
UnityEvent onSaveStart = new UnityEvent()
 
UnityEvent onSaveEnd = new UnityEvent()
 
UnityEvent onLoadStart = new UnityEvent()
 
UnityEvent onLoadEnd = new UnityEvent()
 

Detailed Description

Allows you to save and load games to PlayerPrefs without writing any scripts.

To use this component:

  1. Add this component to a game object.
  2. Set the playerPrefs key (i.e., saved game slot) where the game will be saved and loaded. To make multiple slots, you can add more GamerSaver components to change the playerPrefsKey field.
  3. To save a game, send the message "SaveGame" to this component (or call it from a script). For example, you can use the SendMessageOnConversation component to send the message.
  4. To load a game, send the message "LoadGame" to this component (or call it from a script).
  5. To restart the game, send the message "RestartGame" (or call it from a script).
  6. To record the state of the game without saving, for example when changing levels, send the "Record" message.
  7. To apply the saved state of the game, for example when returning to a level, send the "Apply" message.
  8. You can also configure this component to save or load when the player "uses" the game object. To do this:
    • Set Function On Use to Save or Load. This tells the component whether to save or load when it receives an OnUse message.
    • Send the message "OnUse" to this component or game object. For example, the sample Selector component sends OnUse when the player hits spacebar over the object.
  9. If you tick Apply Game State When Loading Levels, then this component will automatically apply the recorded game state as soon as the level is loaded. You're responsible for issuing the "Record" message before loading the level. You can use PersistentDataManager to do this.
  10. If the scene contains a LevelManager, it will load using the LevelManager instead of just applying the saved-game data.

Member Enumeration Documentation

◆ FunctionOnUse

Enumerator
None 
Save 
Load 
Restart 

Member Function Documentation

◆ Apply()

void PixelCrushers.DialogueSystem.GameSaver.Apply ( )

Applies the recorded state of the game to the current scene.

◆ Awake()

void PixelCrushers.DialogueSystem.GameSaver.Awake ( )

◆ LoadGame() [1/3]

void PixelCrushers.DialogueSystem.GameSaver.LoadGame ( )

Loads the game from default slot 0.

◆ LoadGame() [2/3]

void PixelCrushers.DialogueSystem.GameSaver.LoadGame ( int  slot)

Loads the game from the data saved under the PlayerPrefs key.

◆ LoadGame() [3/3]

void PixelCrushers.DialogueSystem.GameSaver.LoadGame ( string  slotString)

Loads the game using a string parameter for the slot number.

Parameters
slotStringSlot string to convert to an int.

◆ OnUse()

void PixelCrushers.DialogueSystem.GameSaver.OnUse ( )

Upon receiving an "OnUse" message, this method saves, loads, or does nothing, based on the value of functionOnUse.

◆ Record()

void PixelCrushers.DialogueSystem.GameSaver.Record ( )

Records the state of the game.

◆ RestartGame()

void PixelCrushers.DialogueSystem.GameSaver.RestartGame ( )

Restarts the game.

◆ SaveGame() [1/3]

void PixelCrushers.DialogueSystem.GameSaver.SaveGame ( )

Saves the game in default slot 0.

◆ SaveGame() [2/3]

void PixelCrushers.DialogueSystem.GameSaver.SaveGame ( int  slot)

Saves the game under the PlayerPrefs key, adding the slot number to support multiple save game slots.

Parameters
slotThe slot to use.

◆ SaveGame() [3/3]

void PixelCrushers.DialogueSystem.GameSaver.SaveGame ( string  slotString)

Saves the game using a string parameter for the slot number.

Parameters
slotStringSlot string to convert to an int.

Member Data Documentation

◆ dontDestroyOnLoad

bool PixelCrushers.DialogueSystem.GameSaver.dontDestroyOnLoad = false

If true, this game object isn't destroyed when you load a new level.

◆ functionOnUse

FunctionOnUse PixelCrushers.DialogueSystem.GameSaver.functionOnUse = FunctionOnUse.None

The function (save or load) to perform when receiving the "OnUse" message.

◆ includeAllItemData

bool PixelCrushers.DialogueSystem.GameSaver.includeAllItemData = false

If true, saved-game data will include all item fields.

If false, it will only include quests' State and Track fields.

◆ includeLocationData

bool PixelCrushers.DialogueSystem.GameSaver.includeLocationData = false

If true, saved-game data will include all location fields.

If false, it will not include any location fields.

◆ includeSimStatus

bool PixelCrushers.DialogueSystem.GameSaver.includeSimStatus = false

If true, saved-game data will include the offered/spoken status of all dialogue entries.

◆ onLoadEnd

UnityEvent PixelCrushers.DialogueSystem.GameSaver.onLoadEnd = new UnityEvent()

◆ onLoadStart

UnityEvent PixelCrushers.DialogueSystem.GameSaver.onLoadStart = new UnityEvent()

◆ onSaveEnd

UnityEvent PixelCrushers.DialogueSystem.GameSaver.onSaveEnd = new UnityEvent()

◆ onSaveStart

UnityEvent PixelCrushers.DialogueSystem.GameSaver.onSaveStart = new UnityEvent()

◆ playerPrefsKey

string PixelCrushers.DialogueSystem.GameSaver.playerPrefsKey = "savedgame"

The root of the PlayerPrefs key where the game will be saved and loaded.

◆ slot

int PixelCrushers.DialogueSystem.GameSaver.slot = 0

The default slot.

This number is appended to playerPrefsKey to make the complete PlayerPrefs key.

◆ startingLevel

string PixelCrushers.DialogueSystem.GameSaver.startingLevel = string.Empty

The starting level to use when restarting the game.


The documentation for this class was generated from the following file: