Beispiel #1
0
        void DrawBranch(BranchNode branch)
        {
            //if node is a branch, draw children and widgets.
            if (branch != null)
            {
                cursor.x += SPACING.x;
                var top    = branch.rect.yMax;
                var bottom = branch.rect.yMax;
                for (int i = 0; i < branch.Children.Count; i++)
                {
                    var c = branch.Children[i];
                    if (c != null)
                    {
                        Draw(c, branch);
                        bottom = c.rect.center.y;
                        dropZones.Add(new DropZone(branch, c.rect, i));

                        if (i == branch.Children.Count - 1)
                        {
                            dropZones.Add(new DropZone(branch, c.rect, i + 1, true));
                        }
                    }
                }
                var left = branch.rect.x + (SPACING.x / 2);
                ReactEditorUtility.DrawLine(new Vector2(left, top), new Vector3(left, bottom), Color.white);
                cursor.x -= SPACING.x;
            }
        }
        void DrawDragOutlines(BaseNode node)
        {
            DrawChildOutlines(node);
            var rect = dragNode.rect;

            rect.position = mousePosition;
            ReactEditorUtility.DrawOutline(rect, Color.yellow / 2, Color.yellow / 2);
        }
        void DrawChildOutlines(BaseNode node)
        {
            ReactEditorUtility.DrawOutline(node.rect, Color.yellow / 2, Color.yellow / 2);
            var p = node as IParentNode;

            if (p != null)
            {
                foreach (var c in p.GetChildren())
                {
                    DrawChildOutlines(c);
                }
            }
        }
        void OnGUIHasBeenDrawn()
        {
            var e = Event.current;

            if (e.type == EventType.MouseDrag && e.delta.sqrMagnitude > 1 && reactor.hotNode != null && reactor.hotNode.rect.Contains(mousePosition) && e.button == 0)
            {
                StartDrag();
                e.Use();
            }
            if (e.type == EventType.DragUpdated)
            {
                UpdateDrag();
                e.Use();
            }
            if (e.type == EventType.DragExited)
            {
                ExitDrag();
                e.Use();
            }
            if (e.type == EventType.DragPerform)
            {
                PerformDrag();
                e.Use();
            }
            if (dragNode != null)
            {
                DrawDragOutlines(dragNode);
            }

            if (dropZone != null)
            {
                if (dropZone.parent != null)
                {
                    var rect = dropZone.rect;
                    if (dropZone.last)
                    {
                        rect.y = rect.yMax;
                    }
                    else
                    {
                        rect.y -= 1;
                    }
                    rect.height = 1;
                    ReactEditorUtility.DrawOutline(dropZone.parent.rect, Color.cyan, Color.cyan / 2);
                    ReactEditorUtility.DrawOutline(rect, Color.white, Color.white / 2);
                }
            }
        }
Beispiel #5
0
        void DrawExecutionState(BaseNode node)
        {
            var stateColor = new Color(1, 1, 1, 0);

            if (Application.isPlaying)
            {
                switch (node.lastState)
                {
                case NodeState.Aborted: stateColor = Color.magenta; break;

                case NodeState.Success: stateColor = Color.green; break;

                case NodeState.Failure: stateColor = Color.red; break;

                case NodeState.NoResult: stateColor = Color.white; break;
                }
                if (node.lastState != NodeState.None)
                {
                    stateColor.a = 0.7f * Mathf.Clamp01(1 - ((Time.time - node.lastExecuteTime)));
                }
                ReactEditorUtility.DrawOutline(node.rect, stateColor, stateColor / 2);
            }
        }
Beispiel #6
0
        void Draw(BaseNode node, BaseNode parent)
        {
            if (node == null)
            {
                return;
            }
            var visible = IsVisible(node);

            node.nodeParent = parent;
            node.rect.y     = cursor.y;
            GUI.color       = Color.white;
            if (visible)
            {
                ReactEditorUtility.DrawBackground(node.rect, reactor.hotNode == node && dragNode == null ? style : GUI.skin.box);
            }
            node.rect = cursor;
            if (visible)
            {
                if (node is Comment && reactor.hotNode != node)
                {
                    var comment = node as Comment;
                    var oc      = new GUIContent(comment.text);
                    //draw node contents
                    var size = EditorStyles.boldLabel.CalcSize(oc);
                    node.rect.width  = size.x + 32;
                    node.rect.height = size.y * 2;
                    EditorGUI.HelpBox(node.rect, comment.text, MessageType.Info);
                    // GUI.Label(node.rect, oc, EditorStyles.boldLabel);
                }
                else
                {
                    Texture icon = null;
                    icon = EditorGUIUtility.ObjectContent(null, node.GetWrappedType()).image;
                    if (node != root)
                    {
                        if (icon == null)
                        {
                            icon = GetIcon(node);
                        }
                        var oc = new GUIContent(node.ToString());
                        //draw node contents
                        var size = EditorStyles.boldLabel.CalcSize(oc);
                        oc.image        = icon;
                        node.rect.width = size.x + 32;
                        GUI.Label(node.rect, oc, EditorStyles.boldLabel);
                    }
                    var focus = false;
                    if (focusFirstControl && reactor.hotNode == node)
                    {
                        focus             = true;
                        focusFirstControl = false;
                    }
                    ReactFieldEditor.DrawFields(node, focus, reactor.hotNode == node);
                }
            }

            var left = 0f;

            if (node.nodeParent != null)
            {
                if (node.nodeParent is DecoratorNode)
                {
                    left = node.nodeParent.rect.xMax;
                }
                else
                {
                    left = node.nodeParent.rect.x + (SPACING.x / 2);
                }
            }
            var top   = node.rect.center.y;
            var right = node.rect.x;

            ReactEditorUtility.DrawLine(new Vector2(left, top), new Vector3(right, top), Color.white);
            cursor.y += node.rect.height + SPACING.y;
            if (visible)
            {
                DrawExecutionState(node);
            }
            DrawRoot(node as Root);
            DrawBranch(node as BranchNode);
            DrawDecorator(node as DecoratorNode);
            viewRect.xMax = Mathf.Max(viewRect.xMax, node.rect.xMax + 32);
            viewRect.yMax = Mathf.Max(viewRect.yMax, node.rect.yMax + 8);
        }