A save object defines a scriptable object class that holds save values to save data in your game. Each object can have as many values as you’d like and is designed to be modular to an extend. You can create multiple save objects of the same type if you need it, but you will need to define seperate save keys for these variants to distinguish them.
API
Fields
bool isExpanded
[SerializeField] private bool
Is used internally for the custom inspector for the object to hold if the object dropdown is expanded or not.
string saveKey
[SerializeField] private string
Defines the save key for the save object. If you want to use multiple of the same type, you will need to make sure this is unique for each variant otherwise there will be issues.
Properties
bool IsInitialized
public bool
Gets if the save object is initialized by checking that the save key is not empty.
string SaveKey
public string
Gets the save key defined for this save object.
Dictionary<string, SaveValueBase> Lookup
public Dictionary<string, SaveValueBase>
Holds a lookup of all the save values this save object stores at runtime.
Methods
virtual void Save()
public virtual void
Saves the values on the save object & applies them to the save file.
playerSaveObject.Save();
virtual void Load()
public virtual void
Loads the save object when called. You shouldn’t need to call this manually as the system does it automatically, but it is there if you require to load it manually.
playerSaveObject.Load();
virtual void ResetObjectSaveValues()
Resets all the save values on the save object to their value defaults.
playerSaveObject.ResetObjectSaveValues();
virtual SerializableDictionary<string, SaveValueBase> GetSaveValue()
Gets the savable value for the save object’s save values. Used in the save managers save method.
SerializableDictionary<string, SaveValueBase> data = playerSaveObject.GetSaveValue();
bool HasValue(string saveKey)
public bool
Gets if there is a save value of the requested key.
bool HasSaveValue = playerSaveObject.HasValue("playerNameSaveKey");
SaveValue<T> GetValue(string saveKey)
public SaveValue<T>
Gets the save value of the key entered.
string value = playerSaveObject.GetValue<string>("playerNameSaveKey");
void SetValue(string saveKey, object value)
public void
Sets the value to the value entered.
playerSaveObject.SetValue("playerNameSaveKey", "John Smith");
void ResetElement(string saveKey)
public void
Resets a value with the corresponding key.
playerSaveObject.ResetElement("playerNameSaveKey");