예제 #1
0
        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();
        }
예제 #2
0
        private void DrawSelf()
        {
            string           label     = m_node.Title;
            BTGraphNodeStyle nodeStyle = BTEditorStyle.GetNodeStyle(m_node);
            Vector2          nodeSize  = BTEditorStyle.GetNodeSize(m_node);
            Rect             position  = new Rect(NodePosition + BTEditorCanvas.Current.Position, nodeSize);
            RunningStatus    status    = BTEditorCanvas.Current.IsDebuging ? GetNodeStatus(m_node) : RunningStatus.None;

            GUI.Box(position, "", nodeStyle.GetStyle(status, m_isSelected));

            int  iconSize    = 32;
            int  iconOffsetY = 7;
            Rect iconPos     = new Rect(position.x + (nodeSize.x - iconSize) / 2, position.y + (nodeSize.y - iconSize) / 2 - iconOffsetY, iconSize, iconSize);

            GUI.DrawTexture(iconPos, BTEditorStyle.GetNodeIcon(m_node));

            Rect titlePos = new Rect(position);

            titlePos.y = titlePos.y - 5;
            EditorGUI.LabelField(titlePos, label, BTEditorStyle.NodeTitleLabel);

            // show index of composite's children.
            if (Parent != null && Parent.Node is Composite)
            {
                Composite compNode    = Parent.Node as Composite;
                int       index       = compNode.GetIndex(m_node);
                Rect      nodeLeftPos = new Rect(position.x + 2, position.center.y - 8, 20, 16);
                EditorGUI.LabelField(nodeLeftPos, index.ToString(), EditorStyles.label);
            }

            if (m_node.Breakpoint != Breakpoint.None)
            {
                Rect imgPosition;
                if (m_node is NodeGroup)
                {
                    imgPosition = new Rect(position.x + 2, position.y + 2, 12, 12);
                }
                else
                {
                    imgPosition = new Rect(position.x + 2, position.y + 2, 12, 12);
                }

                GUI.DrawTexture(imgPosition, BTEditorStyle.Breakpoint);
            }

            // show obsolete icon
            if (BTNodeObsoleteFactory.IsObsolete(m_node))
            {
                int  obsSize     = 24;
                Rect obsoletePos = new Rect(position.x + nodeSize.x - obsSize - 5, position.y + 5, obsSize, obsSize);
                GUI.DrawTexture(obsoletePos, BTEditorStyle.WarningIcon);
            }
        }
예제 #3
0
        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();
            }
        }
예제 #4
0
        private void DrawConstraints()
        {
            if (m_node.Constraints.Count == 0)
            {
                return;
            }

            Vector2 nodeSize = BTEditorStyle.GetNodeSize(m_node);
            Rect    position = new Rect(NodePosition + BTEditorCanvas.Current.Position, nodeSize);

            Rect cnsFoldoutPos = new Rect(position.x - 15, position.y + position.height, 10, 10);

            m_node.IsConstraintsExpanded = EditorGUI.Foldout(cnsFoldoutPos, m_node.IsConstraintsExpanded, GUIContent.none);

            int constraintOffsetY = 3;

            if (!m_node.IsConstraintsExpanded)
            {
                Rect consLabelPos = new Rect(cnsFoldoutPos.x + 20, cnsFoldoutPos.y + constraintOffsetY, 100, 20);
                EditorGUI.LabelField(consLabelPos, "<color=white>Constraints</color>", BTEditorStyle.NodeConstraintLabel);
            }
            else
            {
                int bits = -1;
                if (BTDebugHelper.DebugContext != null && BTDebugHelper.CurrentDebugRootTree != null)
                {
                    long treeId = BTDebugHelper.CurrentDebugRootTree.guid;
                    if (BTDebugHelper.DebugContext._travelNodes.ContainsKey(treeId))
                    {
                        if (BTDebugHelper.DebugContext._travelNodes[treeId].Contains(m_node))
                        {
                            bits = BTDebugHelper.DebugContext.blackboard.GetInt(treeId, m_node.guid, "Constraints");
                        }
                    }
                }

                bool lastFailed = false;
                for (int i = 0; i < m_node.Constraints.Count; i++)
                {
                    Constraint constraint = m_node.Constraints[i];

                    Rect headerPos = position;
                    headerPos.y += nodeSize.y + i * 16 + constraintOffsetY;
                    Rect labelPos = new Rect(headerPos.x, headerPos.y, position.width + 100, 16);

                    string str = "";
                    if (bits != -1 && !lastFailed)
                    {
                        int v = (bits >> i) & 1;
                        if (v == 1)
                        {
                            str = string.Format(constraint.InvertResult ? "<color=green>! {0}</color>" : "<color=green>{0}</color>", constraint.Title);
                        }
                        else
                        {
                            lastFailed = true;
                            str        = string.Format(constraint.InvertResult ? "<color=red>! {0}</color>" : "<color=red>{0}</color>", constraint.Title);
                        }
                    }
                    else
                    {
                        str = string.Format(constraint.InvertResult ? "<color=white>! {0}</color>" : "<color=white>{0}</color>", constraint.Title);
                    }
                    EditorGUI.LabelField(labelPos, str, BTEditorStyle.NodeConstraintLabel);
                }
            }

            // show obsolete icon
            if (!BTNodeObsoleteFactory.IsObsolete(m_node))
            {
                for (int i = 0; i < m_node.Constraints.Count; i++)
                {
                    Constraint constraint = m_node.Constraints[i];
                    if (BTNodeObsoleteFactory.IsObsolete(constraint))
                    {
                        int  obsSize     = 24;
                        Rect obsoletePos = new Rect(position.x + nodeSize.x - obsSize - 5, position.y + 5, obsSize, obsSize);
                        GUI.DrawTexture(obsoletePos, BTEditorStyle.WarningIcon);
                        break;
                    }
                }
            }
        }