Class DataBag
A databag can persist values of different types through Unity's serialization system. Types that are not supported by Unity's serialization out-of-the-box require implementations of the ISerializer and IDeserializer interfaces for that type.
Implementations of supported types will overwrite the default serialization behaviour, with the exception of classes that inherit from Unity's Object.
Inheritance
Implements
Inherited Members
Namespace: InsaneScatterbrain.Serialization
Syntax
[Serializable]
public class DataBag : ISerializationCallbackReceiver
Properties
Names
Declaration
public IEnumerable<string> Names { get; }
Property Value
Type | Description |
---|---|
System.Collections.Generic.IEnumerable<T><string> |
Methods
Contains(string)
Checks if a value is stored under the given name.
Declaration
public bool Contains(string name)
Parameters
Type | Name | Description |
---|---|---|
string | name | The name. |
Returns
Type | Description |
---|---|
bool | True if the name exists, false otherwise. |
Get(string)
Gets the value stored under the given name.
Declaration
public object Get(string name)
Parameters
Type | Name | Description |
---|---|---|
string | name | The name. |
Returns
Type | Description |
---|---|
object | The associated value. |
OnAfterDeserialize()
Called after Unity deserializes the databag. It deserializes all the objects inside it.
Declaration
public void OnAfterDeserialize()
OnBeforeSerialize()
Called before Unity serializes the databag. It serializes all the objects inside it.
Declaration
public void OnBeforeSerialize()
Remove(string)
Removes the value from the bag that is stored under the given name.
Declaration
public void Remove(string name)
Parameters
Type | Name | Description |
---|---|---|
string | name | The name. |
Set(string, object)
Store the given value under the given name.
Declaration
public void Set(string name, object value)
Parameters
Type | Name | Description |
---|---|---|
string | name | The name. |
object | value | The value. |