Ejemplo n.º 1
0
 public void AddChildNode(NodeDesigner childNodeDesigner, NodeConnection nodeConnection, bool adjustOffset, bool replaceNode, int replaceNodeIndex)
 {
     if (replaceNode)
     {
         ParentTask parentTask = this.mTask as ParentTask;
         parentTask.Children[replaceNodeIndex] = childNodeDesigner.Task;
     }
     else
     {
         if (!this.isEntryDisplay)
         {
             ParentTask parentTask2 = this.mTask as ParentTask;
             int        i           = 0;
             if (parentTask2.Children != null)
             {
                 for (i = 0; i < parentTask2.Children.Count; i++)
                 {
                     if (childNodeDesigner.GetAbsolutePosition().x < (parentTask2.Children[i].NodeData.NodeDesigner as NodeDesigner).GetAbsolutePosition().x)
                     {
                         break;
                     }
                 }
             }
             parentTask2.AddChild(childNodeDesigner.Task, i);
         }
         if (adjustOffset)
         {
             childNodeDesigner.Task.NodeData.Offset -= this.GetAbsolutePosition();
         }
     }
     childNodeDesigner.ParentNodeDesigner   = this;
     nodeConnection.DestinationNodeDesigner = childNodeDesigner;
     nodeConnection.NodeConnectionType      = NodeConnectionType.Fixed;
     if (!nodeConnection.OriginatingNodeDesigner.Equals(this))
     {
         nodeConnection.OriginatingNodeDesigner = this;
     }
     this.outgoingNodeConnections.Add(nodeConnection);
     this.mConnectionIsDirty = true;
 }
        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);
        }
Ejemplo n.º 3
0
    public static void Load(TaskSerializationData taskData, BehaviorSource behaviorSource)
    {
        behaviorSource.EntryTask     = null;
        behaviorSource.RootTask      = null;
        behaviorSource.DetachedTasks = null;
        behaviorSource.Variables     = null;
        FieldSerializationData fieldSerializationData;

        if (taskData == null || (fieldSerializationData = taskData.fieldSerializationData).byteData == null || fieldSerializationData.byteData.Count == 0)
        {
            return;
        }
        fieldSerializationData.byteDataArray = fieldSerializationData.byteData.ToArray();
        taskIDs = null;
        if (taskData.variableStartIndex != null)
        {
            List <SharedVariable>    list       = new List <SharedVariable>();
            Dictionary <string, int> dictionary = ObjectPool.Get <Dictionary <string, int> >();
            for (int i = 0; i < taskData.variableStartIndex.Count; i++)
            {
                int num = taskData.variableStartIndex[i];
                int num2;
                if (i + 1 < taskData.variableStartIndex.Count)
                {
                    num2 = taskData.variableStartIndex[i + 1];
                }
                else if (taskData.startIndex != null && taskData.startIndex.Count > 0)
                {
                    num2 = taskData.startIndex[0];
                }
                else
                {
                    num2 = fieldSerializationData.startIndex.Count;
                }
                dictionary.Clear();
                for (int j = num; j < num2; j++)
                {
                    dictionary.Add(fieldSerializationData.typeName[j], fieldSerializationData.startIndex[j]);
                }
                SharedVariable sharedVariable = BytesToSharedVariable(fieldSerializationData, dictionary, fieldSerializationData.byteDataArray, taskData.variableStartIndex[i], behaviorSource, false, string.Empty);
                if (sharedVariable != null)
                {
                    list.Add(sharedVariable);
                }
            }
            ObjectPool.Return(dictionary);
            behaviorSource.Variables = list;
        }
        List <Task> list2 = new List <Task>();

        if (taskData.types != null)
        {
            for (int k = 0; k < taskData.types.Count; k++)
            {
                LoadTask(taskData, fieldSerializationData, ref list2, ref behaviorSource);
            }
        }
        if (taskData.parentIndex.Count != list2.Count)
        {
            Debug.LogError("Deserialization Error: parent index count does not match task list count");
            return;
        }
        for (int l = 0; l < taskData.parentIndex.Count; l++)
        {
            if (taskData.parentIndex[l] == -1)
            {
                if (behaviorSource.EntryTask == null)
                {
                    behaviorSource.EntryTask = list2[l];
                }
                else
                {
                    if (behaviorSource.DetachedTasks == null)
                    {
                        behaviorSource.DetachedTasks = new List <Task>();
                    }
                    behaviorSource.DetachedTasks.Add(list2[l]);
                }
            }
            else if (taskData.parentIndex[l] == 0)
            {
                behaviorSource.RootTask = list2[l];
            }
            else if (taskData.parentIndex[l] != -1)
            {
                ParentTask parentTask = list2[taskData.parentIndex[l]] as ParentTask;
                if (parentTask != null)
                {
                    int index = (parentTask.Children != null) ? parentTask.Children.Count : 0;
                    parentTask.AddChild(list2[l], index);
                }
            }
        }
        if (taskIDs != null)
        {
            foreach (ObjectFieldMap current in taskIDs.Keys)
            {
                List <int> list3     = BinaryDeserialization.taskIDs[current];
                Type       fieldType = current.fieldInfo.FieldType;
                if (typeof(IList).IsAssignableFrom(fieldType))
                {
                    if (fieldType.IsArray)
                    {
                        Type  elementType = fieldType.GetElementType();
                        Array array       = Array.CreateInstance(elementType, list3.Count);
                        for (int m = 0; m < array.Length; m++)
                        {
                            array.SetValue(list2[list3[m]], m);
                        }
                        current.fieldInfo.SetValue(current.obj, array);
                    }
                    else
                    {
                        Type  type  = fieldType.GetGenericArguments()[0];
                        IList list4 = TaskUtility.CreateInstance(typeof(List <>).MakeGenericType(new Type[]
                        {
                            type
                        })) as IList;
                        for (int n = 0; n < list3.Count; n++)
                        {
                            list4.Add(list2[list3[n]]);
                        }
                        current.fieldInfo.SetValue(current.obj, list4);
                    }
                }
                else
                {
                    current.fieldInfo.SetValue(current.obj, list2[list3[0]]);
                }
            }
        }
    }
Ejemplo n.º 4
0
        // Token: 0x06000159 RID: 345 RVA: 0x0000C0A0 File Offset: 0x0000A2A0
        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"]);
            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 = 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 (object obj2 in (obj as IEnumerable))
                    {
                        Dictionary <string, object> dict2 = (Dictionary <string, object>)obj2;
                        Task child = JSONDeserialization.DeserializeTask(behaviorSource, dict2, ref IDtoTask, unityObjects);
                        int  index = (parentTask.Children != null) ? parentTask.Children.Count : 0;
                        parentTask.AddChild(child, index);
                    }
                }
            }
            return(task);
        }