Example #1
0
        public bool CheckForSerialization(bool force, BehaviorSource behaviorSource = null)
        {
            bool flag = (behaviorSource == null) ? this.m_HasSerialized : behaviorSource.m_HasSerialized;

            if (!flag || force)
            {
                if (behaviorSource != null)
                {
                    behaviorSource.m_HasSerialized = true;
                }
                else
                {
                    this.m_HasSerialized = true;
                }
                if (this.m_TaskData != null && !string.IsNullOrEmpty(this.m_TaskData.JSONSerialization))
                {
                    JSONDeserialization.Load(this.m_TaskData, (behaviorSource != null) ? behaviorSource : this);
                }
                else
                {
                    BinaryDeserialization.Load(this.m_TaskData, (behaviorSource != null) ? behaviorSource : this);
                }
                return(true);
            }
            return(false);
        }
 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;
         }
         if (gameObject == null)
         {
             Debug.LogError("Error: Unable to find GameObject on " + behaviorSource.behaviorName + " for property mapping with variable " + base.Name);
             return;
         }
         Component component = gameObject.GetComponent(TaskUtility.GetTypeWithinAssembly(array[0]));
         if (component == null)
         {
             Debug.LogError("Error: Unable to find component on " + behaviorSource.behaviorName + " for property mapping with variable " + base.Name);
             return;
         }
         Type         type     = component.GetType();
         PropertyInfo property = type.GetProperty(array[1]);
         if (property != null)
         {
             MethodInfo methodInfo = property.GetGetMethod();
             if (methodInfo != null)
             {
                 this.m_Getter = (Func <T>)Delegate.CreateDelegate(typeof(Func <T>), component, methodInfo);
             }
             methodInfo = property.GetSetMethod();
             if (methodInfo != null)
             {
                 this.m_Setter = (Action <T>)Delegate.CreateDelegate(typeof(Action <T>), component, methodInfo);
             }
         }
     }
 }
        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> tasks = new List <Task>();
                foreach (Dictionary <string, object> dict in (dictionary["DetachedTasks"] as IEnumerable))
                {
                    tasks.Add(JSONDeserializationDeprecated.DeserializeTask(behaviorSource, dict, ref dictionary2, taskData.fieldSerializationData.unityObjects));
                }
                behaviorSource.detachedTasks = tasks;
            }
            if (JSONDeserializationDeprecated.taskIDs != null && JSONDeserializationDeprecated.taskIDs.Count > 0)
            {
                foreach (JSONDeserializationDeprecated.TaskField current in JSONDeserializationDeprecated.taskIDs.Keys)
                {
                    List <int> list2     = JSONDeserializationDeprecated.taskIDs[current];
                    Type       fieldType = current.fieldInfo.FieldType;
                    if (current.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++;
                            }
                        }
                        current.fieldInfo.SetValue(current.task, array);
                    }
                    else
                    {
                        Task task3 = dictionary2[list2[0]];
                        if (task3.GetType().Equals(current.fieldInfo.FieldType) || task3.GetType().IsSubclassOf(current.fieldInfo.FieldType))
                        {
                            current.fieldInfo.SetValue(current.task, task3);
                        }
                    }
                }
                JSONDeserializationDeprecated.taskIDs = null;
            }
        }
        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 (Dictionary <string, object> dict2 in (obj as IEnumerable))
                    {
                        Task child = JSONDeserializationDeprecated.DeserializeTask(behaviorSource, dict2, ref IDtoTask, unityObjects);
                        int  index = (parentTask.Children != null) ? parentTask.Children.Count : 0;
                        parentTask.AddChild(child, index);
                    }
                }
            }
            return(task);
        }
Example #5
0
 public void SetBehaviorSource(BehaviorSource behaviorSource)
 {
     this.mBehaviorSource = behaviorSource;
 }
Example #6
0
 public Behavior()
 {
     this.m_BehaviorSource = new BehaviorSource(this);
 }
Example #7
0
 public virtual void InitializePropertyMapping(BehaviorSource behaviorSource)
 {
 }