예제 #1
0
        public static JSONAble UnSerialize(JSONObject jsonObject)
        {
            JSONAble r = null;

            if (jsonObject.HasField("_class") && jsonObject.HasField("_data"))
            {
                string c = jsonObject.GetField("_class").str;
                Type   t = Type.GetType(c);
                if (t.IsSubclassOf(typeof(JSONAble)))
                {
                    if (t.IsSubclassOf(typeof(ScriptableObject)))
                    {
                        r = ScriptableObject.CreateInstance(t) as JSONAble;
                        r.fromJSONObject(jsonObject.GetField("_data"));
                    }
                }
            }
            else if (jsonObject.IsArray)
            {
                r = ScriptableObject.CreateInstance <IsoUnityCollectionType>();
                r.fromJSONObject(jsonObject);
            }
            else if (jsonObject.IsString || jsonObject.IsNumber || jsonObject.IsBool)
            {
                r = ScriptableObject.CreateInstance <IsoUnityBasicType>();
                r.fromJSONObject(jsonObject);
            }

            return(r);
        }
예제 #2
0
        public override void fromJSONObject(JSONObject json)
        {
            List <JSONObject> ljo = json.list;

            if (this.l == null)
            {
                this.l = ScriptableObject.CreateInstance <IsoUnityList>();
            }
            else
            {
                this.l.Clear();
            }
            foreach (var jo in ljo)
            {
                JSONAble unserialized = JSONSerializer.UnSerialize(jo);
                this.l.Add(unserialized);
            }
        }
예제 #3
0
    public void fromJSONObject(JSONObject json)
    {
        this.name = json["name"].ToString();

        //Clean basic types
        destroyBasic(this.args);

        this.args = new Dictionary <string, object>();

        JSONObject parameters = json["parameters"];

        foreach (string key in parameters.keys)
        {
            JSONObject param        = parameters[key];
            JSONAble   unserialized = JSONSerializer.UnSerialize(param);
            this.setParameter(key, unserialized);
        }
    }
예제 #4
0
    public void fromJSONObject(JSONObject json)
    {
        //quitar comillas dobles (se añaden solas en la conversion)
        int len = json["name"].ToString().Length - 2;

        this.name = json["name"].ToString().Substring(1, len);

        //Clean basic types
        destroyBasic(this.args);

        this.args = new Dictionary <string, Object>();

        JSONObject parameters = json["parameters"];

        foreach (string key in parameters.keys)
        {
            //Debug.Log(parameters[key]); de parameters[key] saca el entity
            JSONObject param        = parameters[key];
            JSONAble   unserialized = JSONSerializer.UnSerialize(param);
            this.setParameter(key, unserialized);
        }
    }
예제 #5
0
    public static JSONAble UnSerialize(JSONObject jsonObject)
    {
        JSONAble r = null;

        if (jsonObject.HasField("_class") && jsonObject.HasField("_data"))
        {
            string c = jsonObject.GetField("_class").str;
            //string[] splitted_class = jsonObject.GetField("_class").str.Split('.');
            //string c = splitted_class[splitted_class.Length-1];

            Type        t          = Type.GetType(c);
            List <Type> interfaces = new List <Type>(t.GetInterfaces());

            if (interfaces.Contains(typeof(JSONAble)))
            {
                if (t.IsSubclassOf(typeof(ScriptableObject)))
                {
                    ScriptableObject so = ScriptableObject.CreateInstance(t);
                    r = so as JSONAble;
                    r.fromJSONObject(jsonObject.GetField("_data"));
                }
            }
        }
        else if (jsonObject.IsArray)
        {
            r = ScriptableObject.CreateInstance <IsoUnityCollectionType>();
            r.fromJSONObject(jsonObject);
        }
        else if (jsonObject.IsString || jsonObject.IsNumber || jsonObject.IsBool)
        {
            r = ScriptableObject.CreateInstance <IsoUnityBasicType>();
            r.fromJSONObject(jsonObject);
        }

        return(r);
    }