Ejemplo n.º 1
0
        private Decorator MouseOverDecorator()
        {
            for (int i = 0; i < nodes.Length; i++)
            {
                Node  node         = nodes[i];
                float sharedHeight = node.position.yMin + 7;
                float sharedWidth  = node.position.width - 14;
                for (int j = 0; j < node.decorators.Length; j++)
                {
                    Decorator decorator = node.decorators[j];

                    Rect decoratorRect = node.position;
                    decoratorRect.width = sharedWidth;
                    decoratorRect.yMin  = sharedHeight;
                    decoratorRect.yMax  = sharedHeight + 32 + NodeDrawer.GetCommentHeight(decorator.comment);

                    if (decoratorRect.Contains(_mousePosition))
                    {
                        return(decorator);
                    }

                    sharedHeight += decoratorRect.yMax - decoratorRect.yMin + 5;
                }
            }
            return(null);
        }
Ejemplo n.º 2
0
        private Service MouseOverService()
        {
            for (int i = 0; i < nodes.Length; i++)
            {
                Node node = nodes[i];
                if (node is Composite)
                {
                    Composite composite = node as Composite;

                    float sharedHeight = node.position.yMax - 14;
                    for (int j = composite.services.Length - 1; j >= 0; j--)
                    {
                        Service service = composite.services[j];

                        Rect serviceRect = node.position;
                        serviceRect.xMin += 7 + 13;
                        serviceRect.xMax -= 7;
                        serviceRect.yMin  = sharedHeight - (32 + NodeDrawer.GetCommentHeight(service.comment));
                        serviceRect.yMax  = sharedHeight;

                        if (serviceRect.Contains(_mousePosition))
                        {
                            return(service);
                        }

                        sharedHeight -= serviceRect.yMax - serviceRect.yMin + 5;
                    }
                }
            }
            return(null);
        }
Ejemplo n.º 3
0
        private void DoNode(Node node)
        {
            GUIStyle style = BehaviorTreesEditorStyles.GetNodeStyle((int)NodeColor.Grey, _selection.Contains(node));

            if (EditorApplication.isPlaying && CompareLockedNodes(node))
            {
                style = BehaviorTreesEditorStyles.GetNodeStyle((int)NodeColor.Yellow, _selection.Contains(node));
            }

            node.position.width  = NodeDrawer.GetMaxWidthContents(node);
            node.position.height = NodeDrawer.GetMaxHeightContents(node);

            GUI.Box(node.position, "", style);

            NodeDrawer.DrawNode(node, _selection.Contains(node));

            if (node.hasTopSelector)
            {
                Rect rect = node.position;
                rect.x     += 20;
                rect.width  = rect.width - 40;
                rect.height = 10;

                GUIStyle topSelectorStyle = BehaviorTreesEditorStyles.GetSelectorStyle(false);

                if (GUI.Button(rect, "", topSelectorStyle) && !EditorApplication.isPlayingOrWillChangePlaymode)
                {
                    if (_fromNode == null)
                    {
                        _fromNode    = node;
                        _isTopSelect = true;
                        if (node.parentNode != null)
                        {
                            node.parentNode.childNodes = ArrayUtility.Remove <Node>(node.parentNode.childNodes, node);
                            node.parentNode            = null;
                        }
                    }
                    else
                    {
                        if (!_isTopSelect && !ArrayUtility.Contains(_fromNode.childNodes, node))
                        {
                            AddTransition(_fromNode, node);
                        }
                        _fromNode = null;
                    }

                    GUIUtility.hotControl      = 0;
                    GUIUtility.keyboardControl = 0;

                    _selection.Clear();
                    _selection.Add(node);

                    UpdateUnitySelection();
                }
            }

            if (node.hasBotSelector)
            {
                Rect rect = node.position;
                rect.x     += 20;
                rect.y     += rect.height - 14;
                rect.width  = rect.width - 40;
                rect.height = 10;

                GUIStyle botSelectorStyle = BehaviorTreesEditorStyles.GetSelectorStyle(false);

                if (GUI.Button(rect, "", botSelectorStyle) && !EditorApplication.isPlayingOrWillChangePlaymode)
                {
                    if (_fromNode == null)
                    {
                        _fromNode    = node;
                        _isTopSelect = false;
                    }
                    else
                    {
                        if (_isTopSelect && !ArrayUtility.Contains(node.childNodes, _fromNode))
                        {
                            AddTransition(node, _fromNode);
                        }
                        _fromNode = null;
                    }

                    GUIUtility.hotControl      = 0;
                    GUIUtility.keyboardControl = 0;

                    _selection.Clear();
                    _selection.Add(node);

                    UpdateUnitySelection();
                }
            }
        }