KeyValue Methods

v4.0

Most often you'll grab values direction from the Dictionaries Methods, but if you have a KeyValue object, there are methods you can use to manage data.

KeyValue Structure

A KeyValue object has a string key, as well as a List<KeyValueList> values. This is where all the data is stored.

Each KeyValueList object has a string typeName and a List<KeyValueObject> objects.

Each KeyValueObject has a object obj, which is a cached object value, and a DictionariesObject DictionariesObject. (The actual variable is private _dictionariesObject, but the Property DictionariesObject is how we get and set the value.

Get Methods

Get data out, or information.

// Get a value from the list. Note the Type must be provided
var firstItem = KeyValue.Value<Sprite>();
var randomItem = KeyValue.Value<Sprite>(true);
var itemInIndex4 = KeyValue.Value<Sprite>(false, 4);

// Get all values from the list as an array
var allStrings = KeyValue.Values<string>();
var allAudioClips = KeyValue.Values<AudioClip>();

// Get all values as a list
var allBools = KeyValue.ValuesList<bool>();


// Get all KeyValueObject objects as an array
Texture2D[] portraitObjects = keyValue.ValueObjects<Texture2D>();

// Get all KeyValueObject objects as a list
List<Texture2D> portraitObjects = keyValue.ValueObjectsList<Texture2D>();


// Number of different types in use on this KeyValue
int typesInUse = KeyValue.TypesInUse;

// Get the names of each type in use
string[] typesInUse = KeyValue.Types;

// Get the total objects in the list (each item in any list is one object)
int totalObjects = KeyValue.TotalObjects;

Add(), Remove(), and Set() Methods

// Set a value
// note the type is determined by the type of the value provided. This means that
// passing in "3" will be an int, and "3f" would be a float!
SetValue(0, 3); // Set index 0 int value to 3
SetValue(3, "Some Text"); // Set index 3 string value to "Some Text"
SetValue(someIndex, audioClip); // Set index someIndex to AudioClip value to audioClip

// Add a value
AddValue(3.3f); // Add a float 3.3f
AddValue(Some Text"); // Add a string "Some Text"
AddValue(audioClip); // Add an AudioClip audioClip

// Remove the FIRST found value
RemoveValue(audioClip); // Remove the first AudioClip which matches audioClip

Last updated

Was this helpful?