Exemplo n.º 1
0
        List <List <T> > LoadUnityType2DList <T>(string jsonText) where T : UnityEngine.Object
        {
            var goList = new List <List <T> >();

            var paths = Json.Deserialize(jsonText) as IList;

            foreach (var sublist in paths)
            {
                var   goSubList = new List <T>();
                IList list      = sublist as IList;
                foreach (var path in list)
                {
                    goSubList.Add(GDEItemManager.GetTypeFromJson <T>(path.ToString()));
                }
                goList.Add(goSubList);
            }

            return(goList);
        }
Exemplo n.º 2
0
        object ConvertValueToType(BasicFieldType type, object value)
        {
            object convertedValue = 0;

            switch (type)
            {
            case BasicFieldType.Bool:
            {
                string b = value.ToString().Trim();
                if (b.ToString().Equals("0"))
                {
                    convertedValue = false;
                }
                else if (b.ToString().Equals("1"))
                {
                    convertedValue = true;
                }
                else
                {
                    convertedValue = Convert.ToBoolean(b);
                }

                break;
            }

            case BasicFieldType.Int:
            {
                convertedValue = Convert.ToInt32(value);
                break;
            }

            case BasicFieldType.Float:
            {
                convertedValue = Convert.ToSingle(value);
                break;
            }

            case BasicFieldType.String:
            {
                convertedValue = value.ToString();
                break;
            }

            case BasicFieldType.Color:
            {
                List <object> colorValues             = value as List <object>;
                Dictionary <string, object> colorDict = new Dictionary <string, object>();
                colorDict.TryAddOrUpdateValue("r", Convert.ToSingle(colorValues[0]) / 255f);
                colorDict.TryAddOrUpdateValue("g", Convert.ToSingle(colorValues[1]) / 255f);
                colorDict.TryAddOrUpdateValue("b", Convert.ToSingle(colorValues[2]) / 255f);
                colorDict.TryAddOrUpdateValue("a", Convert.ToSingle(colorValues[3]));

                convertedValue = colorDict;

                break;
            }

            case BasicFieldType.Vector2:
            {
                List <object> vectValues             = value as List <object>;
                Dictionary <string, object> vectDict = new Dictionary <string, object>();
                vectDict.TryAddOrUpdateValue("x", Convert.ToSingle(vectValues[0]));
                vectDict.TryAddOrUpdateValue("y", Convert.ToSingle(vectValues[1]));

                convertedValue = vectDict;

                break;
            }

            case BasicFieldType.Vector3:
            {
                List <object> vectValues             = value as List <object>;
                Dictionary <string, object> vectDict = new Dictionary <string, object>();
                vectDict.TryAddOrUpdateValue("x", Convert.ToSingle(vectValues[0]));
                vectDict.TryAddOrUpdateValue("y", Convert.ToSingle(vectValues[1]));
                vectDict.TryAddOrUpdateValue("z", Convert.ToSingle(vectValues[2]));

                convertedValue = vectDict;

                break;
            }

            case BasicFieldType.Vector4:
            {
                List <object> vectValues             = value as List <object>;
                Dictionary <string, object> vectDict = new Dictionary <string, object>();
                vectDict.TryAddOrUpdateValue("x", Convert.ToSingle(vectValues[0]));
                vectDict.TryAddOrUpdateValue("y", Convert.ToSingle(vectValues[1]));
                vectDict.TryAddOrUpdateValue("z", Convert.ToSingle(vectValues[2]));
                vectDict.TryAddOrUpdateValue("w", Convert.ToSingle(vectValues[3]));

                convertedValue = vectDict;

                break;
            }

            case BasicFieldType.GameObject:
            {
                convertedValue = GDEItemManager.GetTypeFromJson <GameObject>(value.ToString());
                break;
            }

            case BasicFieldType.Texture2D:
            {
                convertedValue = GDEItemManager.GetTypeFromJson <Texture2D>(value.ToString());
                break;
            }

            case BasicFieldType.Material:
            {
                convertedValue = GDEItemManager.GetTypeFromJson <Material>(value.ToString());
                break;
            }

            case BasicFieldType.AudioClip:
            {
                convertedValue = GDEItemManager.GetTypeFromJson <AudioClip>(value.ToString());
                break;
            }

            case BasicFieldType.Undefined:
            {
                if (value != null)
                {
                    convertedValue = value.ToString();
                }
                break;
            }
            }

            return(convertedValue);
        }