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;
            }
        }
Beispiel #2
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);
        }