public sealed class BinarySerializerPersistentStateManager : MonoBehaviour, IPersistentStateManager
An implementation of an IPersistentStateManager that uses binary serialization to save/load persistent data related to the Streamable Assets Manager.
Name | Type | Description |
---|---|---|
DisableAutoInvocationOfBeforeAndAfterLoadMethods | bool |
By default, when the Component Manager's Load method is called, it will automatically
call
OnBeforeDataLoaded before calling the Load... methods, and then it will automatically
call OnAfterDataLoaded
after all data has been loaded. In some instances, this may be undesirable, for instance
if you want to
load non Streamable Assets Manager data before or after the Component Manager's Load
method is called.
|
DisableAutoInvocationOfBeforeAndAfterSaveMethods | bool |
By default, when the Component Manager's Save method is called, it will automatically
call
OnBeforeDataSaved before calling the Save... methods, and then it will automatically
call OnAfterDataSaved
after all data has been saved. In some instances, this may be undesirable, for instance
if you want to
save non Streamable Assets Manager data before or after the Component Manager's Save
method is called.
|
FileExist | bool |
Gets a value indicating whether the save data file named FileName exists. This property will generate garbage as the full file path of the file needs to be generated each time it is called. Therefore, you should not call it repeatedly. |
FileName | string |
Gets or sets the file name that the manager should use to save/load data. If you are implementing a save system that uses multiple save files, you should set the FileName before beginning the Save and Load operations. |
FilePath | string |
Gets the full file path of the file. This will be equal to Application.persistentDataPath/FileName. The path needs to be generated each time this property is called, therefore it will generate garbage. You should store the returned value rather than calling the property repeatedly. |
bool LoadBool()
Loads a boolean value via BinaryReader.ReadBoolean
bool
The loaded boolean.
double LoadDouble()
Loads a double value via BinaryReader.ReadDouble
double
The loaded double.
float LoadFloat()
Loads a float value via BinaryReader.ReadSingle
float
The loaded float.
int LoadInt()
Loads a integer value via BinaryReader.ReadInt32
int
The loaded integer.
string LoadString()
Loads a string value via BinaryReader.ReadString
string
The loaded string.
void OnAfterDataLoaded()
Called after all data is loaded. The open BeinaryReader is closed along with the FileStream.
void OnBeforeDataLoaded()
Called before the Streamable Assets Manager begins the loading process. This opens the file which holds the save data, a file stream to read from, and a binary reader to read from the open stream.
Type | Condition |
---|---|
FileNotFoundException | Thrown when the file specified does not exist in Application.persistentDataPath. |
void OnBeforeDataSaved()
Called before the Streamable Assets Manager saves data via the Component Manager (happens
when Save or ConvertOldData is called).
This methods opens or creates a file named fileName at Application.persistentDataPath,
a stream to that file, and a binary writer for writing to the stream.
If Disable Auto Invocation Of Before And After SaveMethods is disabled in the inspector,
you will need to call this method manually before calling ComponentManager.Save
or ComponentManager.ConvertOldData.
void SaveBool(bool value)
Saves a boolean value to the FileStream via BinaryWriter.Write
Name | Type | Description |
---|---|---|
value | bool |
The bool to save. |
void SaveDouble(double value)
Saves a double value to the FileStream via BinaryWriter.Write
Name | Type | Description |
---|---|---|
value | double |
The double to save. |
void SaveFloat(float value)
Saves a float value to the FileStream via BinaryWriter.Write
Name | Type | Description |
---|---|---|
value | float |
The float to save. |
void SaveInt(int value)
Saves an integer value to the FileStream via BinaryWriter.Write
Name | Type | Description |
---|---|---|
value | int |
The integer to save. |
void SaveString(string value)
Saves a string value to the FileStream via BinaryWriter.Write
Name | Type | Description |
---|---|---|
value | string |
The string to save. |
void SaveString(string value)
Called after data is saved by the Streamable Assets Manager via the Component Manager
(happens when Save or ConvertOldData is called).
This closes the binary writer and file stream.
If Disable Auto Invocation Of Before And After SaveMethods is disabled in the inspector,
you will need to call this method manually after calling ComponentManager.Save
or ComponentManager.ConvertOldData.