/// <summary>
        /// 通过序列化信息解析数据
        /// </summary>
        /// <param name="force">强制解析</param>
        /// <param name="behaviorSource"></param>
        /// <returns></returns>
        public bool CheckForSerialization(bool force, BehaviorSource behaviorSource = null)
        {
            bool flag = (behaviorSource == null) ? this.HasSerialized : behaviorSource.HasSerialized;

            if (!flag || force)
            {
                if (behaviorSource != null)
                {
                    behaviorSource.HasSerialized = true;
                }
                else
                {
                    this.HasSerialized = true;
                }
                if (this.mTaskData != null && !string.IsNullOrEmpty(this.mTaskData.JSONSerialization))
                {
                    JSONDeserialization.Load(this.mTaskData, (behaviorSource != null) ? behaviorSource : this);
                }
                else
                {
                    BinaryDeserialization.Load(this.mTaskData, (behaviorSource != null) ? behaviorSource : this);
                }
                return(true);
            }
            return(false);
        }
Beispiel #2
0
 static int InitializePropertyMapping(IntPtr L)
 {
     try
     {
         ToLua.CheckArgsCount(L, 2);
         BehaviorDesigner.Runtime.SharedVariable obj  = (BehaviorDesigner.Runtime.SharedVariable)ToLua.CheckObject <BehaviorDesigner.Runtime.SharedVariable>(L, 1);
         BehaviorDesigner.Runtime.BehaviorSource arg0 = (BehaviorDesigner.Runtime.BehaviorSource)ToLua.CheckObject <BehaviorDesigner.Runtime.BehaviorSource>(L, 2);
         obj.InitializePropertyMapping(arg0);
         return(0);
     }
     catch (Exception e)
     {
         return(LuaDLL.toluaL_exception(L, e));
     }
 }
Beispiel #3
0
 // Token: 0x06000253 RID: 595 RVA: 0x00010DE0 File Offset: 0x0000EFE0
 public override void InitializePropertyMapping(BehaviorSource behaviorSource)
 {
     if (!Application.isPlaying || !(behaviorSource.Owner.GetObject() is Behavior))
     {
         return;
     }
     if (!string.IsNullOrEmpty(base.PropertyMapping))
     {
         string[] array = base.PropertyMapping.Split(new char[]
         {
             '/'
         });
         GameObject gameObject;
         if (!object.Equals(base.PropertyMappingOwner, null))
         {
             gameObject = base.PropertyMappingOwner;
         }
         else
         {
             gameObject = (behaviorSource.Owner.GetObject() as Behavior).gameObject;
         }
         Component    component = gameObject.GetComponent(TaskUtility.GetTypeWithinAssembly(array[0]));
         Type         type      = component.GetType();
         PropertyInfo property  = type.GetProperty(array[1]);
         if (property != null)
         {
             MethodInfo methodInfo = property.GetGetMethod();
             if (methodInfo != null)
             {
                 this.mGetter = (Func <T>)Delegate.CreateDelegate(typeof(Func <T>), component, methodInfo);
             }
             methodInfo = property.GetSetMethod();
             if (methodInfo != null)
             {
                 this.mSetter = (Action <T>)Delegate.CreateDelegate(typeof(Action <T>), component, methodInfo);
             }
         }
     }
 }
Beispiel #4
0
 // Token: 0x0600024F RID: 591 RVA: 0x00010DD4 File Offset: 0x0000EFD4
 public virtual void InitializePropertyMapping(BehaviorSource behaviorSource)
 {
 }
Beispiel #5
0
 public Behavior()
 {
     base.\u002Ector();
     this.mBehaviorSource = new BehaviorSource((IBehavior)this);
 }
Beispiel #6
0
 public void SetBehaviorSource(BehaviorSource behaviorSource)
 {
     this.mBehaviorSource = behaviorSource;
 }
        // Token: 0x0600016E RID: 366 RVA: 0x0000D74C File Offset: 0x0000B94C
        public static Task DeserializeTask(BehaviorSource behaviorSource, Dictionary <string, object> dict, ref Dictionary <int, Task> IDtoTask, List <UnityEngine.Object> unityObjects)
        {
            Task task = null;

            try
            {
                Type type = TaskUtility.GetTypeWithinAssembly(dict["ObjectType"] as string);
                if (type == null)
                {
                    if (dict.ContainsKey("Children"))
                    {
                        type = typeof(UnknownParentTask);
                    }
                    else
                    {
                        type = typeof(UnknownTask);
                    }
                }
                task = (TaskUtility.CreateInstance(type) as Task);
            }
            catch (Exception)
            {
            }
            if (task == null)
            {
                return(null);
            }
            task.Owner = (behaviorSource.Owner.GetObject() as Behavior);
            task.ID    = Convert.ToInt32(dict["ID"]);
            object obj;

            if (dict.TryGetValue("Name", out obj))
            {
                task.FriendlyName = (string)obj;
            }
            if (dict.TryGetValue("Instant", out obj))
            {
                task.IsInstant = Convert.ToBoolean(obj);
            }
            if (dict.TryGetValue("Disabled", out obj))
            {
                task.Disabled = Convert.ToBoolean(obj);
            }
            IDtoTask.Add(task.ID, task);
            task.NodeData = JSONDeserializationDeprecated.DeserializeNodeData(dict["NodeData"] as Dictionary <string, object>, task);
            if (task.GetType().Equals(typeof(UnknownTask)) || task.GetType().Equals(typeof(UnknownParentTask)))
            {
                if (!task.FriendlyName.Contains("Unknown "))
                {
                    task.FriendlyName = string.Format("Unknown {0}", task.FriendlyName);
                }
                if (!task.NodeData.Comment.Contains("Loaded from an unknown type. Was a task renamed or deleted?"))
                {
                    task.NodeData.Comment = string.Format("Loaded from an unknown type. Was a task renamed or deleted?{0}", (!task.NodeData.Comment.Equals(string.Empty)) ? string.Format("\0{0}", task.NodeData.Comment) : string.Empty);
                }
            }
            JSONDeserializationDeprecated.DeserializeObject(task, task, dict, behaviorSource, unityObjects);
            if (task is ParentTask && dict.TryGetValue("Children", out obj))
            {
                ParentTask parentTask = task as ParentTask;
                if (parentTask != null)
                {
                    foreach (object obj2 in (obj as IEnumerable))
                    {
                        Dictionary <string, object> dict2 = (Dictionary <string, object>)obj2;
                        Task child = JSONDeserializationDeprecated.DeserializeTask(behaviorSource, dict2, ref IDtoTask, unityObjects);
                        int  index = (parentTask.Children != null) ? parentTask.Children.Count : 0;
                        parentTask.AddChild(child, index);
                    }
                }
            }
            return(task);
        }
        // Token: 0x0600016B RID: 363 RVA: 0x0000D2C4 File Offset: 0x0000B4C4
        public static void Load(TaskSerializationData taskData, BehaviorSource behaviorSource)
        {
            behaviorSource.EntryTask     = null;
            behaviorSource.RootTask      = null;
            behaviorSource.DetachedTasks = null;
            behaviorSource.Variables     = null;
            Dictionary <string, object> dictionary;

            if (!JSONDeserializationDeprecated.serializationCache.TryGetValue(taskData.JSONSerialization.GetHashCode(), out dictionary))
            {
                dictionary = (MiniJSON.Deserialize(taskData.JSONSerialization) as Dictionary <string, object>);
                JSONDeserializationDeprecated.serializationCache.Add(taskData.JSONSerialization.GetHashCode(), dictionary);
            }
            if (dictionary == null)
            {
                Debug.Log("Failed to deserialize");
                return;
            }
            JSONDeserializationDeprecated.taskIDs = new Dictionary <JSONDeserializationDeprecated.TaskField, List <int> >();
            Dictionary <int, Task> dictionary2 = new Dictionary <int, Task>();

            JSONDeserializationDeprecated.DeserializeVariables(behaviorSource, dictionary, taskData.fieldSerializationData.unityObjects);
            if (dictionary.ContainsKey("EntryTask"))
            {
                behaviorSource.EntryTask = JSONDeserializationDeprecated.DeserializeTask(behaviorSource, dictionary["EntryTask"] as Dictionary <string, object>, ref dictionary2, taskData.fieldSerializationData.unityObjects);
            }
            if (dictionary.ContainsKey("RootTask"))
            {
                behaviorSource.RootTask = JSONDeserializationDeprecated.DeserializeTask(behaviorSource, dictionary["RootTask"] as Dictionary <string, object>, ref dictionary2, taskData.fieldSerializationData.unityObjects);
            }
            if (dictionary.ContainsKey("DetachedTasks"))
            {
                List <Task> list = new List <Task>();
                foreach (object obj in (dictionary["DetachedTasks"] as IEnumerable))
                {
                    Dictionary <string, object> dict = (Dictionary <string, object>)obj;
                    list.Add(JSONDeserializationDeprecated.DeserializeTask(behaviorSource, dict, ref dictionary2, taskData.fieldSerializationData.unityObjects));
                }
                behaviorSource.DetachedTasks = list;
            }
            if (JSONDeserializationDeprecated.taskIDs != null && JSONDeserializationDeprecated.taskIDs.Count > 0)
            {
                foreach (JSONDeserializationDeprecated.TaskField key in JSONDeserializationDeprecated.taskIDs.Keys)
                {
                    List <int> list2     = JSONDeserializationDeprecated.taskIDs[key];
                    Type       fieldType = key.fieldInfo.FieldType;
                    if (key.fieldInfo.FieldType.IsArray)
                    {
                        int num = 0;
                        for (int i = 0; i < list2.Count; i++)
                        {
                            Task task = dictionary2[list2[i]];
                            if (task.GetType().Equals(fieldType.GetElementType()) || task.GetType().IsSubclassOf(fieldType.GetElementType()))
                            {
                                num++;
                            }
                        }
                        Array array = Array.CreateInstance(fieldType.GetElementType(), num);
                        int   num2  = 0;
                        for (int j = 0; j < list2.Count; j++)
                        {
                            Task task2 = dictionary2[list2[j]];
                            if (task2.GetType().Equals(fieldType.GetElementType()) || task2.GetType().IsSubclassOf(fieldType.GetElementType()))
                            {
                                array.SetValue(task2, num2);
                                num2++;
                            }
                        }
                        key.fieldInfo.SetValue(key.task, array);
                    }
                    else
                    {
                        Task task3 = dictionary2[list2[0]];
                        if (task3.GetType().Equals(key.fieldInfo.FieldType) || task3.GetType().IsSubclassOf(key.fieldInfo.FieldType))
                        {
                            key.fieldInfo.SetValue(key.task, task3);
                        }
                    }
                }
                JSONDeserializationDeprecated.taskIDs = null;
            }
        }
Beispiel #9
0
 public Behavior()
 {
     this.mBehaviorSource = new BehaviorSource(this);
 }
        public static Task DeserializeTask(BehaviorSource behaviorSource, Dictionary <string, object> dict, ref Dictionary <int, Task> IDtoTask, List <UnityEngine.Object> unityObjects)
        {
            Task task = null;

            try
            {
                Type type = TaskUtility.GetTypeWithinAssembly(dict["Type"] as string);
                if (type == null)
                {
                    if (dict.ContainsKey("Children"))
                    {
                        type = typeof(UnknownParentTask);
                    }
                    else
                    {
                        type = typeof(UnknownTask);
                    }
                }
                task = (TaskUtility.CreateInstance(type) as Task);
                if (task is UnknownTask)
                {
                    UnknownTask unknownTask = task as UnknownTask;
                    unknownTask.JSONSerialization = MiniJSON.Serialize(dict);
                }
            }
            catch (Exception)
            {
            }
            if (task == null)
            {
                return(null);
            }
            task.Owner = (behaviorSource.Owner.GetObject() as Behavior);
            task.ID    = Convert.ToInt32(dict["ID"], CultureInfo.InvariantCulture);
            object obj;

            if (dict.TryGetValue("Name", out obj))
            {
                task.FriendlyName = (string)obj;
            }
            if (dict.TryGetValue("Instant", out obj))
            {
                task.IsInstant = Convert.ToBoolean(obj, CultureInfo.InvariantCulture);
            }
            if (dict.TryGetValue("Disabled", out obj))
            {
                task.Disabled = Convert.ToBoolean(obj, CultureInfo.InvariantCulture);
            }
            IDtoTask.Add(task.ID, task);
            task.NodeData = JSONDeserialization.DeserializeNodeData(dict["NodeData"] as Dictionary <string, object>, task);
            if (task.GetType().Equals(typeof(UnknownTask)) || task.GetType().Equals(typeof(UnknownParentTask)))
            {
                if (!task.FriendlyName.Contains("Unknown "))
                {
                    task.FriendlyName = string.Format("Unknown {0}", task.FriendlyName);
                }
                task.NodeData.Comment = "Unknown Task. Right click and Replace to locate new task.";
            }
            JSONDeserialization.DeserializeObject(task, task, dict, behaviorSource, unityObjects);
            if (task is ParentTask && dict.TryGetValue("Children", out obj))
            {
                ParentTask parentTask = task as ParentTask;
                if (parentTask != null)
                {
                    foreach (Dictionary <string, object> dict2 in (obj as IEnumerable))
                    {
                        Task child = JSONDeserialization.DeserializeTask(behaviorSource, dict2, ref IDtoTask, unityObjects);
                        int  index = (parentTask.Children != null) ? parentTask.Children.Count : 0;
                        parentTask.AddChild(child, index);
                    }
                }
            }
            return(task);
        }