コード例 #1
0
 // Token: 0x060001F6 RID: 502 RVA: 0x000125C4 File Offset: 0x000107C4
 private static Dictionary <string, object>[] SerializeVariables(List <SharedVariable> variables, ref List <Object> unityObjects)
 {
     Dictionary <string, object>[] array = new Dictionary <string, object> [variables.Count];
     for (int i = 0; i < variables.Count; i++)
     {
         array[i] = JSONSerialization.SerializeVariable(variables[i], ref unityObjects);
     }
     return(array);
 }
コード例 #2
0
 // Token: 0x060001FA RID: 506 RVA: 0x0001290C File Offset: 0x00010B0C
 private static void SerializeFields(object obj, ref Dictionary <string, object> dict, ref List <Object> unityObjects)
 {
     FieldInfo[] allFields = TaskUtility.GetAllFields(obj.GetType());
     for (int i = 0; i < allFields.Length; i++)
     {
         if (!BehaviorDesignerUtility.HasAttribute(allFields[i], typeof(NonSerializedAttribute)) && ((!allFields[i].IsPrivate && !allFields[i].IsFamily) || BehaviorDesignerUtility.HasAttribute(allFields[i], typeof(SerializeField))) && (!(obj is ParentTask) || !allFields[i].Name.Equals("children")))
         {
             if (allFields[i].GetValue(obj) != null)
             {
                 string key = (allFields[i].FieldType.Name + allFields[i].Name).ToString();
                 if (typeof(IList).IsAssignableFrom(allFields[i].FieldType))
                 {
                     IList list = allFields[i].GetValue(obj) as IList;
                     if (list != null)
                     {
                         List <object> list2 = new List <object>();
                         for (int j = 0; j < list.Count; j++)
                         {
                             if (list[j] == null)
                             {
                                 list2.Add(null);
                             }
                             else
                             {
                                 Type type = list[j].GetType();
                                 if (list[j] is Task)
                                 {
                                     Task task = list[j] as Task;
                                     list2.Add(task.ID);
                                 }
                                 else if (list[j] is SharedVariable)
                                 {
                                     list2.Add(JSONSerialization.SerializeVariable(list[j] as SharedVariable, ref unityObjects));
                                 }
                                 else if (list[j] is Object)
                                 {
                                     Object @object = list[j] as Object;
                                     if (!object.ReferenceEquals(@object, null) && @object != null)
                                     {
                                         list2.Add(unityObjects.Count);
                                         unityObjects.Add(@object);
                                     }
                                 }
                                 else if (type.Equals(typeof(LayerMask)))
                                 {
                                     list2.Add(((LayerMask)list[j]).value);
                                 }
                                 else if (type.IsPrimitive || type.IsEnum || type.Equals(typeof(string)) || type.Equals(typeof(Vector2)) || type.Equals(typeof(Vector3)) || type.Equals(typeof(Vector4)) || type.Equals(typeof(Quaternion)) || type.Equals(typeof(Matrix4x4)) || type.Equals(typeof(Color)) || type.Equals(typeof(Rect)))
                                 {
                                     list2.Add(list[j]);
                                 }
                                 else
                                 {
                                     Dictionary <string, object> item = new Dictionary <string, object>();
                                     JSONSerialization.SerializeFields(list[j], ref item, ref unityObjects);
                                     list2.Add(item);
                                 }
                             }
                         }
                         if (list2 != null)
                         {
                             dict.Add(key, list2);
                         }
                     }
                 }
                 else if (typeof(Task).IsAssignableFrom(allFields[i].FieldType))
                 {
                     Task task2 = allFields[i].GetValue(obj) as Task;
                     if (task2 != null)
                     {
                         if (BehaviorDesignerUtility.HasAttribute(allFields[i], typeof(InspectTaskAttribute)))
                         {
                             Dictionary <string, object> dictionary = new Dictionary <string, object>();
                             dictionary.Add("Type", task2.GetType());
                             JSONSerialization.SerializeFields(task2, ref dictionary, ref unityObjects);
                             dict.Add(key, dictionary);
                         }
                         else
                         {
                             dict.Add(key, task2.ID);
                         }
                     }
                 }
                 else if (typeof(SharedVariable).IsAssignableFrom(allFields[i].FieldType))
                 {
                     if (!dict.ContainsKey(key))
                     {
                         dict.Add(key, JSONSerialization.SerializeVariable(allFields[i].GetValue(obj) as SharedVariable, ref unityObjects));
                     }
                 }
                 else if (typeof(Object).IsAssignableFrom(allFields[i].FieldType))
                 {
                     Object object2 = allFields[i].GetValue(obj) as Object;
                     if (!object.ReferenceEquals(object2, null) && object2 != null)
                     {
                         dict.Add(key, unityObjects.Count);
                         unityObjects.Add(object2);
                     }
                 }
                 else if (allFields[i].FieldType.Equals(typeof(LayerMask)))
                 {
                     dict.Add(key, ((LayerMask)allFields[i].GetValue(obj)).value);
                 }
                 else if (allFields[i].FieldType.IsPrimitive || allFields[i].FieldType.IsEnum || allFields[i].FieldType.Equals(typeof(string)) || allFields[i].FieldType.Equals(typeof(Vector2)) || allFields[i].FieldType.Equals(typeof(Vector3)) || allFields[i].FieldType.Equals(typeof(Vector4)) || allFields[i].FieldType.Equals(typeof(Quaternion)) || allFields[i].FieldType.Equals(typeof(Matrix4x4)) || allFields[i].FieldType.Equals(typeof(Color)) || allFields[i].FieldType.Equals(typeof(Rect)))
                 {
                     dict.Add(key, allFields[i].GetValue(obj));
                 }
                 else if (allFields[i].FieldType.Equals(typeof(AnimationCurve)))
                 {
                     AnimationCurve animationCurve           = allFields[i].GetValue(obj) as AnimationCurve;
                     Dictionary <string, object> dictionary2 = new Dictionary <string, object>();
                     if (animationCurve.keys != null)
                     {
                         Keyframe[]            keys  = animationCurve.keys;
                         List <List <object> > list3 = new List <List <object> >();
                         for (int k = 0; k < keys.Length; k++)
                         {
                             list3.Add(new List <object>
                             {
                                 keys[k].time,
                                 keys[k].value,
                                 keys[k].inTangent,
                                 keys[k].outTangent,
                                 keys[k].tangentMode
                             });
                         }
                         dictionary2.Add("Keys", list3);
                     }
                     dictionary2.Add("PreWrapMode", animationCurve.preWrapMode);
                     dictionary2.Add("PostWrapMode", animationCurve.postWrapMode);
                     dict.Add(key, dictionary2);
                 }
                 else
                 {
                     Dictionary <string, object> value = new Dictionary <string, object>();
                     JSONSerialization.SerializeFields(allFields[i].GetValue(obj), ref value, ref unityObjects);
                     dict.Add(key, value);
                 }
             }
         }
     }
 }