示例#1
0
        private void CalculateNodeCommentRect(Rect nodeRect)
        {
            bool flag = false;

            if (mTask.NodeData.WatchedFields != null && this.mTask.NodeData.WatchedFields.Count > 0)
            {
                string text  = string.Empty;
                string text2 = string.Empty;
                for (int i = 0; i < this.mTask.NodeData.WatchedFields.Count; i++)
                {
                    FieldInfo fieldInfo = this.mTask.NodeData.WatchedFields[i];
                    text  = text + BehaviorDesignerUtility.SplitCamelCase(fieldInfo.Name) + ": \n";
                    text2 = text2 + ((fieldInfo.GetValue(this.mTask) == null) ? "null" : fieldInfo.GetValue(this.mTask).ToString()) + "\n";
                }
                float num;
                float num2;
                BehaviorDesignerUtility.TaskCommentGUIStyle.CalcMinMaxWidth(new GUIContent(text), out num, out num2);
                float num3;
                BehaviorDesignerUtility.TaskCommentGUIStyle.CalcMinMaxWidth(new GUIContent(text2), out num, out num3);
                float num4 = num2;
                float num5 = num3;
                float num6 = Mathf.Min(220f, num2 + num3 + 20f);
                if (num6 == 220f)
                {
                    num4 = num2 / (num2 + num3) * 220f;
                    num5 = num3 / (num2 + num3) * 220f;
                }
                this.watchedFieldRect       = new Rect(nodeRect.xMax + 4f, nodeRect.y, num6 + 8f, nodeRect.height);
                this.watchedFieldNamesRect  = new Rect(nodeRect.xMax + 6f, nodeRect.y + 4f, num4, nodeRect.height - 8f);
                this.watchedFieldValuesRect = new Rect(nodeRect.xMax + 6f + num4, nodeRect.y + 4f, num5, nodeRect.height - 8f);
                flag = true;
            }
            if (!this.mTask.NodeData.Comment.Equals(string.Empty))
            {
                if (this.isParent)
                {
                    float num7;
                    float num8;
                    BehaviorDesignerUtility.TaskCommentGUIStyle.CalcMinMaxWidth(new GUIContent(this.mTask.NodeData.Comment), out num7, out num8);
                    float num9 = Mathf.Min(220f, num8 + 20f);
                    if (flag)
                    {
                        this.commentRect      = new Rect(nodeRect.xMin - 12f - num9, nodeRect.y, num9 + 8f, nodeRect.height);
                        this.commentLabelRect = new Rect(nodeRect.xMin - 6f - num9, nodeRect.y + 4f, num9, nodeRect.height - 8f);
                    }
                    else
                    {
                        this.commentRect      = new Rect(nodeRect.xMax + 4f, nodeRect.y, num9 + 8f, nodeRect.height);
                        this.commentLabelRect = new Rect(nodeRect.xMax + 6f, nodeRect.y + 4f, num9, nodeRect.height - 8f);
                    }
                }
                else
                {
                    float num10 = Mathf.Min(100f, BehaviorDesignerUtility.TaskCommentGUIStyle.CalcHeight(new GUIContent(this.mTask.NodeData.Comment), nodeRect.width - 4f));
                    this.commentRect      = new Rect(nodeRect.x, nodeRect.yMax + 4f, nodeRect.width, num10 + 4f);
                    this.commentLabelRect = new Rect(nodeRect.x, nodeRect.yMax + 4f, nodeRect.width - 4f, num10);
                }
            }
        }
示例#2
0
        public void OnGUI()
        {
            this.mScrollPosition = EditorGUILayout.BeginScrollView(this.mScrollPosition, new GUILayoutOption[0]);
            if (this.mErrorDetails != null && this.mErrorDetails.Count > 0)
            {
                for (int i = 0; i < this.mErrorDetails.Count; i++)
                {
                    ErrorDetails errorDetails = this.mErrorDetails[i];
                    if (errorDetails != null && !(errorDetails.NodeDesigner == null) && errorDetails.NodeDesigner.Task != null)
                    {
                        string text = string.Empty;
                        switch (errorDetails.Type)
                        {
                        case BehaviorDesigner.Editor.ErrorDetails.ErrorType.RequiredField:
                            text = string.Format("The task {0} ({1}, index {2}) requires a value for the field {3}.", new object[]
                            {
                                errorDetails.TaskFriendlyName,
                                errorDetails.TaskType,
                                errorDetails.NodeDesigner.Task.ID,
                                BehaviorDesignerUtility.SplitCamelCase(errorDetails.FieldName)
                            });
                            break;

                        case BehaviorDesigner.Editor.ErrorDetails.ErrorType.SharedVariable:
                            text = string.Format("The task {0} ({1}, index {2}) has a Shared Variable field ({3}) that is marked as shared but is not referencing a Shared Variable.", new object[]
                            {
                                errorDetails.TaskFriendlyName,
                                errorDetails.TaskType,
                                errorDetails.NodeDesigner.Task.ID,
                                BehaviorDesignerUtility.SplitCamelCase(errorDetails.FieldName)
                            });
                            break;

                        case BehaviorDesigner.Editor.ErrorDetails.ErrorType.MissingChildren:
                            text = string.Format("The {0} task ({1}, index {2}) is a parent task which does not have any children", errorDetails.TaskFriendlyName, errorDetails.TaskType, errorDetails.NodeDesigner.Task.ID);
                            break;

                        case BehaviorDesigner.Editor.ErrorDetails.ErrorType.UnknownTask:
                            text = string.Format("The task at index {0} is unknown. Has a task been renamed or deleted?", errorDetails.NodeDesigner.Task.ID);
                            break;
                        }
                        EditorGUILayout.LabelField(text, (i % 2 != 0) ? BehaviorDesignerUtility.ErrorListDarkBackground : BehaviorDesignerUtility.ErrorListLightBackground, new GUILayoutOption[]
                        {
                            GUILayout.Height(30f),
                            GUILayout.Width((float)(Screen.width - 7))
                        });
                    }
                }
            }
            else if (!BehaviorDesignerPreferences.GetBool(BDPreferences.ErrorChecking))
            {
                EditorGUILayout.LabelField("Enable realtime error checking from the preferences to view the errors.", BehaviorDesignerUtility.ErrorListLightBackground, new GUILayoutOption[0]);
            }
            else
            {
                EditorGUILayout.LabelField("The behavior tree has no errors.", BehaviorDesignerUtility.ErrorListLightBackground, new GUILayoutOption[0]);
            }
            EditorGUILayout.EndScrollView();
        }
示例#3
0
 private void Init()
 {
     taskName = BehaviorDesignerUtility.SplitCamelCase(mTask.GetType().Name.ToString());
     isParent = mTask.GetType().IsSubclassOf(typeof(ParentTask));
     if (isParent)
     {
         outgoingNodeConnections = new List <NodeConnection>();
     }
     mRectIsDirty         = (mCacheIsDirty = true);
     mIncomingRectIsDirty = true;
     mOutgoingRectIsDirty = true;
 }
示例#4
0
        public void DrawTaskList(BehaviorDesignerWindow window, bool enabled)
        {
            GUILayout.BeginHorizontal(new GUILayoutOption[0]);
            GUI.SetNextControlName("Search");
            string value = GUILayout.TextField(this.mSearchString, GUI.skin.FindStyle("ToolbarSeachTextField"), new GUILayoutOption[0]);

            if (this.mFocusSearch)
            {
                GUI.FocusControl("Search");
                this.mFocusSearch = false;
            }
            if (!this.mSearchString.Equals(value))
            {
                this.mSearchString = value;
                this.Search(BehaviorDesignerUtility.SplitCamelCase(this.mSearchString).ToLower().Replace(" ", string.Empty), this.mCategoryList);
            }
            if (GUILayout.Button(string.Empty, (!this.mSearchString.Equals(string.Empty)) ? GUI.skin.FindStyle("ToolbarSeachCancelButton") : GUI.skin.FindStyle("ToolbarSeachCancelButtonEmpty"), new GUILayoutOption[0]))
            {
                this.mSearchString = string.Empty;
                this.Search(string.Empty, this.mCategoryList);
                GUI.FocusControl(null);
            }
            GUILayout.EndHorizontal();
            BehaviorDesignerUtility.DrawContentSeperator(2);
            GUILayout.Space(4f);
            this.mScrollPosition = GUILayout.BeginScrollView(this.mScrollPosition, new GUILayoutOption[0]);
            GUI.enabled          = (enabled);
            if (this.mCategoryList.Count > 1)
            {
                this.DrawCategory(window, this.mCategoryList[1]);
            }
            if (this.mCategoryList.Count > 3)
            {
                this.DrawCategory(window, this.mCategoryList[3]);
            }
            if (this.mCategoryList.Count > 0)
            {
                this.DrawCategory(window, this.mCategoryList[0]);
            }
            if (this.mCategoryList.Count > 2)
            {
                this.DrawCategory(window, this.mCategoryList[2]);
            }
            GUI.enabled = (true);
            GUILayout.EndScrollView();
        }
        public static object DrawFields(Task task, object obj, GUIContent guiContent)
        {
            if (obj == null)
            {
                return(null);
            }
            List <Type>  baseClasses = FieldInspector.GetBaseClasses(obj.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 (!BehaviorDesignerUtility.HasAttribute(fields[j], typeof(NonSerializedAttribute)) && !BehaviorDesignerUtility.HasAttribute(fields[j], typeof(HideInInspector)) && ((!fields[j].IsPrivate && !fields[j].IsFamily) || BehaviorDesignerUtility.HasAttribute(fields[j], typeof(SerializeField))) && (!(obj is ParentTask) || !fields[j].Name.Equals("children")))
                    {
                        if (guiContent == null)
                        {
                            string name = fields[j].Name;
                            BehaviorDesigner.Runtime.Tasks.TooltipAttribute[] array;
                            if ((array = (fields[j].GetCustomAttributes(typeof(BehaviorDesigner.Runtime.Tasks.TooltipAttribute), false) as BehaviorDesigner.Runtime.Tasks.TooltipAttribute[])).Length > 0)
                            {
                                guiContent = new GUIContent(BehaviorDesignerUtility.SplitCamelCase(name), array[0].Tooltip);
                            }
                            else
                            {
                                guiContent = new GUIContent(BehaviorDesignerUtility.SplitCamelCase(name));
                            }
                        }
                        EditorGUI.BeginChangeCheck();
                        object value = FieldInspector.DrawField(task, guiContent, fields[j], fields[j].GetValue(obj));
                        if (EditorGUI.EndChangeCheck())
                        {
                            fields[j].SetValue(obj, value);
                            GUI.changed = true;
                        }
                        guiContent = null;
                    }
                }
            }
            return(obj);
        }
示例#6
0
        private bool Search(string searchString, List <TaskList.CategoryList> categoryList)
        {
            bool result = searchString.Equals(string.Empty);

            for (int i = 0; i < categoryList.Count; i++)
            {
                bool flag = false;
                categoryList[i].Visible = false;
                if (categoryList[i].Subcategories != null && this.Search(searchString, categoryList[i].Subcategories))
                {
                    categoryList[i].Visible = true;
                    result = true;
                }
                if (BehaviorDesignerUtility.SplitCamelCase(categoryList[i].Name).ToLower().Replace(" ", string.Empty).Contains(searchString))
                {
                    result = true;
                    flag   = true;
                    categoryList[i].Visible = true;
                    if (categoryList[i].Subcategories != null)
                    {
                        this.MarkVisible(categoryList[i].Subcategories);
                    }
                }
                if (categoryList[i].Tasks != null)
                {
                    for (int j = 0; j < categoryList[i].Tasks.Count; j++)
                    {
                        categoryList[i].Tasks[j].Visible = searchString.Equals(string.Empty);
                        if (flag || categoryList[i].Tasks[j].Name.ToLower().Replace(" ", string.Empty).Contains(searchString))
                        {
                            categoryList[i].Tasks[j].Visible = true;
                            result = true;
                            categoryList[i].Visible = true;
                        }
                    }
                }
            }
            return(result);
        }
示例#7
0
 public void DrawNodeComment(Vector2 offset)
 {
     if (this.mTask.NodeData.Comment.Length != this.prevCommentLength)
     {
         this.prevCommentLength = this.mTask.NodeData.Comment.Length;
         this.mRectIsDirty      = true;
     }
     if (this.mTask.NodeData.WatchedFields != null && this.mTask.NodeData.WatchedFields.Count != this.prevWatchedFieldsLength)
     {
         this.prevWatchedFieldsLength = this.mTask.NodeData.WatchedFields.Count;
         this.mRectIsDirty            = true;
     }
     if (this.mTask.NodeData.Comment.Equals(string.Empty) && (this.mTask.NodeData.WatchedFields == null || this.mTask.NodeData.WatchedFields.Count == 0))
     {
         return;
     }
     if (this.mTask.NodeData.WatchedFields != null && this.mTask.NodeData.WatchedFields.Count > 0)
     {
         string text  = string.Empty;
         string text2 = string.Empty;
         for (int i = 0; i < this.mTask.NodeData.WatchedFields.Count; i++)
         {
             FieldInfo fieldInfo = this.mTask.NodeData.WatchedFields[i];
             text  = text + BehaviorDesignerUtility.SplitCamelCase(fieldInfo.Name) + ": \n";
             text2 = text2 + ((fieldInfo.GetValue(this.mTask) == null) ? "null" : fieldInfo.GetValue(this.mTask).ToString()) + "\n";
         }
         GUI.Box(this.watchedFieldRect, string.Empty, BehaviorDesignerUtility.TaskDescriptionGUIStyle);
         GUI.Label(this.watchedFieldNamesRect, text, BehaviorDesignerUtility.TaskCommentRightAlignGUIStyle);
         GUI.Label(this.watchedFieldValuesRect, text2, BehaviorDesignerUtility.TaskCommentLeftAlignGUIStyle);
     }
     if (!this.mTask.NodeData.Comment.Equals(string.Empty))
     {
         GUI.Box(this.commentRect, string.Empty, BehaviorDesignerUtility.TaskDescriptionGUIStyle);
         GUI.Label(this.commentLabelRect, this.mTask.NodeData.Comment, BehaviorDesignerUtility.TaskCommentGUIStyle);
     }
 }
示例#8
0
 public SearchableType(Type type)
 {
     this.mType = type;
     this.mName = BehaviorDesignerUtility.SplitCamelCase(this.mType.Name);
 }
示例#9
0
        public void Init()
        {
            this.mCategoryList = new List <TaskList.CategoryList>();
            List <Type> list = new List <Type>();

            Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
            for (int i = 0; i < assemblies.Length; i++)
            {
                Type[] types = assemblies[i].GetTypes();
                for (int j = 0; j < types.Length; j++)
                {
                    if (!types[j].Equals(typeof(BehaviorReference)) && !types[j].IsAbstract)
                    {
                        if (types[j].IsSubclassOf(typeof(BehaviorDesigner.Runtime.Tasks.Action)) || types[j].IsSubclassOf(typeof(Composite)) || types[j].IsSubclassOf(typeof(Conditional)) || types[j].IsSubclassOf(typeof(Decorator)))
                        {
                            list.Add(types[j]);
                        }
                    }
                }
            }
            list.Sort(new AlphanumComparator <Type>());
            Dictionary <string, TaskList.CategoryList> dictionary = new Dictionary <string, TaskList.CategoryList>();
            string text = string.Empty;
            int    id   = 0;

            for (int k = 0; k < list.Count; k++)
            {
                if (list[k].IsSubclassOf(typeof(BehaviorDesigner.Runtime.Tasks.Action)))
                {
                    text = "Actions";
                }
                else if (list[k].IsSubclassOf(typeof(Composite)))
                {
                    text = "Composites";
                }
                else if (list[k].IsSubclassOf(typeof(Conditional)))
                {
                    text = "Conditionals";
                }
                else
                {
                    text = "Decorators";
                }
                TaskCategoryAttribute[] array;
                if ((array = (list[k].GetCustomAttributes(typeof(TaskCategoryAttribute), false) as TaskCategoryAttribute[])).Length > 0)
                {
                    text = text + "/" + array[0].Category;
                }
                string   text2  = string.Empty;
                string[] array2 = text.Split(new char[]
                {
                    '/'
                });
                TaskList.CategoryList categoryList = null;
                TaskList.CategoryList categoryList2;
                for (int l = 0; l < array2.Length; l++)
                {
                    if (l > 0)
                    {
                        text2 += "/";
                    }
                    text2 += array2[l];
                    if (!dictionary.ContainsKey(text2))
                    {
                        categoryList2 = new TaskList.CategoryList(array2[l], text2, this.PreviouslyExpanded(id), id++);
                        if (categoryList == null)
                        {
                            this.mCategoryList.Add(categoryList2);
                        }
                        else
                        {
                            categoryList.addSubcategory(categoryList2);
                        }
                        dictionary.Add(text2, categoryList2);
                    }
                    else
                    {
                        categoryList2 = dictionary[text2];
                    }
                    categoryList = categoryList2;
                }
                categoryList2 = dictionary[text2];
                categoryList2.addTask(list[k]);
            }
            this.Search(BehaviorDesignerUtility.SplitCamelCase(this.mSearchString).ToLower().Replace(" ", string.Empty), this.mCategoryList);
        }
        public static void DrawComponentSelector(VariableSynchronizerInspector.Synchronizer synchronizer, Type componentType, VariableSynchronizerInspector.ComponentListType listType)
        {
            bool flag = false;

            EditorGUI.BeginChangeCheck();
            synchronizer.gameObject = (EditorGUILayout.ObjectField("GameObject", synchronizer.gameObject, typeof(GameObject), true, new GUILayoutOption[0]) as GameObject);
            if (EditorGUI.EndChangeCheck())
            {
                flag = true;
            }
            if (synchronizer.gameObject == null)
            {
                GUI.enabled = (false);
            }
            switch (listType)
            {
            case VariableSynchronizerInspector.ComponentListType.Instant:
                if (flag)
                {
                    if (synchronizer.gameObject != null)
                    {
                        synchronizer.component = synchronizer.gameObject.GetComponent(componentType);
                    }
                    else
                    {
                        synchronizer.component = null;
                    }
                }
                break;

            case VariableSynchronizerInspector.ComponentListType.Popup:
            {
                int           num   = 0;
                List <string> list  = new List <string>();
                Component[]   array = null;
                list.Add("None");
                if (synchronizer.gameObject != null)
                {
                    array = synchronizer.gameObject.GetComponents(componentType);
                    for (int i = 0; i < array.Length; i++)
                    {
                        if (array[i].Equals(synchronizer.component))
                        {
                            num = list.Count;
                        }
                        string text = BehaviorDesignerUtility.SplitCamelCase(array[i].GetType().Name);
                        int    num2 = 0;
                        for (int j = 0; j < list.Count; j++)
                        {
                            if (list[i].Equals(text))
                            {
                                num2++;
                            }
                        }
                        if (num2 > 0)
                        {
                            text = text + " " + num2;
                        }
                        list.Add(text);
                    }
                }
                EditorGUI.BeginChangeCheck();
                num = EditorGUILayout.Popup("Component", num, list.ToArray(), new GUILayoutOption[0]);
                if (EditorGUI.EndChangeCheck())
                {
                    if (num != 0)
                    {
                        synchronizer.component = array[num - 1];
                    }
                    else
                    {
                        synchronizer.component = null;
                    }
                }
                break;
            }

            case VariableSynchronizerInspector.ComponentListType.BehaviorDesignerGroup:
                if (synchronizer.gameObject != null)
                {
                    Behavior[] components = synchronizer.gameObject.GetComponents <Behavior>();
                    if (components != null && components.Length > 1)
                    {
                        synchronizer.componentGroup = EditorGUILayout.IntField("Behavior Tree Group", synchronizer.componentGroup, new GUILayoutOption[0]);
                    }
                    synchronizer.component = VariableSynchronizerInspector.GetBehaviorWithGroup(components, synchronizer.componentGroup);
                }
                break;
            }
        }
示例#11
0
        public int Compare(T x, T y)
        {
            string text = string.Empty;

            if (x.GetType().IsSubclassOf(typeof(Type)))
            {
                Type type = x as Type;
                text = this.TypePrefix(type) + "/";
                TaskCategoryAttribute[] array;
                if ((array = (type.GetCustomAttributes(typeof(TaskCategoryAttribute), false) as TaskCategoryAttribute[])).Length > 0)
                {
                    text = text + array[0].Category + "/";
                }
                TaskNameAttribute[] array2;
                if ((array2 = (type.GetCustomAttributes(typeof(TaskNameAttribute), false) as TaskNameAttribute[])).Length > 0)
                {
                    text += array2[0].Name;
                }
                else
                {
                    text += BehaviorDesignerUtility.SplitCamelCase(type.Name.ToString());
                }
            }
            else if (x.GetType().IsSubclassOf(typeof(SharedVariable)))
            {
                string text2 = x.GetType().Name;
                if (text2.Length > 6 && text2.Substring(0, 6).Equals("Shared"))
                {
                    text2 = text2.Substring(6, text2.Length - 6);
                }
                text = BehaviorDesignerUtility.SplitCamelCase(text2);
            }
            else
            {
                text = BehaviorDesignerUtility.SplitCamelCase(x.ToString());
            }
            if (text == null)
            {
                return(0);
            }
            string text3 = string.Empty;

            if (y.GetType().IsSubclassOf(typeof(Type)))
            {
                Type type2 = y as Type;
                text3 = this.TypePrefix(type2) + "/";
                TaskCategoryAttribute[] array3;
                if ((array3 = (type2.GetCustomAttributes(typeof(TaskCategoryAttribute), false) as TaskCategoryAttribute[])).Length > 0)
                {
                    text3 = text3 + array3[0].Category + "/";
                }
                TaskNameAttribute[] array4;
                if ((array4 = (type2.GetCustomAttributes(typeof(TaskNameAttribute), false) as TaskNameAttribute[])).Length > 0)
                {
                    text3 += array4[0].Name;
                }
                else
                {
                    text3 += BehaviorDesignerUtility.SplitCamelCase(type2.Name.ToString());
                }
            }
            else if (y.GetType().IsSubclassOf(typeof(SharedVariable)))
            {
                string text4 = y.GetType().Name;
                if (text4.Length > 6 && text4.Substring(0, 6).Equals("Shared"))
                {
                    text4 = text4.Substring(6, text4.Length - 6);
                }
                text3 = BehaviorDesignerUtility.SplitCamelCase(text4);
            }
            else
            {
                text3 = BehaviorDesignerUtility.SplitCamelCase(y.ToString());
            }
            if (text3 == null)
            {
                return(0);
            }
            int length  = text.Length;
            int length2 = text3.Length;
            int num     = 0;
            int num2    = 0;

            while (num < length && num2 < length2)
            {
                int num4;
                if (char.IsDigit(text[num]) && char.IsDigit(text[num2]))
                {
                    string text5 = string.Empty;
                    while (num < length && char.IsDigit(text[num]))
                    {
                        text5 += text[num];
                        num++;
                    }
                    string text6 = string.Empty;
                    while (num2 < length2 && char.IsDigit(text3[num2]))
                    {
                        text6 += text3[num2];
                        num2++;
                    }
                    int num3 = 0;
                    int.TryParse(text5, out num3);
                    int value = 0;
                    int.TryParse(text6, out value);
                    num4 = num3.CompareTo(value);
                }
                else
                {
                    num4 = text[num].CompareTo(text3[num2]);
                }
                if (num4 != 0)
                {
                    return(num4);
                }
                num++;
                num2++;
            }
            return(length - length2);
        }