示例#1
0
        private static void DeserializeVariables(IVariableSource variableSource, Dictionary <string, object> dict, List <UnityEngine.Object> unityObjects)
        {
            object obj;

            if (dict.TryGetValue("Variables", out obj))
            {
                List <SharedVariable> list = new List <SharedVariable>();
                IList list2 = obj as IList;
                for (int i = 0; i < list2.Count; i++)
                {
                    SharedVariable item = DeserializeJSON.DeserializeSharedVariable(list2[i] as Dictionary <string, object>, variableSource, true, unityObjects);
                    list.Add(item);
                }
                variableSource.SetAllVariables(list);
            }
        }
示例#2
0
        private static object ValueToObject(Task task, Type type, object obj, IVariableSource variableSource, List <UnityEngine.Object> unityObjects)
        {
            if (type.Equals(typeof(SharedVariable)) || type.IsSubclassOf(typeof(SharedVariable)))
            {
                SharedVariable sharedVariable = DeserializeJSON.DeserializeSharedVariable(obj as Dictionary <string, object>, variableSource, false, unityObjects);
                if (sharedVariable == null)
                {
                    sharedVariable = (TaskUtility.CreateInstance(type) as SharedVariable);
                }
                return(sharedVariable);
            }
            if (type.Equals(typeof(UnityEngine.Object)) || type.IsSubclassOf(typeof(UnityEngine.Object)))
            {
                return(DeserializeJSON.IndexToUnityObject(Convert.ToInt32(obj), unityObjects));
            }
            if (!type.IsPrimitive)
            {
                if (!type.Equals(typeof(string)))
                {
                    goto IL_C5;
                }
            }
            try
            {
                object result = Convert.ChangeType(obj, type);
                return(result);
            }
            catch (Exception)
            {
                object result = null;
                return(result);
            }
IL_C5:
            if (type.IsSubclassOf(typeof(Enum)))
            {
                try
                {
                    object result = Enum.Parse(type, (string)obj);
                    return(result);
                }
                catch (Exception)
                {
                    object result = null;
                    return(result);
                }
            }
            if (type.Equals(typeof(Vector2)))
            {
                return(DeserializeJSON.StringToVector2((string)obj));
            }
            if (type.Equals(typeof(Vector3)))
            {
                return(DeserializeJSON.StringToVector3((string)obj));
            }
            if (type.Equals(typeof(Vector4)))
            {
                return(DeserializeJSON.StringToVector4((string)obj));
            }
            if (type.Equals(typeof(Quaternion)))
            {
                return(DeserializeJSON.StringToQuaternion((string)obj));
            }
            if (type.Equals(typeof(Matrix4x4)))
            {
                return(DeserializeJSON.StringToMatrix4x4((string)obj));
            }
            if (type.Equals(typeof(Color)))
            {
                return(DeserializeJSON.StringToColor((string)obj));
            }
            if (type.Equals(typeof(Rect)))
            {
                return(DeserializeJSON.StringToRect((string)obj));
            }
            if (type.Equals(typeof(LayerMask)))
            {
                return(DeserializeJSON.ValueToLayerMask(Convert.ToInt32(obj)));
            }
            if (type.Equals(typeof(AnimationCurve)))
            {
                return(DeserializeJSON.ValueToAnimationCurve((Dictionary <string, object>)obj));
            }
            object obj2 = TaskUtility.CreateInstance(type);

            DeserializeJSON.DeserializeObject(task, obj2, obj as Dictionary <string, object>, variableSource, unityObjects);
            return(obj2);
        }