Cross Platform Easy Save
VoxelBusters.Serialization.SerializationManager Class Reference

The SerializationManager class is the interface for saving and restoring object values between game sessions. More...

Static Public Member Functions

static void BeginSerializeGroup (string key, params SerializationOption[] options)
 Begins the serialize group. More...
 
static void SerializeInt32 (string key, int value, params SerializationOption[] options)
 Saves the given integer value. More...
 
static void SerializeSingle (string key, float value, params SerializationOption[] options)
 Saves the given float value. More...
 
static void SerializeString (string key, string value, params SerializationOption[] options)
 Saves the given string value. More...
 
static void Serialize< T > (string key, T value, params SerializationOption[] options)
 Saves the given value. More...
 
static void EndSerializeGroup ()
 Closes a group started with BeginSerializeGroup. More...
 
static void BeginDeserializeGroup (string key)
 Begins the deserialize group. More...
 
static int DeserializeInt32 (string key, int defaultValue=default(int))
 Returns the integer value associated with the given key. More...
 
static float DeserializeSingle (string key, float defaultValue=default(float))
 Returns the float value associated with the given key. More...
 
static string DeserializeString (string key, string defaultValue=default(string))
 Returns the string value associated with the given key. More...
 
static T Deserialize< T > (string key, T defaultValue=default(T))
 Returns the value associated with the given key. More...
 
static void EndDeserializeGroup ()
 Closes a group started with BeginDeserializeGroup. More...
 
static bool HasKey (string key)
 Determines whether storage contains value associated with given key. More...
 
static void DeleteKey (string key)
 Removes the value identified by the key. More...
 
static void DeleteAll ()
 Removes all the data stored in the system. Use it with caution. More...
 
static void ClearCache ()
 Removes all the data that have been cached by the serialization system. More...
 
static SerializationOption BufferSize (int value)
 Custom serializaion option passed to specify the stream buffer size. More...
 
static SerializationOption SerializationMethod (SerializationMethodOptions value)
 Custom serializaion option passed to specify the serialization (save) method used while serializing object. More...
 
static SerializationOption StorageTarget (eStorageTarget value)
 Custom serializaion option passed to specify the storage location where data will be saved. More...
 

Detailed Description

The SerializationManager class is the interface for saving and restoring object values between game sessions.

Member Function Documentation

◆ BeginDeserializeGroup()

static void VoxelBusters.Serialization.SerializationManager.BeginDeserializeGroup ( string  key)
static

Begins the deserialize group.

Parameters
keyName of the key associated with saved group.
// use this script to save and read multiple attributes of player from a single document
using System.Collections;
public class ExampleClass : MonoBehaviour
{
void SaveProfile()
{
// shows how to batch multiple data components and save it in a single file
SerializationManager.BeginSerializeGroup("profile"); // creates a new document called profile
SerializationManager.SerializeString("name", "player1"); // adds name info
SerializationManager.SerializeInt32("level", 1); // adds level info
SerializationManager.SerializeSingle("progress", 0.9f); // adds progress info
SerializationManager.EndSerializeGroup(); // marks end of the document and saves the data
}
void ReadProfile()
{
// shows how to read data fields from batched document
SerializationManager.BeginDeserializeGroup("profile"); // open saved document called profile
string name = SerializationManager.DeserializeString("name"); // adds name info
int level = SerializationManager.DeserializeInt32("level"); // adds level info
float progress= SerializationManager.DeserializeSingle("progress"); // adds progress info
SerializationManager.EndDeserializeGroup(); // marks end of the document and saves the data
}
}

◆ BeginSerializeGroup()

static void VoxelBusters.Serialization.SerializationManager.BeginSerializeGroup ( string  key,
params SerializationOption []  options 
)
static

Begins the serialize group.

Begins the serialize group.

All serialize calls enclosed inside this element will be saved in a single document. The group must be closed with a call to EndSerializeGroup.

Parameters
keyA string value associated with the value. If specified key already exists, value replaces the existing value. If key is not found, new copy of value will be created in the specified storage.
optionsAn optional array of serialization option specifies custom settings used for this specific operation. These options overrides the SerializationSettings values.
// use this script to save and read multiple attributes of player from a single document
using System.Collections;
public class ExampleClass : MonoBehaviour
{
void SaveProfile()
{
// shows how to batch multiple data components and save it in a single file
SerializationManager.BeginSerializeGroup("profile"); // creates a new document called profile
SerializationManager.SerializeString("name", "player1"); // adds name info
SerializationManager.SerializeInt32("level", 1); // adds level info
SerializationManager.SerializeSingle("progress", 0.9f); // adds progress info
SerializationManager.EndSerializeGroup(); // marks end of the document and saves the data
}
void ReadProfile()
{
// shows how to read data fields from batched document
SerializationManager.BeginDeserializeGroup("profile"); // open saved document called profile
string name = SerializationManager.DeserializeString("name"); // adds name info
int level = SerializationManager.DeserializeInt32("level"); // adds level info
float progress= SerializationManager.DeserializeSingle("progress"); // adds progress info
SerializationManager.EndDeserializeGroup(); // marks end of the document and saves the data
}
}

◆ BufferSize()

static SerializationOption VoxelBusters.Serialization.SerializationManager.BufferSize ( int  value)
static

Custom serializaion option passed to specify the stream buffer size.

This option can be used for serialization mode.

Parameters
valueValue.

◆ ClearCache()

static void VoxelBusters.Serialization.SerializationManager.ClearCache ( )
static

Removes all the data that have been cached by the serialization system.

◆ DeleteAll()

static void VoxelBusters.Serialization.SerializationManager.DeleteAll ( )
static

Removes all the data stored in the system. Use it with caution.

Call this function to delete all the saved information. Be careful while using this. You cannot undo this action.

◆ DeleteKey()

static void VoxelBusters.Serialization.SerializationManager.DeleteKey ( string  key)
static

Removes the value identified by the key.

Parameters
keyName of the key associated with value.

◆ Deserialize< T >()

static T VoxelBusters.Serialization.SerializationManager.Deserialize< T > ( string  key,
defaultValue = default(T) 
)
static

Returns the value associated with the given key.

Returns the value associated with the given key.

If the value doesn't already exist in the storage the function will return defaultValue.

Returns
The value previously stored.
Parameters
keyName of the key associated with value.
defaultValueValue to return if the specified key is not found in the storage.
// use this script to save and read custom object
using System.Collections;
public class PlayerProfile
{
// fields
public string playerName;
public int playerLevel;
public float playerProgress;
// constructors
public PlayerProfile()
{}
public PlayerProfile(string name, int level, float progress)
{
playerName = name;
playerLevel = level;
playerProgress = progress;
}
}
public class ExampleClass : MonoBehaviour
{
// fields
PlayerProfile profile = new PlayerProfile("player1", 1, 0.9f);
// methods
void SaveProfile()
{
// shows how to save custom object
SerializationManager.Serialize("profile", profile);
}
void ReadProfile()
{
// shows how to read custom object
profile = SerializationManager.Deserialize<PlayerProfile>("profile");
}
}

◆ DeserializeInt32()

static int VoxelBusters.Serialization.SerializationManager.DeserializeInt32 ( string  key,
int  defaultValue = default(int) 
)
static

Returns the integer value associated with the given key.

Returns the integer value associated with the given key.

If the value doesn't already exist in the storage the function will return defaultValue.

Returns
The value previously stored.
Parameters
keyName of the key associated with integer value.
defaultValueInteger value to return if the specified key is not found in the storage.
// use this script to save and read player level info (int value)
using System.Collections;
public class ExampleClass : MonoBehaviour
{
void OnReachedCheckpoint9()
{
// saves new level info
int newLevel = 10;
SerializationManager.SerializeInt32("level", newLevel);
}
int GetPlayerLevel()
{
// read saved value
return SerializationManager.DeserializeInt32("level");
}
}

◆ DeserializeSingle()

static float VoxelBusters.Serialization.SerializationManager.DeserializeSingle ( string  key,
float  defaultValue = default(float) 
)
static

Returns the float value associated with the given key.

Returns the float value associated with the given key.

If the value doesn't already exist in the storage the function will return defaultValue.

Returns
The value previously stored.
Parameters
keyName of the key associated with float value.
defaultValueFloat value to return if the specified key is not found in the storage.
// use this script to save and read player progress (float value)
using System.Collections;
public class ExampleClass : MonoBehaviour
{
void OnPlayerProgressChanged(float newValue)
{
// saves progress info
SerializationManager.SerializeSingle("progress", newValue);
}
float GetPlayerProgress()
{
// read saved value
return SerializationManager.DeserializeSingle("progress");
}
}

◆ DeserializeString()

static string VoxelBusters.Serialization.SerializationManager.DeserializeString ( string  key,
string  defaultValue = default(string) 
)
static

Returns the string value associated with the given key.

Returns the string value associated with the given key.

If the value doesn't already exist in the storage the function will return defaultValue.

Returns
The value previously stored.
Parameters
keyName of the key associated with string value.
defaultValueString value to return if the specified key is not found in the storage.
// use this script to save and read player name (string value)
using System.Collections;
public class ExampleClass : MonoBehaviour
{
void OnPlayerNameChanged(string newName)
{
// saves name info
SerializationManager.SerializeString("name", newName);
}
string GetPlayerName()
{
// read saved value
return SerializationManager.DeserializeString("name");
}
}

◆ EndDeserializeGroup()

static void VoxelBusters.Serialization.SerializationManager.EndDeserializeGroup ( )
static

Closes a group started with BeginDeserializeGroup.

◆ EndSerializeGroup()

static void VoxelBusters.Serialization.SerializationManager.EndSerializeGroup ( )
static

Closes a group started with BeginSerializeGroup.

◆ HasKey()

static bool VoxelBusters.Serialization.SerializationManager.HasKey ( string  key)
static

Determines whether storage contains value associated with given key.

Returns
true if storage has the specified key; otherwise, false.
Parameters
keyA string value used to uniquely identify the stored value.

◆ SerializationMethod()

static SerializationOption VoxelBusters.Serialization.SerializationManager.SerializationMethod ( SerializationMethodOptions  value)
static

Custom serializaion option passed to specify the serialization (save) method used while serializing object.

This option can be used for serialization mode.

Parameters
valueValue.

◆ Serialize< T >()

static void VoxelBusters.Serialization.SerializationManager.Serialize< T > ( string  key,
value,
params SerializationOption []  options 
)
static

Saves the given value.

Parameters
keyA string value associated with the value. If specified key already exists, value replaces the existing value. If key is not found, new copy of value will be created in the specified storage.
valueThe value to be saved.
optionsAn optional array of serialization option specifies custom settings used for this specific operation. These options overrides the SerializationSettings values.
// use this script to save and read custom object (here, PlayerProfile)
using System.Collections;
public class PlayerProfile
{
// fields
public string playerName;
public int playerLevel;
public float playerProgress;
// constructors
public PlayerProfile()
{}
public PlayerProfile(string name, int level, float progress)
{
playerName = name;
playerLevel = level;
playerProgress = progress;
}
}
public class ExampleClass : MonoBehaviour
{
// fields
PlayerProfile profile = new PlayerProfile("player1", 1, 0.9f);
// methods
void SaveProfile()
{
// shows how to save custom object
SerializationManager.Serialize("profile", profile);
}
void ReadProfile()
{
// shows how to read custom object
profile = SerializationManager.Deserialize<PlayerProfile>("profile");
}
}

◆ SerializeInt32()

static void VoxelBusters.Serialization.SerializationManager.SerializeInt32 ( string  key,
int  value,
params SerializationOption []  options 
)
static

Saves the given integer value.

Parameters
keyA string value associated with the value. If specified key already exists, value replaces the existing value. If key is not found, new copy of value will be created in the specified storage.
valueThe value to be saved.
optionsAn optional array of serialization option specifies custom settings used for this specific operation. These options overrides the SerializationSettings values.
// use this script to save and read player level info (int value)
using System.Collections;
public class ExampleClass : MonoBehaviour
{
void OnReachedCheckpoint9()
{
// saves new level info
int newLevel = 10;
SerializationManager.SerializeInt32("level", newLevel);
}
int GetPlayerLevel()
{
// read saved value
return SerializationManager.DeserializeInt32("level");
}
}

◆ SerializeSingle()

static void VoxelBusters.Serialization.SerializationManager.SerializeSingle ( string  key,
float  value,
params SerializationOption []  options 
)
static

Saves the given float value.

Parameters
keyA string value associated with the value. If specified key already exists, value replaces the existing value. If key is not found, new copy of value will be created in the specified storage.
valueThe value to be saved.
optionsAn optional array of serialization option specifies custom settings used for this specific operation. These options overrides the SerializationSettings values.
// use this script to save and read player progress (float value)
using System.Collections;
public class ExampleClass : MonoBehaviour
{
void OnPlayerProgressChanged(float newValue)
{
// saves progress info
SerializationManager.SerializeSingle("progress", newValue);
}
float GetPlayerProgress()
{
// read saved value
return SerializationManager.DeserializeSingle("progress");
}
}

◆ SerializeString()

static void VoxelBusters.Serialization.SerializationManager.SerializeString ( string  key,
string  value,
params SerializationOption []  options 
)
static

Saves the given string value.

Parameters
keyA string value associated with the value. If specified key already exists, value replaces the existing value. If key is not found, new copy of value will be created in the specified storage.
valueThe value to be saved.
optionsAn optional array of serialization option specifies custom settings used for this specific operation. These options overrides the SerializationSettings values.
// use this script to save and read player name (string value)
using System.Collections;
public class ExampleClass : MonoBehaviour
{
void OnPlayerNameChanged(string newName)
{
// saves name info
SerializationManager.SerializeString("name", newName);
}
string GetPlayerName()
{
// read saved value
return SerializationManager.DeserializeString("name");
}
}

◆ StorageTarget()

static SerializationOption VoxelBusters.Serialization.SerializationManager.StorageTarget ( eStorageTarget  value)
static

Custom serializaion option passed to specify the storage location where data will be saved.

Parameters
valueValue.

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