private void DrawServices()
        {
            EditorGUILayout.Space();
            DrawSeparator();

            for (int i = 0; i < m_target.Services.Count; i++)
            {
                Service service          = m_target.Services[i];
                Rect    headerPos        = GUILayoutUtility.GetRect(0, 18.0f, GUILayout.ExpandWidth(true));
                Rect    foldoutPos       = new Rect(headerPos.x, headerPos.y, 20.0f, headerPos.height);
                Rect    labelPos         = new Rect(foldoutPos.xMax, headerPos.y, headerPos.width - 38.0f, headerPos.height);
                Rect    optionsButtonPos = new Rect(labelPos.xMax, headerPos.y, 18.0f, headerPos.height);

                service.IsExpanded = EditorGUI.Foldout(foldoutPos, service.IsExpanded, GUIContent.none);
                EditorGUI.LabelField(labelPos, service.Title, BTEditorStyle.BoldLabel);
                if (GUI.Button(optionsButtonPos, BTEditorStyle.OptionsIcon, EditorStyles.label))
                {
                    GenericMenu menu = BTContextMenuFactory.CreateServiceContextMenu(m_target, i);
                    menu.DropDown(new Rect(BTEditorCanvas.Current.Event.mousePosition, Vector2.zero));
                }

                if (service.IsExpanded)
                {
                    var serviceInspector = GetServiceInspector(service);
                    serviceInspector.OnInspectorGUI();
                }

                DrawSeparator();
            }
        }
 private void DrawOptions(Rect screenRect)
 {
     if (GUI.Button(screenRect, BTEditorStyle.OptionsIcon, EditorStyles.toolbarButton))
     {
         GenericMenu menu = BTContextMenuFactory.CreateBehaviourTreeEditorMenu(this);
         menu.DropDown(new Rect(Event.current.mousePosition, Vector2.zero));
     }
 }
        private void DrawHeader()
        {
            Rect titlePosition = GUILayoutUtility.GetRect(GUIContent.none, BTEditorStyle.RegionBackground, GUILayout.ExpandWidth(true), GUILayout.Height(15.0f));

            titlePosition.x     -= 19;
            titlePosition.y     -= 2;
            titlePosition.width += 28;

            Rect optionsButtonPosition = new Rect(titlePosition.xMax - 28.0f, titlePosition.y, 20.0f, 20.0f);

            DrawCategoryHeader(titlePosition, m_target.Title);
            if (GUI.Button(optionsButtonPosition, BTEditorStyle.OptionsIcon, EditorStyles.label))
            {
                GenericMenu menu = BTContextMenuFactory.CreateNodeInspectorContextMenu(m_target);
                menu.DropDown(new Rect(Event.current.mousePosition, Vector2.zero));
            }

            GUILayout.Space(2.5f);
            DrawSeparator();

            // show obsolete tip
            if (BTNodeObsoleteFactory.IsObsolete(m_target))
            {
                string tip = BTNodeObsoleteFactory.GetTipString(m_target);
                EditorGUILayout.HelpBox(tip, MessageType.Warning);
                GUILayout.Space(2.5f);
                DrawSeparator();
            }

            // show reference of class.
            string reference = BTNodeHelpBoxFactory.GetHelpString(m_target);

            if (!string.IsNullOrEmpty(reference))
            {
                EditorGUILayout.LabelField(reference, BTEditorStyle.HelpBox);
                GUILayout.Space(2.5f);
                DrawSeparator();
            }

            //m_target.Name = EditorGUILayout.TextField("Name", m_target.Name);
            EditorGUILayout.LabelField("Comment");
            m_target.Comment = EditorGUILayout.TextArea(m_target.Comment, BTEditorStyle.MultilineTextArea);

            if (m_graphNode.Parent != null && m_graphNode.Parent.Node is WeightedRandom)
            {
                EditorGUILayout.Space();
                m_target.Weight = EditorGUILayout.Slider("Weight", m_target.Weight, 0.0f, 1.0f);
            }

            GUILayout.Space(2.5f);
            DrawSeparator();
            EditorGUILayout.Space();
        }
Exemple #4
0
        private void HandleEvents(Rect screenRect)
        {
            if (BTEditorCanvas.Current.Event.type == EventType.MouseDown && BTEditorCanvas.Current.Event.button == SELECT_MOUSE_BUTTON)
            {
                if (screenRect.Contains(BTEditorCanvas.Current.Event.mousePosition))
                {
                    ClearSelection();

                    m_canBeginBoxSelection = true;
                    m_selectionBoxStartPos = BTEditorCanvas.Current.Event.mousePosition;
                    BTEditorCanvas.Current.Event.Use();
                }
            }
            else if (BTEditorCanvas.Current.Event.type == EventType.MouseDrag && BTEditorCanvas.Current.Event.button == SELECT_MOUSE_BUTTON)
            {
                if (screenRect.Contains(BTEditorCanvas.Current.Event.mousePosition))
                {
                    if (!m_drawSelectionBox && m_canBeginBoxSelection)
                    {
                        m_drawSelectionBox = true;
                    }

                    BTEditorCanvas.Current.Event.Use();
                }
            }
            else if (BTEditorCanvas.Current.Event.type == EventType.MouseUp)
            {
                if (screenRect.Contains(BTEditorCanvas.Current.Event.mousePosition))
                {
                    if (BTEditorCanvas.Current.Event.button == SELECT_MOUSE_BUTTON)
                    {
                        if (m_drawSelectionBox)
                        {
                            m_drawSelectionBox = false;
                        }

                        BTEditorCanvas.Current.Event.Use();
                    }
                    else if (BTEditorCanvas.Current.Event.button == CONTEXT_MOUSE_BUTTON)
                    {
                        GenericMenu menu = BTContextMenuFactory.CreateGraphContextMenu(this);
                        menu.DropDown(new Rect(BTEditorCanvas.Current.Event.mousePosition, Vector2.zero));

                        BTEditorCanvas.Current.Event.Use();
                    }
                }

                m_canBeginBoxSelection = false;
            }
        }
        private void DrawConstraints()
        {
            EditorGUILayout.Space();
            DrawSeparator();

            for (int i = 0; i < m_target.Constraints.Count; i++)
            {
                Constraint constraint       = m_target.Constraints[i];
                Rect       headerPos        = GUILayoutUtility.GetRect(0, 18.0f, GUILayout.ExpandWidth(true));
                Rect       foldoutPos       = new Rect(headerPos.x, headerPos.y, 20.0f, headerPos.height);
                Rect       labelPos         = new Rect(foldoutPos.xMax, headerPos.y, headerPos.width - 56.0f, headerPos.height);
                Rect       togglePos        = new Rect(labelPos.xMax - 40, headerPos.y, 18.0f, headerPos.height);
                Rect       toggleLabelPos   = new Rect(togglePos.xMax - 5, headerPos.y, 45.0f, headerPos.height);
                Rect       optionsButtonPos = new Rect(togglePos.xMax + 40, headerPos.y, 18.0f, headerPos.height);

                constraint.IsExpanded = EditorGUI.Foldout(foldoutPos, constraint.IsExpanded, GUIContent.none);
                EditorGUI.LabelField(labelPos, constraint.Title, BTEditorStyle.BoldLabel);
                constraint.InvertResult = EditorGUI.Toggle(togglePos, GUIContent.none, constraint.InvertResult);
                EditorGUI.LabelField(toggleLabelPos, "invert", BTEditorStyle.BoldLabel);
                if (GUI.Button(optionsButtonPos, BTEditorStyle.OptionsIcon, EditorStyles.label))
                {
                    GenericMenu menu = BTContextMenuFactory.CreateConstraintContextMenu(m_target, i);
                    menu.DropDown(new Rect(BTEditorCanvas.Current.Event.mousePosition, Vector2.zero));
                }

                if (constraint.IsExpanded)
                {
                    var constraintInspector = GetConstraintInspector(constraint);
                    constraintInspector.OnInspectorGUI();
                }

                // show obsolete tip
                if (BTNodeObsoleteFactory.IsObsolete(constraint))
                {
                    string tip = BTNodeObsoleteFactory.GetTipString(constraint);
                    EditorGUILayout.HelpBox(tip, MessageType.Warning);
                    GUILayout.Space(2.5f);
                    DrawSeparator();
                }

                DrawSeparator();
            }
        }
        private void ShowContextMenu()
        {
            GenericMenu menu = BTContextMenuFactory.CreateNodeContextMenu(this);

            menu.DropDown(new Rect(BTEditorCanvas.Current.Event.mousePosition, Vector2.zero));
        }