예제 #1
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);
        }
예제 #2
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);
        }
예제 #3
0
 private void DoTransition(Node node)
 {
     // This code is borrowed from ICode(https://www.assetstore.unity3d.com/en/#!/content/13761)
     Node[] childNodes = node.childNodes;
     if (node.childNodes != null)
     {
         for (int i = 0; i < childNodes.Length; i++)
         {
             Node child = childNodes[i];
             child.position.width  = NodeDrawer.GetMaxWidthContents(child);
             child.position.height = NodeDrawer.GetMaxHeightContents(child);
             if (EditorApplication.isPlaying)
             {
                 if (CompareLockedNodes(child))
                 {
                     DrawConnection(node.position.center, new Vector3(child.position.center.x, child.position.yMin - 7), Color.cyan, 1, false, true);
                 }
                 else
                 {
                     DrawConnection(node.position.center, new Vector3(child.position.center.x, child.position.yMin - 7), Color.gray, 1, false, false, 1);
                 }
             }
             else
             {
                 DrawConnection(node.position.center, new Vector3(child.position.center.x, child.position.yMin - 7), Color.white, 1, false, false, 1);
             }
         }
     }
 }
예제 #4
0
        private void DoNode(Node node)
        {
            GUIStyle style = BehaviorTreeEditorStyles.GetNodeStyle((int)NodeColor.Grey, _selection.Contains(node));

            if (EditorApplication.isPlaying && CompareLockedNodes(node))
            {
                style = BehaviorTreeEditorStyles.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 = BehaviorTreeEditorStyles.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 = BehaviorTreeEditorStyles.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();
                }
            }
        }