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

Last updated