コード例 #1
0
ファイル: NodeDrawer.cs プロジェクト: yabos/SaveTheQueen
        private static void DrawDecorators(Node node, ref float height)
        {
            for (int i = 0; i < node.decorators.Length; i++)
            {
                Decorator decorator = node.decorators[i];

                Rect decoratorRect = node.position;
                decoratorRect.xMin += 7;
                decoratorRect.xMax -= 7;
                decoratorRect.yMin  = height;
                decoratorRect.yMax  = height + 32 + GetCommentHeight(decorator.comment);

                GUIStyle decoratorStyle = BehaviorTreesEditorStyles.GetNodeStyle((int)NodeColor.Blue, BehaviorTreesEditor.CompareSelectedDecorators(decorator));
                if (EditorApplication.isPlaying)
                {
                    decoratorStyle = BehaviorTreesEditorStyles.GetNodeStyle(BehaviorTreesEditor.CheckThisDecoratorClosed(decorator) ? (int)NodeColor.Red : (int)NodeColor.Blue, BehaviorTreesEditor.CompareSelectedDecorators(decorator));
                }
                GUI.Box(decoratorRect, "", decoratorStyle);

                Rect decoratorIconRect = node.position;
                decoratorIconRect.x = node.position.xMin + 7;
                decoratorIconRect.y = height - 1;
                GUI.Label(decoratorIconRect, decoratorIcon);

                Rect decoratorNameRect = node.position;
                decoratorNameRect.x = node.position.xMin + 42;
                decoratorNameRect.y = height + 5;
                GUI.Label(decoratorNameRect, "<color=white>" + decorator.Name + "</color>", BehaviorTreesEditorStyles.nodeBoxNameNormalStyle);

                GUIContent decoratorCommentContent = new GUIContent(decorator.comment);
                Rect       decoratorCommentRect    = node.position;
                decoratorCommentRect.x     = node.position.xMin + 7;
                decoratorCommentRect.y     = height + 30;
                decoratorCommentRect.width = BehaviorTreesEditorStyles.nodeBoxCommentStyle.CalcSize(decoratorCommentContent).x + 10;
                GUI.Label(decoratorCommentRect, "<color=white>" + decorator.comment + "</color>", BehaviorTreesEditorStyles.nodeBoxCommentStyle);

                height += decoratorRect.yMax - decoratorRect.yMin + 5;
            }
        }
コード例 #2
0
ファイル: NodeDrawer.cs プロジェクト: yabos/SaveTheQueen
        private static void DrawServices(Node node, float height)
        {
            if (node is Composite)
            {
                Composite composite = node as Composite;
                for (int i = 0; i < composite.services.Length; i++)
                {
                    Service service = composite.services[i];

                    Rect serviceRect = node.position;
                    serviceRect.xMin += 7 + 13;
                    serviceRect.xMax -= 7;
                    serviceRect.yMin  = height;
                    serviceRect.yMax  = height + 32 + GetCommentHeight(service.comment);
                    GUIStyle serviceStyle = BehaviorTreesEditorStyles.GetNodeStyle((int)NodeColor.Aqua, BehaviorTreesEditor.CompareSelectedServices(service));
                    GUI.Box(serviceRect, "", serviceStyle);

                    Rect serviceIconRect = node.position;
                    serviceIconRect.x = node.position.xMin + 7 + 13;
                    serviceIconRect.y = height - 1;
                    GUI.Label(serviceIconRect, serviceIcon);

                    Rect serviceNameRect = node.position;
                    serviceNameRect.x = node.position.xMin + 42 + 13;
                    serviceNameRect.y = height + 5;
                    GUI.Label(serviceNameRect, "<color=white>" + service.Name + "</color>", BehaviorTreesEditorStyles.nodeBoxNameNormalStyle);

                    GUIContent serviceCommentContent = new GUIContent(service.comment);
                    Rect       serviceCommentRect    = node.position;
                    serviceCommentRect.x     = node.position.xMin + 7 + 13;
                    serviceCommentRect.y     = height + 30;
                    serviceCommentRect.width = BehaviorTreesEditorStyles.nodeBoxCommentStyle.CalcSize(serviceCommentContent).x + 10;
                    GUI.Label(serviceCommentRect, "<color=white>" + service.comment + "</color>", BehaviorTreesEditorStyles.nodeBoxCommentStyle);

                    height += serviceRect.yMax - serviceRect.yMin + 5;
                }
            }
        }
コード例 #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();
                }
            }
        }
コード例 #4
0
ファイル: NodeDrawer.cs プロジェクト: yabos/SaveTheQueen
        private static void DrawNode(Node node, bool selected, Texture2D iconImage, int boxColor)
        {
            float sharedHeight = node.position.yMin + 15;

            DrawDecorators(node, ref sharedHeight);

            Rect insideMainNode = node.position;

            insideMainNode.xMin += 7;
            insideMainNode.xMax -= 7;
            insideMainNode.yMin  = sharedHeight;
            insideMainNode.yMax  = sharedHeight + 32 + GetCommentHeight(node.comment);

            GUIStyle insideMainNodeStyle = BehaviorTreesEditorStyles.GetNodeStyle(boxColor, false);

            if (EditorApplication.isPlaying)
            {
                if (node is Task)
                {
                    Task t = node as Task;
                    insideMainNodeStyle = BehaviorTreesEditorStyles.GetNodeStyle(
                        BehaviorTreesEditor.CheckThisTaskClosed(t) ? (int)NodeColor.Yellow : boxColor, BehaviorTreesEditor.CheckThisTaskClosed(t));
                }
            }
            GUI.Box(insideMainNode, "", insideMainNodeStyle);

            int?myIndex = BehaviorTreesEditorUtility.GetMyIndex(node);

            if (myIndex != null && circleIcon != null)
            {
                float circleIconWidth  = circleIcon.width * 1.1f;
                float circleIconHeight = circleIcon.height * 1.1f;
                Rect  indexRect        = new Rect(insideMainNode.xMax - circleIconWidth / 2f + 12, insideMainNode.yMin - circleIconHeight / 2f, circleIconWidth, circleIconHeight);
                GUI.DrawTexture(indexRect, circleIcon);
                indexRect.xMin -= 2;
                indexRect.yMin -= 2;
                GUI.Label(indexRect, "<color=black>" + (myIndex + 1).ToString() + "</color>", BehaviorTreesEditorStyles.nodeIndexLabel);
            }

            Rect iconRect = node.position;

            iconRect.x = node.position.xMin + 7;
            iconRect.y = sharedHeight - 1;
            GUI.Label(iconRect, iconImage);

            Rect nameRect = node.position;

            nameRect.x = node.position.xMin + 42;
            nameRect.y = sharedHeight + 5;

            GUI.Label(nameRect, "<color=white>" + node.Name + "</color>", BehaviorTreesEditorStyles.nodeBoxNameNormalStyle);

            GUIContent commentContent = new GUIContent(node.comment);
            Rect       commentRect    = node.position;

            commentRect.x     = node.position.xMin + 7;
            commentRect.y     = sharedHeight + 30;
            commentRect.width = BehaviorTreesEditorStyles.nodeBoxCommentStyle.CalcSize(commentContent).x + 10;
            GUI.Label(commentRect, "<color=white>" + node.comment + "</color>", BehaviorTreesEditorStyles.nodeBoxCommentStyle);

            sharedHeight += insideMainNode.yMax - insideMainNode.yMin + 5;
            DrawServices(node, sharedHeight);
        }