Save Value

CarterGames.SaveManager.Runtime
CarterGames.Assets.SaveManager

The save value class defines a value that is saved. It’s in the name. This inherits from an abstract base class that holds a non-type object as the value. While the generic class which you’ll be using can be any type. However the type you are saving has to be serializable already. You can serialize a dictionary with the serialized dictionary class provided with the asset should you wish.

You can define a save value in any save object inheriting class. Fields will need to be either [SerializeField] or public to be visible in the inspector & save editor window. They can be defined in a few ways:

// A string save value with a randomly generated save key.
[SerializeField] private SaveValue<string> playerName;

// A string save value with a manually defined save key.
[SerializeField] private SaveValue<string> playerName = new SaveValue<string>("playerNameSaveKey");

// A string save value with a manually defined save key & default value defined.
[SerializeField] private SaveValue<string> playerName = new SaveValue<string>("playerNameSaveKey", "John Smith");

API

Fields

[SerializeField] private T – Contains the value that is stored in the save value.

Properties

public T – Gets/Sets the value that this save value stores.

Debug.Log(playerName.Value);
playerName.Value = "John Smith";

public override object – Gets/Sets the raw value stored in the save value. This is intended for internal use only. Use Value instead for getting/setting the save value.

Constructors

Creates a new save value of the type defined with a randomly generated save key when initialized.

[SerializeField] private SaveValue<string> playerName;

Creates a new save value of the type defined with a user defined save key. Note: The save key MUST be unique for each save value defined on the save object its contained on.

[SerializeField] private SaveValue<string> playerName = new SaveValue<string>("PlayerNameSaveKey");

Creates a new save value of the type defined with a user defined save key & assigned value. Note: The save key MUST be unique for each save value defined on the save object its contained on.

[SerializeField] private SaveValue<string> playerName = new SaveValue<string>("PlayerNameSaveKey", "John Smith");

Methods

Resets the value to the type’s default value.

playerName.ResetValue();