BinarySerializerPersistentStateManager Class

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.

Properties

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.

In these instances, you can disable the auto calling of those two methods (by the Component Manager) by enabling the Disable Auto Invocation Of Before And After Load Methods option in the insepctor, which this property returns. Note, however, that you will need to call the OnBeforeDataLoaded and OnAfterDataLoaded methods manually, before and after beginning/completing the load operation.

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.

In these instances, you can disable the auto calling of those two methods (by the Component Manager) by enabling the Disable Auto Invocation Of Before And After Save Methods option in the insepctor, which this property returns. Note, however, that you will need to call the OnBeforeDataSaved and OnAfterDataSaved methods manually, before and after beginning/completing the save operation.

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.

Methods

LoadBool()

bool LoadBool()

Loads a boolean value via BinaryReader.ReadBoolean

Returns

bool
The loaded boolean.


LoadDouble()

double LoadDouble()

Loads a double value via BinaryReader.ReadDouble

Returns

double
The loaded double.


LoadFloat()

float LoadFloat()

Loads a float value via BinaryReader.ReadSingle

Returns

float
The loaded float.


LoadInt()

int LoadInt()

Loads a integer value via BinaryReader.ReadInt32

Returns

int
The loaded integer.


LoadString()

string LoadString()

Loads a string value via BinaryReader.ReadString

Returns

string
The loaded string.


OnAfterDataLoaded()

void OnAfterDataLoaded()

Called after all data is loaded. The open BeinaryReader is closed along with the FileStream.


OnBeforeDataLoaded()

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.

Exceptions

Type Condition
FileNotFoundException Thrown when the file specified does not exist in Application.persistentDataPath.

OnBeforeDataSaved()

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.


SaveBool(bool)

void SaveBool(bool value)

Saves a boolean value to the FileStream via BinaryWriter.Write

Parameters

Name Type Description
value bool

The bool to save.


SaveDouble(double)

void SaveDouble(double value)

Saves a double value to the FileStream via BinaryWriter.Write

Parameters

Name Type Description
value double

The double to save.


SaveFloat(float)

void SaveFloat(float value)

Saves a float value to the FileStream via BinaryWriter.Write

Parameters

Name Type Description
value float

The float to save.


SaveInt(int)

void SaveInt(int value)

Saves an integer value to the FileStream via BinaryWriter.Write

Parameters

Name Type Description
value int

The integer to save.


SaveString(string)

void SaveString(string value)

Saves a string value to the FileStream via BinaryWriter.Write

Parameters

Name Type Description
value string

The string to save.


SaveString(string)

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.