コード例 #1
0
        public static void Save(BehaviorSource behaviorSource)
        {
            behaviorSource.CheckForSerialization(false, null);
            SerializeJSON.taskSerializationData  = new TaskSerializationData();
            SerializeJSON.fieldSerializationData = SerializeJSON.taskSerializationData.fieldSerializationData;
            Dictionary <string, object> dictionary = new Dictionary <string, object>();

            if (behaviorSource.EntryTask != null)
            {
                dictionary.Add("EntryTask", SerializeJSON.SerializeTask(behaviorSource.EntryTask, true, ref SerializeJSON.fieldSerializationData.unityObjects));
            }
            if (behaviorSource.RootTask != null)
            {
                dictionary.Add("RootTask", SerializeJSON.SerializeTask(behaviorSource.RootTask, true, ref SerializeJSON.fieldSerializationData.unityObjects));
            }
            if (behaviorSource.DetachedTasks != null && behaviorSource.DetachedTasks.Count > 0)
            {
                Dictionary <string, object>[] array = new Dictionary <string, object> [behaviorSource.DetachedTasks.Count];
                for (int i = 0; i < behaviorSource.DetachedTasks.Count; i++)
                {
                    array[i] = SerializeJSON.SerializeTask(behaviorSource.DetachedTasks[i], true, ref SerializeJSON.fieldSerializationData.unityObjects);
                }
                dictionary.Add("DetachedTasks", array);
            }
            if (behaviorSource.Variables != null && behaviorSource.Variables.Count > 0)
            {
                dictionary.Add("Variables", SerializeJSON.SerializeVariables(behaviorSource.Variables, ref SerializeJSON.fieldSerializationData.unityObjects));
            }
            SerializeJSON.taskSerializationData.JSONSerialization = MiniJSON.Serialize(dictionary);
            behaviorSource.TaskData = SerializeJSON.taskSerializationData;
            if (behaviorSource.Owner != null)
            {
                EditorUtility.SetDirty(behaviorSource.Owner.GetObject());
            }
        }
コード例 #2
0
 public static void Save(BehaviorSource behaviorSource)
 {
     BinarySerialization.fieldIndex             = 0;
     BinarySerialization.taskSerializationData  = new TaskSerializationData();
     BinarySerialization.fieldSerializationData = BinarySerialization.taskSerializationData.fieldSerializationData;
     if (behaviorSource.Variables != null)
     {
         for (int i = 0; i < behaviorSource.Variables.Count; i++)
         {
             BinarySerialization.taskSerializationData.variableStartIndex.Add(BinarySerialization.fieldSerializationData.startIndex.Count);
             BinarySerialization.SaveSharedVariable(behaviorSource.Variables[i], string.Empty);
         }
     }
     if (!object.ReferenceEquals(behaviorSource.EntryTask, null))
     {
         BinarySerialization.SaveTask(behaviorSource.EntryTask, -1);
     }
     if (!object.ReferenceEquals(behaviorSource.RootTask, null))
     {
         BinarySerialization.SaveTask(behaviorSource.RootTask, 0);
     }
     if (behaviorSource.DetachedTasks != null)
     {
         for (int j = 0; j < behaviorSource.DetachedTasks.Count; j++)
         {
             BinarySerialization.SaveTask(behaviorSource.DetachedTasks[j], -1);
         }
     }
     behaviorSource.TaskData = BinarySerialization.taskSerializationData;
     if (behaviorSource.Owner != null)
     {
         EditorUtility.SetDirty(behaviorSource.Owner.GetObject());
     }
 }
コード例 #3
0
        // Token: 0x06000179 RID: 377 RVA: 0x0000CEA8 File Offset: 0x0000B0A8
        public static List <ErrorDetails> CheckForErrors(BehaviorSource behaviorSource)
        {
            if (behaviorSource == null || behaviorSource.EntryTask == null)
            {
                return(null);
            }
            List <ErrorDetails> result = null;
            bool flag = AssetDatabase.GetAssetPath(behaviorSource.Owner.GetObject()).Length > 0;

            ErrorCheck.CheckTaskForErrors(behaviorSource.EntryTask, flag, ref result);
            if (behaviorSource.RootTask == null)
            {
                ErrorCheck.AddError(ref result, ErrorDetails.ErrorType.MissingChildren, behaviorSource.EntryTask, -1, null);
            }
            if (behaviorSource.RootTask != null)
            {
                ErrorCheck.CheckTaskForErrors(behaviorSource.RootTask, flag, ref result);
            }
            if (!EditorApplication.isPlaying && flag && behaviorSource.Variables != null)
            {
                for (int i = 0; i < behaviorSource.Variables.Count; i++)
                {
                    object value = behaviorSource.Variables[i].GetValue();
                    if (value is Object && AssetDatabase.GetAssetPath(value as Object).Length == 0)
                    {
                        ErrorCheck.AddError(ref result, ErrorDetails.ErrorType.InvalidVariableReference, null, i, behaviorSource.Variables[i].Name);
                    }
                }
            }
            return(result);
        }
コード例 #4
0
        protected FubuMVC.Swank.Specification.Specification BuildSpec <TNamespace>(BehaviorGraph graph, Action <Swank> configure = null, string specFile = null)
        {
            var configuration = Swank.CreateConfig(x =>
            {
                if (configure != null)
                {
                    configure(x);
                }

                x.AppliesToThisAssembly()
                .Where(y => y.FirstCall().HandlerType.InNamespace <TNamespace>());

                if (specFile != null)
                {
                    x.MergeThisSpecification(specFile);
                }
            });

            var behaviorSource     = new BehaviorSource(graph, configuration);
            var resourceConvention = new ResourceConvention(new MarkerConvention <ResourceDescription>(), behaviorSource);
            var moduleConvention   = new ModuleConvention(new MarkerConvention <ModuleDescription>());

            return(new FubuMVC.Swank.Specification.SpecificationService(configuration,
                                                                        behaviorSource,
                                                                        new TypeDescriptorCache(),
                                                                        moduleConvention,
                                                                        resourceConvention,
                                                                        new EndpointConvention(),
                                                                        new MemberConvention(),
                                                                        new OptionConvention(),
                                                                        new StatusCodeConvention(),
                                                                        new HeaderConvention(),
                                                                        new TypeConvention(),
                                                                        new MergeService()).Generate());
        }
コード例 #5
0
    private static void ExportBehavior(string className, StreamWriter fileWriter, BehaviorSource behaviorSource)
    {
        fileWriter.Write(string.Format("{0} = {1}.New()", className, "BehaviorTreeRoot") + line_end);
        fileWriter.Write(line_end);

        fileWriter.Write(string.Format("function {0}.New()", className) + line_end);
        fileWriter.Write(line_end);
        fileWriter.Write(string.Format("\tlocal root = {{}}") + line_end);
        fileWriter.Write(string.Format("\tsetmetatable(root,  {{__index = {0}}})", className) + line_end);
        fileWriter.Write(string.Format("\troot.__index = root") + line_end);
        fileWriter.Write(string.Format("\troot.name = \"{0}\"", className) + line_end);

        int nodeIdx = 0;

        fileWriter.Write(string.Format("\tdo") + line_end);
        ExportToLua.ExportNode(fileWriter, "root", behaviorSource.RootTask, 2, ref nodeIdx);
        fileWriter.Write(string.Format("\tend") + line_end);

        fileWriter.Write(line_end);
        fileWriter.Write(string.Format("\treturn root") + line_end);
        fileWriter.Write(string.Format("end") + line_end);

        fileWriter.Write(line_end);
        fileWriter.Write(string.Format("return {0}.New()", className) + line_end);
    }
コード例 #6
0
        // Token: 0x0600025A RID: 602 RVA: 0x0001652C File Offset: 0x0001472C
        public static Task PasteTask(BehaviorSource behaviorSource, TaskSerializer serializer)
        {
            Dictionary <int, Task> dictionary = new Dictionary <int, Task>();
            Task task = JSONDeserialization.DeserializeTask(behaviorSource, MiniJSON.Deserialize(serializer.serialization) as Dictionary <string, object>, ref dictionary, serializer.unityObjects);

            TaskCopier.CheckSharedVariables(behaviorSource, task);
            return(task);
        }
コード例 #7
0
 public static bool LeftMouseDown(IVariableSource variableSource, BehaviorSource behaviorSource, Vector2 mousePosition, List <float> variablePosition, float variableStartPosition, Vector2 scrollPosition, ref int selectedVariableIndex, ref string selectedVariableName, ref int selectedVariableTypeIndex)
 {
     if (variablePosition != null && mousePosition.y > variableStartPosition && variableSource != null)
     {
         List <SharedVariable> allVariables;
         if (!Application.isPlaying && behaviorSource != null && behaviorSource.Owner is Behavior)
         {
             Behavior behavior = behaviorSource.Owner as Behavior;
             if (behavior.ExternalBehavior != null)
             {
                 BehaviorSource behaviorSource2 = behavior.GetBehaviorSource();
                 behaviorSource2.CheckForSerialization(true, null);
                 allVariables = behaviorSource2.GetAllVariables();
                 ExternalBehavior externalBehavior = behavior.ExternalBehavior;
                 externalBehavior.BehaviorSource.Owner = externalBehavior;
                 externalBehavior.BehaviorSource.CheckForSerialization(true, behaviorSource);
             }
             else
             {
                 allVariables = variableSource.GetAllVariables();
             }
         }
         else
         {
             allVariables = variableSource.GetAllVariables();
         }
         if (allVariables == null || allVariables.Count != variablePosition.Count)
         {
             return(false);
         }
         int i = 0;
         while (i < variablePosition.Count)
         {
             if (mousePosition.y < variablePosition[i] - scrollPosition.y)
             {
                 if (i == selectedVariableIndex)
                 {
                     return(false);
                 }
                 selectedVariableIndex     = i;
                 selectedVariableName      = allVariables[i].Name;
                 selectedVariableTypeIndex = VariableInspector.sharedVariableTypesDict[allVariables[i].GetType().Name];
                 return(true);
             }
             else
             {
                 i++;
             }
         }
     }
     if (selectedVariableIndex != -1)
     {
         selectedVariableIndex = -1;
         return(true);
     }
     return(false);
 }
コード例 #8
0
ファイル: Tests.cs プロジェクト: mikeobrien/FubuMVC.Swank
        public void should_enumerate_actions_in_all_assemblies_except_the_swank_assembly_by_default()
        {
            _graph.AddAction <GetHandler>("GET");

            var chains = new BehaviorSource(_graph, new Configuration()).GetChains();

            chains.Count.ShouldEqual(4);
            chains.All(x => x.FirstCall().HandlerType.Assembly == Assembly.GetExecutingAssembly()).ShouldBeTrue();
        }
コード例 #9
0
        // Token: 0x060002C3 RID: 707 RVA: 0x0001BA68 File Offset: 0x00019C68
        private static void ShowPropertyMappingMenu(BehaviorSource behaviorSource, SharedVariable sharedVariable)
        {
            VariableInspector.mPropertyMappingVariable       = sharedVariable;
            VariableInspector.mPropertyMappingBehaviorSource = behaviorSource;
            VariableInspector.mPropertyMappingMenu           = new GenericMenu();
            List <string>     list  = new List <string>();
            List <GameObject> list2 = new List <GameObject>();

            list.Add("None");
            list2.Add(null);
            int num = 0;

            if (behaviorSource.Owner.GetObject() is Behavior)
            {
                GameObject gameObject = (behaviorSource.Owner.GetObject() as Behavior).gameObject;
                int        num2;
                if ((num2 = VariableInspector.AddPropertyName(sharedVariable, gameObject, ref list, ref list2, true)) != -1)
                {
                    num = num2;
                }
                GameObject[] array;
                if (AssetDatabase.GetAssetPath(gameObject).Length == 0)
                {
                    array = Object.FindObjectsOfType <GameObject>();
                }
                else
                {
                    Transform[] componentsInChildren = gameObject.GetComponentsInChildren <Transform>();
                    array = new GameObject[componentsInChildren.Length];
                    for (int i = 0; i < componentsInChildren.Length; i++)
                    {
                        array[i] = componentsInChildren[i].gameObject;
                    }
                }
                for (int j = 0; j < array.Length; j++)
                {
                    if (!array[j].Equals(gameObject) && (num2 = VariableInspector.AddPropertyName(sharedVariable, array[j], ref list, ref list2, false)) != -1)
                    {
                        num = num2;
                    }
                }
            }
            for (int k = 0; k < list.Count; k++)
            {
                string[] array2 = list[k].Split(new char[]
                {
                    '.'
                });
                if (list2[k] != null)
                {
                    array2[array2.Length - 1] = VariableInspector.GetFullPath(list2[k].transform) + "/" + array2[array2.Length - 1];
                }
                VariableInspector.mPropertyMappingMenu.AddItem(new GUIContent(array2[array2.Length - 1]), k == num, new GenericMenu.MenuFunction2(VariableInspector.PropertySelected), new VariableInspector.SelectedPropertyMapping(list[k], list2[k]));
            }
            VariableInspector.mPropertyMappingMenu.ShowAsContext();
        }
コード例 #10
0
ファイル: Tests.cs プロジェクト: mikeobrien/FubuMVC.Swank
        public void should_only_enumerate_actions_in_the_specified_assemblies()
        {
            _graph.AddAction <GetHandler>("GET");

            var configuration = Swank.CreateConfig(x => x.AppliesTo <Tests>());
            var chains        = new BehaviorSource(_graph, configuration).GetChains();

            chains.Count.ShouldEqual(4);
            chains.All(x => x.FirstCall().HandlerType.Assembly == Assembly.GetExecutingAssembly()).ShouldBeTrue();
        }
コード例 #11
0
ファイル: Tests.cs プロジェクト: mikeobrien/FubuMVC.Swank
        public void should_filter_actions_based_on_filter_in_the_configuration()
        {
            var configuration = Swank.CreateConfig(x => x
                                                   .AppliesToThisAssembly()
                                                   .Where(y => y.Route.Pattern.StartsWith("/handlers/widget")));

            var chains = new BehaviorSource(_graph, configuration).GetChains();

            chains.Count.ShouldEqual(2);
            chains.All(x => x.Route.Pattern.StartsWith("/handlers/widget")).ShouldBeTrue();
        }
コード例 #12
0
        public bool ClearFocus(bool addVariable, BehaviorSource behaviorSource)
        {
            GUIUtility.keyboardControl = 0;
            bool result = false;

            if (addVariable && !string.IsNullOrEmpty(this.mVariableName) && VariableInspector.VariableNameValid(behaviorSource, this.mVariableName))
            {
                result             = VariableInspector.AddVariable(behaviorSource, this.mVariableName, this.mVariableTypeIndex, false);
                this.mVariableName = string.Empty;
            }
            return(result);
        }
コード例 #13
0
 private static void CheckReferences(BehaviorSource behaviorSource, Task task)
 {
     FieldInfo[] allFields = TaskUtility.GetAllFields(task.GetType());
     for (int i = 0; i < allFields.Length; i++)
     {
         if (!allFields[i].FieldType.IsArray && (allFields[i].FieldType.Equals(typeof(Task)) || allFields[i].FieldType.IsSubclassOf(typeof(Task))))
         {
             Task task2 = allFields[i].GetValue(task) as Task;
             if (task2 != null)
             {
                 Task task3 = TaskReferences.FindReferencedTask(behaviorSource, task2);
                 if (task3 != null)
                 {
                     allFields[i].SetValue(task, task3);
                 }
             }
         }
         else if (allFields[i].FieldType.IsArray && (allFields[i].FieldType.GetElementType().Equals(typeof(Task)) || allFields[i].FieldType.GetElementType().IsSubclassOf(typeof(Task))))
         {
             Task[] array = allFields[i].GetValue(task) as Task[];
             if (array != null)
             {
                 IList list = Activator.CreateInstance(typeof(List <>).MakeGenericType(new Type[]
                 {
                     allFields[i].FieldType.GetElementType()
                 })) as IList;
                 for (int j = 0; j < array.Length; j++)
                 {
                     Task task4 = TaskReferences.FindReferencedTask(behaviorSource, array[j]);
                     if (task4 != null)
                     {
                         list.Add(task4);
                     }
                 }
                 Array array2 = Array.CreateInstance(allFields[i].FieldType.GetElementType(), list.Count);
                 list.CopyTo(array2, 0);
                 allFields[i].SetValue(task, array2);
             }
         }
     }
     if (task.GetType().IsSubclassOf(typeof(ParentTask)))
     {
         ParentTask parentTask = task as ParentTask;
         if (parentTask.Children != null)
         {
             for (int k = 0; k < parentTask.Children.Count; k++)
             {
                 TaskReferences.CheckReferences(behaviorSource, parentTask.Children[k]);
             }
         }
     }
 }
コード例 #14
0
 public static void CheckReferences(BehaviorSource behaviorSource)
 {
     if (behaviorSource.RootTask != null)
     {
         TaskReferences.CheckReferences(behaviorSource, behaviorSource.RootTask);
     }
     if (behaviorSource.DetachedTasks != null)
     {
         for (int i = 0; i < behaviorSource.DetachedTasks.Count; i++)
         {
             TaskReferences.CheckReferences(behaviorSource, behaviorSource.DetachedTasks[i]);
         }
     }
 }
コード例 #15
0
    public static void Save(BehaviorSource behaviorSource)
    {
        Init();

        if (behaviorSource == null)
        {
            return;
        }
        if (behaviorSource.EntryTask == null)
        {
            return;
        }

        ExportToLua.ExportTree(behaviorSource);
    }
コード例 #16
0
        // Token: 0x060002BA RID: 698 RVA: 0x0001AC70 File Offset: 0x00018E70
        public static bool SyncVariables(BehaviorSource localBehaviorSource, List <SharedVariable> variables)
        {
            List <SharedVariable> list = localBehaviorSource.GetAllVariables();

            if (variables != null)
            {
                bool result = false;
                if (list == null)
                {
                    list = new List <SharedVariable>();
                    localBehaviorSource.SetAllVariables(list);
                    result = true;
                }
                for (int i = 0; i < variables.Count; i++)
                {
                    if (list.Count - 1 < i)
                    {
                        SharedVariable sharedVariable = Activator.CreateInstance(variables[i].GetType()) as SharedVariable;
                        sharedVariable.Name     = variables[i].Name;
                        sharedVariable.IsShared = true;
                        sharedVariable.SetValue(variables[i].GetValue());
                        list.Add(sharedVariable);
                        result = true;
                    }
                    else if (list[i].Name != variables[i].Name || list[i].GetType() != variables[i].GetType())
                    {
                        SharedVariable sharedVariable2 = Activator.CreateInstance(variables[i].GetType()) as SharedVariable;
                        sharedVariable2.Name     = variables[i].Name;
                        sharedVariable2.IsShared = true;
                        sharedVariable2.SetValue(variables[i].GetValue());
                        list[i] = sharedVariable2;
                        result  = true;
                    }
                }
                for (int j = list.Count - 1; j > variables.Count - 1; j--)
                {
                    list.RemoveAt(j);
                    result = true;
                }
                return(result);
            }
            if (list != null && list.Count > 0)
            {
                list.Clear();
                return(true);
            }
            return(false);
        }
コード例 #17
0
        // Token: 0x060002B9 RID: 697 RVA: 0x0001AB2C File Offset: 0x00018D2C
        public static bool DrawVariables(IVariableSource variableSource, BehaviorSource behaviorSource, ref string variableName, ref bool focusNameField, ref int variableTypeIndex, ref Vector2 scrollPosition, ref List <float> variablePosition, ref float variableStartPosition, ref int selectedVariableIndex, ref string selectedVariableName, ref int selectedVariableTypeIndex)
        {
            scrollPosition = GUILayout.BeginScrollView(scrollPosition, new GUILayoutOption[0]);
            bool flag  = false;
            bool flag2 = false;
            List <SharedVariable> list = (variableSource == null) ? null : variableSource.GetAllVariables();

            if (VariableInspector.DrawHeader(variableSource, behaviorSource == null, ref variableStartPosition, ref variableName, ref focusNameField, ref variableTypeIndex, ref selectedVariableIndex, ref selectedVariableName, ref selectedVariableTypeIndex))
            {
                flag = true;
            }
            list = ((variableSource == null) ? null : variableSource.GetAllVariables());
            if (list != null && list.Count > 0)
            {
                GUI.enabled = !flag2;
                if (VariableInspector.DrawAllVariables(true, variableSource, ref list, true, ref variablePosition, ref selectedVariableIndex, ref selectedVariableName, ref selectedVariableTypeIndex, true, true))
                {
                    flag = true;
                }
            }
            if (flag && variableSource != null)
            {
                variableSource.SetAllVariables(list);
            }
            GUI.enabled = true;
            GUILayout.EndScrollView();
            if (flag && !EditorApplication.isPlayingOrWillChangePlaymode && behaviorSource != null && behaviorSource.Owner is Behavior)
            {
                Behavior behavior = behaviorSource.Owner as Behavior;
                if (behavior.ExternalBehavior != null)
                {
                    if (BehaviorDesignerPreferences.GetBool(BDPreferences.BinarySerialization))
                    {
                        BinarySerialization.Save(behaviorSource);
                    }
                    else
                    {
                        JSONSerialization.Save(behaviorSource);
                    }
                    BehaviorSource behaviorSource2 = behavior.ExternalBehavior.GetBehaviorSource();
                    behaviorSource2.CheckForSerialization(true, null);
                    VariableInspector.SyncVariables(behaviorSource2, list);
                }
            }
            return(flag);
        }
コード例 #18
0
        public void EnableBehavior()
        {
            AgentBehaviorTree.CreateAIBehaviorManager();
            if (Object.op_Inequality((Object)BehaviorManager.instance, (Object)null))
            {
                ((BehaviorManager)BehaviorManager.instance).EnableBehavior((Behavior)this);
            }
            BehaviorSource behaviorSource = this.GetBehaviorSource();

            if (this._initialized)
            {
                return;
            }
            for (int index = 0; index < 12; ++index)
            {
                this.get_HasEvent()[index] = this.TaskContainsMethod(((Behavior.EventTypes)index).ToString(), behaviorSource.get_RootTask());
            }
        }
コード例 #19
0
ファイル: NodeDesigner.cs プロジェクト: mengtest/StateTree
        public void LoadNode(Task task, BehaviorSource behaviorSource, Vector2 offset, ref int id)
        {
            mTask                       = task;
            mTask.Owner                 = (behaviorSource.Owner as Behavior);
            mTask.ID                    = id++;
            mTask.NodeData              = new NodeData();
            mTask.NodeData.Offset       = offset;
            mTask.NodeData.NodeDesigner = this;
            LoadTaskIcon();
            Init();
            mTask.FriendlyName = taskName;
            RequiredComponentAttribute[] array;
            if (mTask.Owner != null && (array = (mTask.GetType().GetCustomAttributes(typeof(RequiredComponentAttribute), true) as RequiredComponentAttribute[])).Length > 0)
            {
                Type componentType = array[0].ComponentType;
                if (typeof(Component).IsAssignableFrom(componentType) && mTask.Owner.gameObject.GetComponent(componentType) == null)
                {
                    mTask.Owner.gameObject.AddComponent(componentType);
                }
            }
            List <Type>  baseClasses = FieldInspector.GetBaseClasses(mTask.GetType());
            BindingFlags bindingAttr = BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic;

            for (int i = baseClasses.Count - 1; i > -1; i--)
            {
                FieldInfo[] fields = baseClasses[i].GetFields(bindingAttr);
                for (int j = 0; j < fields.Length; j++)
                {
                    if (typeof(SharedVariable).IsAssignableFrom(fields[j].FieldType) && !fields[j].FieldType.IsAbstract)
                    {
                        SharedVariable sharedVariable = fields[j].GetValue(mTask) as SharedVariable;
                        if (sharedVariable == null)
                        {
                            sharedVariable = (Activator.CreateInstance(fields[j].FieldType) as SharedVariable);
                        }
                        if (TaskUtility.HasAttribute(fields[j], typeof(RequiredFieldAttribute)) || TaskUtility.HasAttribute(fields[j], typeof(SharedRequiredAttribute)))
                        {
                            sharedVariable.IsShared = true;
                        }
                        fields[j].SetValue(mTask, sharedVariable);
                    }
                }
            }
        }
コード例 #20
0
 // Token: 0x06000187 RID: 391 RVA: 0x0000D71C File Offset: 0x0000B91C
 public static bool DrawInspectorGUI(BehaviorSource behaviorSource, bool fromInspector, ref bool showVariables)
 {
     EditorGUI.BeginChangeCheck();
     GUILayout.BeginHorizontal(new GUILayoutOption[0]);
     EditorGUILayout.LabelField("Behavior Name", new GUILayoutOption[]
     {
         GUILayout.Width(120f)
     });
     behaviorSource.behaviorName = EditorGUILayout.TextField(behaviorSource.behaviorName, new GUILayoutOption[0]);
     if (fromInspector && GUILayout.Button("Open", new GUILayoutOption[0]))
     {
         BehaviorDesignerWindow.ShowWindow();
         BehaviorDesignerWindow.instance.LoadBehavior(behaviorSource, false, true);
     }
     GUILayout.EndHorizontal();
     EditorGUILayout.LabelField("Behavior Description", new GUILayoutOption[0]);
     behaviorSource.behaviorDescription = EditorGUILayout.TextArea(behaviorSource.behaviorDescription, new GUILayoutOption[]
     {
         GUILayout.Height(48f)
     });
     if (fromInspector)
     {
         string text = "BehaviorDesigner.VariablesFoldout." + behaviorSource.GetHashCode();
         if (showVariables = EditorGUILayout.Foldout(EditorPrefs.GetBool(text, true), "Variables"))
         {
             EditorGUI.indentLevel++;
             List <SharedVariable> allVariables = behaviorSource.GetAllVariables();
             if (allVariables != null && VariableInspector.DrawAllVariables(false, behaviorSource, ref allVariables, false, ref ExternalBehaviorInspector.variablePosition, ref ExternalBehaviorInspector.selectedVariableIndex, ref ExternalBehaviorInspector.selectedVariableName, ref ExternalBehaviorInspector.selectedVariableTypeIndex, true, false))
             {
                 if (BehaviorDesignerPreferences.GetBool(BDPreferences.BinarySerialization))
                 {
                     BinarySerialization.Save(behaviorSource);
                 }
                 else
                 {
                     JSONSerialization.Save(behaviorSource);
                 }
             }
             EditorGUI.indentLevel--;
         }
         EditorPrefs.SetBool(text, showVariables);
     }
     return(EditorGUI.EndChangeCheck());
 }
コード例 #21
0
        public static List <ErrorDetails> CheckForErrors(BehaviorSource behaviorSource)
        {
            if (behaviorSource == null || behaviorSource.EntryTask == null)
            {
                return(null);
            }
            List <ErrorDetails> result = null;

            ErrorCheck.CheckTaskForErrors(behaviorSource.EntryTask, ref result);
            if (behaviorSource.RootTask == null)
            {
                ErrorCheck.AddError(ref result, ErrorDetails.ErrorType.MissingChildren, behaviorSource.EntryTask, null);
            }
            if (behaviorSource.RootTask != null)
            {
                ErrorCheck.CheckTaskForErrors(behaviorSource.RootTask, ref result);
            }
            return(result);
        }
コード例 #22
0
 // Token: 0x0600025B RID: 603 RVA: 0x00016568 File Offset: 0x00014768
 private static void CheckSharedVariables(BehaviorSource behaviorSource, Task task)
 {
     if (task == null)
     {
         return;
     }
     TaskCopier.CheckSharedVariableFields(behaviorSource, task, task);
     if (task is ParentTask)
     {
         ParentTask parentTask = task as ParentTask;
         if (parentTask.Children != null)
         {
             for (int i = 0; i < parentTask.Children.Count; i++)
             {
                 TaskCopier.CheckSharedVariables(behaviorSource, parentTask.Children[i]);
             }
         }
     }
 }
コード例 #23
0
        private static void ShowPropertyMappingMenu(BehaviorSource behaviorSource, SharedVariable sharedVariable)
        {
            VariableInspector.mPropertyMappingVariable       = sharedVariable;
            VariableInspector.mPropertyMappingBehaviorSource = behaviorSource;
            VariableInspector.mPropertyMappingMenu           = new GenericMenu();
            List <string>     list  = new List <string>();
            List <GameObject> list2 = new List <GameObject>();

            list.Add("None");
            list2.Add(null);
            int num = 0;

            if (behaviorSource.Owner.GetObject() is Behavior)
            {
                GameObject gameObject = (behaviorSource.Owner.GetObject() as Behavior).gameObject;
                int        num2;
                if ((num2 = VariableInspector.AddPropertyName(sharedVariable, gameObject, ref list, ref list2, true)) != -1)
                {
                    num = num2;
                }
                GameObject[] array = UnityEngine.Object.FindObjectsOfType <GameObject>();
                for (int i = 0; i < array.Length; i++)
                {
                    if (!array[i].Equals(gameObject) && (num2 = VariableInspector.AddPropertyName(sharedVariable, array[i], ref list, ref list2, false)) != -1)
                    {
                        num = num2;
                    }
                }
            }
            for (int j = 0; j < list.Count; j++)
            {
                string[] array2 = list[j].Split(new char[]
                {
                    '.'
                });
                if (list2[j] != null)
                {
                    array2[array2.Length - 1] = VariableInspector.GetFullPath(list2[j].transform) + "/" + array2[array2.Length - 1];
                }
                VariableInspector.mPropertyMappingMenu.AddItem(new GUIContent(array2[array2.Length - 1]), j == num, new GenericMenu.MenuFunction2(VariableInspector.PropertySelected), new VariableInspector.SelectedPropertyMapping(list[j], list2[j]));
            }
            VariableInspector.mPropertyMappingMenu.ShowAsContext();
        }
コード例 #24
0
ファイル: Demo.cs プロジェクト: seenen/BehaviorTree_Seenen
    void StartInnal()
    {
        BehaviorTree[] bts = yuren.GetComponents<BehaviorTree>();

        for (int i = 0; i < bts.Length; ++i)
        {
            if (bts[i].BehaviorName == "MonsterNormal")
                btBirth = bts[i];
        }

        Task EntryTask = null;
        Task rootTask = null;
        List<Task> detachedTasks = null;

        BehaviorSource bsSource = btBirth.GetBehaviorSource();

        bsSource.Load(out EntryTask, out rootTask, out detachedTasks);

        for (int i = 0; i < 4; ++i)
        {
            GameObject obj = (GameObject)GameObject.Instantiate(mMonsterList.GetMonsterByIndex(i));
            obj.AddComponent<NavMeshAgent>();

            BehaviorTree behaviorTree = obj.AddComponent<BehaviorTree>();

            BehaviorSource bs = new BehaviorSource();
            bs.behaviorName             = i.ToString();
            bs.behaviorDescription      = bsSource.behaviorDescription;
            bs.Owner                    = behaviorTree;
            bs.TaskData                 = bsSource.TaskData;

            bs.CheckForSerialization(true);

            behaviorTree.SetBehaviorSource(bs);


            MonsterMono mm  = obj.AddComponent<MonsterMono>();
            mm.mPathList    = mWayPoints;
            mm.Begin();
        }


    }
コード例 #25
0
        private static Task FindReferencedTask(BehaviorSource behaviorSource, Task referencedTask)
        {
            int  iD = referencedTask.ID;
            Task result;

            if (behaviorSource.RootTask != null && (result = TaskReferences.FindReferencedTask(behaviorSource.RootTask, iD)) != null)
            {
                return(result);
            }
            if (behaviorSource.DetachedTasks != null)
            {
                for (int i = 0; i < behaviorSource.DetachedTasks.Count; i++)
                {
                    if ((result = TaskReferences.FindReferencedTask(behaviorSource.DetachedTasks[i], iD)) != null)
                    {
                        return(result);
                    }
                }
            }
            return(null);
        }
コード例 #26
0
    private static void ExportTree(BehaviorSource behaviorSource)
    {
        string folder = Path.GetDirectoryName(m_outputFolderPath);

        if (!Directory.Exists(folder))
        {
            Directory.CreateDirectory(folder);
        }


        string treeName = behaviorSource.behaviorName;
        string treePath = m_outputFolderPath + treeName + ".lua";

        Debug.Log("export ai tree file: " + treePath);

        StreamWriter treeFile = new StreamWriter(treePath);

        ExportToLua.ExportBehavior(treeName, treeFile, behaviorSource);
        treeFile.Close();


        StreamWriter recordAllAiFile = new StreamWriter(m_outputFolderPath + "All_BT.lua");
        string       btNumber;

        recordAllAiFile.Write("all_bt_name = {\n");
        DirectoryInfo theFolder = new DirectoryInfo(m_outputFolderPath);

        FileInfo[] filesInfo = theFolder.GetFiles();
        foreach (FileInfo fInfo in filesInfo)
        {
            if (fInfo.Name.StartsWith("BT") && !fInfo.Name.EndsWith(".meta"))
            {
                btNumber = fInfo.Name.Substring(0, fInfo.Name.Length - 4); //去掉.lua 后缀
                recordAllAiFile.Write(string.Format("\"{0}\",\n", btNumber));
            }
        }
        recordAllAiFile.Write("}\n");
        recordAllAiFile.Close();
    }
コード例 #27
0
 // Token: 0x0600025C RID: 604 RVA: 0x000165D0 File Offset: 0x000147D0
 private static void CheckSharedVariableFields(BehaviorSource behaviorSource, Task task, object obj)
 {
     if (obj == null)
     {
         return;
     }
     FieldInfo[] allFields = TaskUtility.GetAllFields(obj.GetType());
     for (int i = 0; i < allFields.Length; i++)
     {
         if (typeof(SharedVariable).IsAssignableFrom(allFields[i].FieldType))
         {
             SharedVariable sharedVariable = allFields[i].GetValue(obj) as SharedVariable;
             if (sharedVariable.IsShared && !string.IsNullOrEmpty(sharedVariable.Name) && behaviorSource.GetVariable(sharedVariable.Name) == null)
             {
                 behaviorSource.SetVariable(sharedVariable.Name, sharedVariable);
             }
             TaskCopier.CheckSharedVariableFields(behaviorSource, task, sharedVariable);
         }
         else if (allFields[i].FieldType.IsClass && !allFields[i].FieldType.Equals(typeof(Type)) && !typeof(Delegate).IsAssignableFrom(allFields[i].FieldType))
         {
             TaskCopier.CheckSharedVariableFields(behaviorSource, task, allFields[i].GetValue(obj));
         }
     }
 }
コード例 #28
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]]);
                }
            }
        }
    }
コード例 #29
0
 public static void Load(BehaviorSource behaviorSource)
 {
     Load(behaviorSource.TaskData, behaviorSource);
 }
コード例 #30
0
    private static void LoadTask(TaskSerializationData taskSerializationData, FieldSerializationData fieldSerializationData, ref List <Task> taskList, ref BehaviorSource behaviorSource)
    {
        int  count = taskList.Count;
        Type type  = TaskUtility.GetTypeWithinAssembly(taskSerializationData.types[count]);

        if (type == null)
        {
            bool flag = false;
            for (int i = 0; i < taskSerializationData.parentIndex.Count; i++)
            {
                if (count == taskSerializationData.parentIndex[i])
                {
                    flag = true;
                    break;
                }
            }
            if (flag)
            {
                type = typeof(UnknownParentTask);
            }
            else
            {
                type = typeof(UnknownTask);
            }
        }
        Task task = TaskUtility.CreateInstance(type) as Task;

        task.Owner = (behaviorSource.Owner.GetObject() as Behavior);
        taskList.Add(task);
        int num = taskSerializationData.startIndex[count];
        int num2;

        if (count + 1 < taskSerializationData.startIndex.Count)
        {
            num2 = taskSerializationData.startIndex[count + 1];
        }
        else
        {
            num2 = fieldSerializationData.startIndex.Count;
        }
        Dictionary <string, int> dictionary = ObjectPool.Get <Dictionary <string, int> >();

        dictionary.Clear();
        for (int j = num; j < num2; j++)
        {
            dictionary.Add(fieldSerializationData.typeName[j], fieldSerializationData.startIndex[j]);
        }
        task.ID           = (int)LoadField(fieldSerializationData, dictionary, typeof(int), "ID", null, null, null);
        task.FriendlyName = (string)LoadField(fieldSerializationData, dictionary, typeof(string), "FriendlyName", null, null, null);
        task.IsInstant    = (bool)LoadField(fieldSerializationData, dictionary, typeof(bool), "IsInstant", null, null, null);
        LoadNodeData(fieldSerializationData, dictionary, taskList[count]);
        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);
            }
        }
        LoadFields(fieldSerializationData, dictionary, taskList[count], string.Empty, behaviorSource);
        ObjectPool.Return(dictionary);
    }
コード例 #31
0
 public bool DrawVariables(BehaviorSource behaviorSource, bool enabled)
 {
     return(VariableInspector.DrawVariables(behaviorSource, enabled, behaviorSource, ref this.mVariableName, ref this.mFocusNameField, ref this.mVariableTypeIndex, ref this.mScrollPosition, ref this.mVariablePosition, ref this.mVariableStartPosition, ref this.mSelectedVariableIndex, ref this.mSelectedVariableName, ref this.mSelectedVariableTypeIndex));
 }