PixelCrushers.DialogueSystem.PersistentDataManager Class Reference

A static class for saving and loading game data using the Dialogue System's Lua environment. More...

Classes

class  AsyncRawDataOperation
 
class  AsyncSaveOperation
 

Public Types

enum  RecordPersistentDataOn { AllGameObjects , OnlyRegisteredGameObjects , NoGameObjects }
 

Static Public Member Functions

static void RegisterPersistentData (GameObject go)
 
static void UnregisterPersistentData (GameObject go)
 
static void Reset (DatabaseResetOptions databaseResetOptions)
 Resets the Lua environment – for example, when starting a new game.
 
static void Reset ()
 Resets the Lua environment – for example, when starting a new game – keeping all loaded database in memory and just resetting them.
 
static void Record ()
 Sends the OnRecordPersistentData message to all GameObjects in the scene to give them an opportunity to record their state in the Lua environment.
 
static void Apply ()
 Sends the OnApplyPersistentData message to all game objects in the scene to give them an opportunity to retrieve their state from the Lua environment.
 
static void LevelWillBeUnloaded ()
 Sends the OnLevelWillBeUnloaded message to all game objects in the scene in case they need to change their behavior.
 
static void ApplySaveData (string saveData, DatabaseResetOptions databaseResetOptions=DatabaseResetOptions.KeepAllLoaded)
 Loads a saved game by applying a saved-game string.
 
static void ApplyLuaInternal (string saveData, bool allowExceptions=false)
 Loads data into the Lua environment.
 
static string GetSaveData ()
 Saves a game by retrieving the Lua environment and returning it as a saved-game string.
 
static void AppendDialogueSystemData (StringBuilder sb)
 
static void AppendVariableData (StringBuilder sb)
 Appends the user variable table to a (saved-game) string.
 
static void AppendItemData (StringBuilder sb)
 Appends the item table to a (saved-game) string.
 
static void AppendLocationData (StringBuilder sb)
 Appends the location table to a (saved-game) string.
 
static void AppendActorData (StringBuilder sb)
 Appends the actor table to a (saved-game) string.
 
static void AppendRelationshipAndStatusTables (StringBuilder sb)
 Appends the relationship and status tables to a (saved-game) string.
 
static void RefreshRelationshipAndStatusTablesFromLua ()
 Instructs the Dialogue System to refresh its internal relationship and status tables from the values in the Lua environment.
 
static void AppendConversationData (StringBuilder sb)
 Appends the conversation table to a (saved-game) string.
 
static void AppendSimStatus (StringBuilder sb)
 Appends SimStatus for all conversations.
 
static void ExpandCompressedSimStatusData ()
 When reapplying saved data, expands compress SimX info into conversations' SimStatus tables.
 
static void InitializeNewVariablesFromDatabase ()
 Instructs the Dialogue System to add any missing variables that are in the master database but not in Lua.
 
static void InitializeNewActorFieldsFromDatabase ()
 Adds any new actors or actor fields that were not in the saved data.
 
static void InitializeNewQuestEntriesFromDatabase ()
 Instructs the Dialogue System to add any missing quests and entries that are in the master database but not in Lua.
 
static void InitializeNewSimStatusFromDatabase ()
 Initializes SimStatus for entries that were added to the database after the saved game.
 
static AsyncSaveOperation GetSaveDataAsync ()
 
static void RecordAsync ()
 Sends the OnRecordPersistentData message to all game objects in the scene to give them an opportunity to record their state in the Lua environment.
 
static byte[] GetRawData ()
 
static AsyncRawDataOperation GetRawDataAsync ()
 
static void ApplyRawData (byte[] bytes)
 

Static Public Attributes

static bool includeActorData = true
 Set true to include actor data in save data, false to exclude.
 
static bool includeAllItemData = false
 Set this true to include all item fields in saved-game data.
 
static bool includeLocationData = false
 Set true to include location data in save data, false to exclude.
 
static bool includeAllConversationFields = false
 Set true to include all conversation fields, false to exclude.
 
static bool includeSimStatus = false
 Set this true to exclude Conversation[#].Dialog[#].SimStatus values from saved-game data.
 
static string saveConversationSimStatusWithField = string.Empty
 Optional field to use when saving a conversation's SimStatus info (e.g., Title).
 
static string saveDialogueEntrySimStatusWithField = string.Empty
 Optional field to use when saving a dialogue entry's SimStatus info (e.g,.
 
static bool includeRelationshipAndStatusData = true
 Set true to include the status & relationship tables in save data, false to exclude.
 
static bool initializeNewVariables = true
 Initialize variables and quests that were added to database after saved game.
 
static bool initializeNewSimStatus = true
 Initialize new SimStatus values for entries that were added to database after saved game.
 
static GetCustomSaveDataDelegate GetCustomSaveData = null
 PersistentDataManager will call this delegate (if set) to add custom data to the saved-game data string.
 
static RecordPersistentDataOn recordPersistentDataOn = RecordPersistentDataOn.AllGameObjects
 
static int asyncGameObjectBatchSize = 1000
 
static int asyncDialogueEntryBatchSize = 100
 

Detailed Description

A static class for saving and loading game data using the Dialogue System's Lua environment.

It allows you to save or load a game with a single line of code.

For more information, see saveLoadSystem

Member Enumeration Documentation

◆ RecordPersistentDataOn

Enumerator
AllGameObjects 

Inform all components on all GameObjects in the scene to record their persistent data if supported.

OnlyRegisteredGameObjects 

Inform only components that have registered to receive notifications to record their persistent data.

NoGameObjects 

Entirely skip informing any GameObjects to record their persistent data.

Member Function Documentation

◆ AppendActorData()

static void PixelCrushers.DialogueSystem.PersistentDataManager.AppendActorData ( StringBuilder  sb)
inlinestatic

Appends the actor table to a (saved-game) string.

◆ AppendConversationData()

static void PixelCrushers.DialogueSystem.PersistentDataManager.AppendConversationData ( StringBuilder  sb)
inlinestatic

Appends the conversation table to a (saved-game) string.

To conserve space, only the SimStatus is recorded. If includeSimStatus is false, nothing is recorded. The exception is if includeAllConversationFields is true.

◆ AppendDialogueSystemData()

static void PixelCrushers.DialogueSystem.PersistentDataManager.AppendDialogueSystemData ( StringBuilder  sb)
inlinestatic

◆ AppendItemData()

static void PixelCrushers.DialogueSystem.PersistentDataManager.AppendItemData ( StringBuilder  sb)
inlinestatic

Appends the item table to a (saved-game) string.

◆ AppendLocationData()

static void PixelCrushers.DialogueSystem.PersistentDataManager.AppendLocationData ( StringBuilder  sb)
inlinestatic

Appends the location table to a (saved-game) string.

Currently doesn't save anything unless includeLocationData is true.

◆ AppendRelationshipAndStatusTables()

static void PixelCrushers.DialogueSystem.PersistentDataManager.AppendRelationshipAndStatusTables ( StringBuilder  sb)
inlinestatic

Appends the relationship and status tables to a (saved-game) string.

Parameters
sbStringBuilder to append to.

◆ AppendSimStatus()

static void PixelCrushers.DialogueSystem.PersistentDataManager.AppendSimStatus ( StringBuilder  sb)
inlinestatic

Appends SimStatus for all conversations.

◆ AppendVariableData()

static void PixelCrushers.DialogueSystem.PersistentDataManager.AppendVariableData ( StringBuilder  sb)
inlinestatic

Appends the user variable table to a (saved-game) string.

◆ Apply()

static void PixelCrushers.DialogueSystem.PersistentDataManager.Apply ( )
inlinestatic

Sends the OnApplyPersistentData message to all game objects in the scene to give them an opportunity to retrieve their state from the Lua environment.

If calling this after loading a new scene, you may want to wait one frame to allow other GameObject's Start methods to complete first. You can limit which GameObjects receive messages by changing recordPersistentDataOn.

◆ ApplyLuaInternal()

static void PixelCrushers.DialogueSystem.PersistentDataManager.ApplyLuaInternal ( string  saveData,
bool  allowExceptions = false 
)
inlinestatic

Loads data into the Lua environment.

Parameters
saveData
allowExceptions

◆ ApplyRawData()

static void PixelCrushers.DialogueSystem.PersistentDataManager.ApplyRawData ( byte[]  bytes)
inlinestatic

◆ ApplySaveData()

static void PixelCrushers.DialogueSystem.PersistentDataManager.ApplySaveData ( string  saveData,
DatabaseResetOptions  databaseResetOptions = DatabaseResetOptions::KeepAllLoaded 
)
inlinestatic

Loads a saved game by applying a saved-game string.

Parameters
saveDataA saved-game string previously returned by GetSaveData().
databaseResetOptionsDatabase reset options.

◆ ExpandCompressedSimStatusData()

static void PixelCrushers.DialogueSystem.PersistentDataManager.ExpandCompressedSimStatusData ( )
inlinestatic

When reapplying saved data, expands compress SimX info into conversations' SimStatus tables.

◆ GetRawData()

static byte[] PixelCrushers.DialogueSystem.PersistentDataManager.GetRawData ( )
inlinestatic

◆ GetRawDataAsync()

static AsyncRawDataOperation PixelCrushers.DialogueSystem.PersistentDataManager.GetRawDataAsync ( )
inlinestatic

◆ GetSaveData()

static string PixelCrushers.DialogueSystem.PersistentDataManager.GetSaveData ( )
inlinestatic

Saves a game by retrieving the Lua environment and returning it as a saved-game string.

This method calls Record() to allow all game objects in the scene to record their state to the Lua environment first. The returned string is human-readable Lua code.

Returns
The saved-game data.

To reduce saved-game data size, only the following information is recorded from the Chat Mapper tables (Item[], Actor[], etc):

  • Actor[]: all data
  • Item[]: only State (for quest log system)
  • Location[]: nothing
  • Variable[]: current value of each variable
  • Conversation[]: SimStatus
  • Relationship and status information is recorded

◆ GetSaveDataAsync()

static AsyncSaveOperation PixelCrushers.DialogueSystem.PersistentDataManager.GetSaveDataAsync ( )
inlinestatic

◆ InitializeNewActorFieldsFromDatabase()

static void PixelCrushers.DialogueSystem.PersistentDataManager.InitializeNewActorFieldsFromDatabase ( )
inlinestatic

Adds any new actors or actor fields that were not in the saved data.

◆ InitializeNewQuestEntriesFromDatabase()

static void PixelCrushers.DialogueSystem.PersistentDataManager.InitializeNewQuestEntriesFromDatabase ( )
inlinestatic

Instructs the Dialogue System to add any missing quests and entries that are in the master database but not in Lua.

◆ InitializeNewSimStatusFromDatabase()

static void PixelCrushers.DialogueSystem.PersistentDataManager.InitializeNewSimStatusFromDatabase ( )
inlinestatic

Initializes SimStatus for entries that were added to the database after the saved game.

◆ InitializeNewVariablesFromDatabase()

static void PixelCrushers.DialogueSystem.PersistentDataManager.InitializeNewVariablesFromDatabase ( )
inlinestatic

Instructs the Dialogue System to add any missing variables that are in the master database but not in Lua.

◆ LevelWillBeUnloaded()

static void PixelCrushers.DialogueSystem.PersistentDataManager.LevelWillBeUnloaded ( )
inlinestatic

Sends the OnLevelWillBeUnloaded message to all game objects in the scene in case they need to change their behavior.

For example, scripts that do something special when destroyed during play may not want to do the same thing when being destroyed by a level unload.

◆ Record()

static void PixelCrushers.DialogueSystem.PersistentDataManager.Record ( )
inlinestatic

Sends the OnRecordPersistentData message to all GameObjects in the scene to give them an opportunity to record their state in the Lua environment.

You can limit which GameObjects receive messages by changing recordPersistentDataOn.

◆ RecordAsync()

static void PixelCrushers.DialogueSystem.PersistentDataManager.RecordAsync ( )
inlinestatic

Sends the OnRecordPersistentData message to all game objects in the scene to give them an opportunity to record their state in the Lua environment.

Runs in batches specified by the value of asyncGameObjectBatchSize.

◆ RefreshRelationshipAndStatusTablesFromLua()

static void PixelCrushers.DialogueSystem.PersistentDataManager.RefreshRelationshipAndStatusTablesFromLua ( )
inlinestatic

Instructs the Dialogue System to refresh its internal relationship and status tables from the values in the Lua environment.

Call this after putting new values in the Lua environment, such as when loading a saved game.

◆ RegisterPersistentData()

static void PixelCrushers.DialogueSystem.PersistentDataManager.RegisterPersistentData ( GameObject  go)
inlinestatic
Parameters
goGameObject that should receive notifications.

◆ Reset() [1/2]

static void PixelCrushers.DialogueSystem.PersistentDataManager.Reset ( )
inlinestatic

Resets the Lua environment – for example, when starting a new game – keeping all loaded database in memory and just resetting them.

◆ Reset() [2/2]

static void PixelCrushers.DialogueSystem.PersistentDataManager.Reset ( DatabaseResetOptions  databaseResetOptions)
inlinestatic

Resets the Lua environment – for example, when starting a new game.

Parameters
databaseResetOptionsThe database reset options can be:
  • RevertToDefault: Removes all but the default database, then resets it.
  • KeepAllLoaded: Keeps all loaded databases in memory and just resets them.

◆ UnregisterPersistentData()

static void PixelCrushers.DialogueSystem.PersistentDataManager.UnregisterPersistentData ( GameObject  go)
inlinestatic
Parameters
goGameObject that should no longer receive notifications.

Member Data Documentation

◆ asyncDialogueEntryBatchSize

int PixelCrushers.DialogueSystem.PersistentDataManager.asyncDialogueEntryBatchSize = 100
static

◆ asyncGameObjectBatchSize

int PixelCrushers.DialogueSystem.PersistentDataManager.asyncGameObjectBatchSize = 1000
static

◆ GetCustomSaveData

GetCustomSaveDataDelegate PixelCrushers.DialogueSystem.PersistentDataManager.GetCustomSaveData = null
static

PersistentDataManager will call this delegate (if set) to add custom data to the saved-game data string.

The custom data should be valid Lua code.

◆ includeActorData

bool PixelCrushers.DialogueSystem.PersistentDataManager.includeActorData = true
static

Set true to include actor data in save data, false to exclude.

◆ includeAllConversationFields

bool PixelCrushers.DialogueSystem.PersistentDataManager.includeAllConversationFields = false
static

Set true to include all conversation fields, false to exclude.

◆ includeAllItemData

bool PixelCrushers.DialogueSystem.PersistentDataManager.includeAllItemData = false
static

Set this true to include all item fields in saved-game data.

This is false by default to minimize the size of the saved-game data by only recording State and Track (for quests).

◆ includeLocationData

bool PixelCrushers.DialogueSystem.PersistentDataManager.includeLocationData = false
static

Set true to include location data in save data, false to exclude.

◆ includeRelationshipAndStatusData

bool PixelCrushers.DialogueSystem.PersistentDataManager.includeRelationshipAndStatusData = true
static

Set true to include the status & relationship tables in save data, false to exclude.

◆ includeSimStatus

bool PixelCrushers.DialogueSystem.PersistentDataManager.includeSimStatus = false
static

Set this true to exclude Conversation[#].Dialog[#].SimStatus values from saved-game data.

If you don't use SimStatus in your Lua conditions, there's no need to save it.

◆ initializeNewSimStatus

bool PixelCrushers.DialogueSystem.PersistentDataManager.initializeNewSimStatus = true
static

Initialize new SimStatus values for entries that were added to database after saved game.

◆ initializeNewVariables

bool PixelCrushers.DialogueSystem.PersistentDataManager.initializeNewVariables = true
static

Initialize variables and quests that were added to database after saved game.

")]

◆ recordPersistentDataOn

RecordPersistentDataOn PixelCrushers.DialogueSystem.PersistentDataManager.recordPersistentDataOn = RecordPersistentDataOn.AllGameObjects
static

◆ saveConversationSimStatusWithField

string PixelCrushers.DialogueSystem.PersistentDataManager.saveConversationSimStatusWithField = string.Empty
static

Optional field to use when saving a conversation's SimStatus info (e.g., Title).

This feature is handy if you can't guarantee that conversation IDs will be the same across saved games. If set, saves the conversation's SimStatus info into a field. If blank, uses conversation ID.

◆ saveDialogueEntrySimStatusWithField

string PixelCrushers.DialogueSystem.PersistentDataManager.saveDialogueEntrySimStatusWithField = string.Empty
static

Optional field to use when saving a dialogue entry's SimStatus info (e.g,.

Title). This feature is handy if you can't guarantee that dialogue entry IDs will be the same across saved games. If set, saves the entry's SimStatus value into a field. If blank, uses entry's ID.


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