public CapiMetadata(object value, CapiType type, Func<object> getter, Func<object, object> setter)
 {
     this.value = value;
     this.type = type;
     this.getter = getter;
     this.setter = setter;
     this.allowedValues = allowedValues;
 }
Esempio n. 2
0
 public CapiMetadata(object value, CapiType type, Func <object> getter, Func <object, object> setter)
 {
     this.value  = value;
     this.type   = type;
     this.getter = getter;
     this.setter = setter;
     // This throws a warning, but our website architecture requires it as of 6/5/2016.
     this.allowedValues = allowedValues;
 }
Esempio n. 3
0
    public static void expose <T> (string propertyName, Func <object> getter, Func <T, object> setter, object[] allowedValues = null)
    {
        // TODO if already exposed throw error

        object value = prepareValue(getter());

        if (allowedValues != null)
        {
            allowedValues = (object[])prepareValue(allowedValues);
        }

        CapiType type = CapiType.STRING;

        if (typeof(T) == typeof(float))
        {
            type = CapiType.NUMBER;
        }
        else if (typeof(T) == typeof(String))
        {
            type = CapiType.STRING;
        }
        else if (typeof(T) == typeof(Boolean))
        {
            type = CapiType.BOOLEAN;
        }
        else if (typeof(T) == typeof(string[]))
        {
            type = CapiType.ARRAY;
        }
        else
        {
            // TODO throw type not supported exception
        }

        var res = GameObject.Find("CAPI");

        if (res == null)
        {
            var capiGO = new GameObject("CAPI");
            capiGO.AddComponent <CapiBehaviour> ();
        }

        Capi.initializeExpose();

        capiMetadata.Add(propertyName, new CapiMetadata(value, type, getter, (v) => { return(setter((T)v)); }));

        Application.ExternalCall("receiveExposeFromUnity", new object[] { propertyName, (int)type, value, allowedValues });
    }