blog games developers documentation portfolio gallery

More in this category:

Access Hashtable properties

The following functions can be called on Hashtable objects when you have the OrbCreationExtensions included in your project and have put the line "using OrbcreationExtensions;" at the top of your script.
Example:

using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using OrbCreationExtensions;

public class MyClass {
public void DoSomethingUseless() {
Hashtable aHashtable;
aHashtable = new Hashtable();
aHashtable["number"] = 1234;
aHashtable["name"] = "red";
aHashtable["color"] = Color.red;
aHashtable["hexColor"] = "#FF0000";

int number = aHashtable.GetInt("number");

// will return empty string if not exists
string name = aHashtable.GetString("name", "");

Color color = aHashtable.GetColor("color");
// or you could also do this:
color = aHashtable.GetColor("hexColor");

Debug.Log("Record is " + aHashtable.GetString("number") + " " + aHashtable.GetString("name") + " " + aHashtable.GetString("hexColor"));
}
}


static object GetValue(object key)


Retrieve property by key. Returns null if the key doesn't exist

static Hashtable GetHashtable(object key)


Retrieve Hashtable property by key. Returns null if the key doesn't exist or if the object is not a Hashtable.

static ArrayList GetArrayList(object key)


Retrieve ArrayList property by key. Returns null if the key doesn't exist or if the object is not a ArrayList.

static ArrayList GetArrayList(object key, bool wrap)


Retrieve ArrayList property by key. Returns null if the key doesn't exist.
If wrap is true, and the property is not of type ArrayList, A new ArrayList is created and the property is added as the first value. Returns null otherwise.

static string GetString(object key)


Retrieve string property by key. Returns null if the key doesn't exist.
If the object is of type int, bool or float, the string representation will be returned. Returns null otherwise.

static string GetString(object key, string defaultValue)


Retrieve string property by key. Returns defaultValue if the key doesn't exist.
If the object is of type int, bool or float, the string representation will be returned. Returns defaultValue otherwise.

static int GetInt(object key)


See static int GetInt(object key, int defaultValue) with a defaultValue of 0

static int GetInt(object key, int defaultValue)


Retrieve int property by key. Returns defaultValue if the key doesn't exist.
If the object is of type string, the int conversion of the string will be returned. Returns defaultValue if the conversion fails. If the object is of type bool 0 or 1 will be returned. If the value is of type float, the Mathf.FloorToInt() value will be returned. Returns defaultValue otherwise.

static float GetFloat(object key)


See static float GetFloat(object key, float defaultValue) with a defaultValue of 0f

static float GetFloat(object key, float defaultValue)


Retrieve float property by key. Returns defaultValue if the key doesn't exist.
If the object is of type string, the float conversion of the string will be returned. Returns defaultValue if the conversion fails. If the object is of type bool 0f or 1f will be returned. If the value is of type int, long or double, it will be casted to float and returned. Returns defaultValue otherwise.

static bool GetBool(object key)


Retrieve bool property by key. Returns false if the key doesn't exist.
If the object is of type string, true wull be return if the string equals "1", "true", True", or "TRUE". If the value is of type int, long, float or double, return true if the value > 0. Returns false otherwise.

static Color GetColor(object key)


Retrieve Color property by key. Returns Color(0,0,0,0) if the key doesn't exist.
If the object is of type string, the string will be converted to a Color and can be in the any of the formats:
0.1, 0.2, 0.3
0.1, 0.2, 0.3, 1.0
#AB45FF
#AB45FFFF
Returns Color(0,0,0,0) if the conversion fails.

static Vector3 GetVector3(object key)


Retrieve Vector3 property by key. Returns null if the key doesn't exist.
If the object is of type string, the string will be converted to a Vector3 when it is in the format:
0.1, 0.2, 0.3
Returns null if the conversion fails.

static Texture2D GetTexture2D(object key)


Retrieve Texture2D property by key. Returns null if the key doesn't exist or if the object is not a Texture2D.

static byte[] GetBytes(object key)


Retrieve byte[] property by key. Returns null if the key doesn't exist or if the object is not a byte[].

static void AddHashtable(Hashtable addHash, bool overwriteExistingKeys)


Add all the key/value pairs of addHash to the receiving Hashtable. If overwriteExistingKeys is true, a value will be overwritten if the key already exists in the receiver. If false, the existing value will remain and the new value is ignored.





follow us