Ejemplo n.º 1
0
    protected virtual void DrawStackNode(StateNode node)
    {
        if (!Canvas.DrawRect(node.Bounds, StackBackgroundColor, true, true, true, Selecteds.Contains(node)))
        {
            return;
        }
        Rect topBound = new Rect(node.Bounds.position, new Vector2(STACK_NODE_WIDTH, STACK_TOP_HEIGHT));

        //画顶部区域,包含文字、输入、添加子节点
        if (Canvas.DrawRect(topBound, StackNodeColor, true, false))
        {
            topBound.position += new Vector2(PIN_WIDTH + 4, 0);
            topBound.width    -= PIN_WIDTH * 2;
            var icon = TypeIconCollector.Get(node.NodeType);
            if (icon)
            {
                Rect rect = new Rect(topBound.x, topBound.y, ICON_SIZE, topBound.height);
                Canvas.DrawIcon(rect, icon);
                topBound.x     += ICON_SIZE;
                topBound.width -= ICON_SIZE;
            }
            Canvas.DrawText(topBound, node.Name, null, node.Comments, StateGraphEditorStyles.NodeNameStyle);
            if (Graph.ChechInput(node))
            {
                Vector2 pos = GetInputPin(node);
                Canvas.DrawCircle(pos, CircleWireColor, PIN_RADIUS, true);
                if (Graph.Links.Exists(it => it.To == node))
                {
                    Canvas.DrawCircle(pos, CircleSoldColor, PIN_RADIUS - 2, false);
                }
            }
            Rect addRect = GetAddChildPinRect(node);
            Canvas.DrawText(addRect, "✚", null, null, StateGraphEditorStyles.TxtButtonStyle);
        }
        childLinkTmp.Clear();
        {//左侧区域
            Rect centerLeftRect = node.Bounds;
            centerLeftRect.position += new Vector2(0, STACK_TOP_HEIGHT + CHILD_INTERVAL);
            centerLeftRect.height   -= (STACK_BOTTOM_HEIGHT + STACK_TOP_HEIGHT + CHILD_INTERVAL * 2);
            centerLeftRect.width     = STACK_LEFT_WIDTH;
            Canvas.DrawRect(centerLeftRect, StackNodeColor, false, false);
        }
        foreach (var link in Graph.Links)
        {
            if (link.IsChild && link.From == node)
            {
                childLinkTmp.Add(link);
            }
        }
        for (int i = 0; i < childLinkTmp.Count; ++i)
        {
            var link = childLinkTmp[i];
            DrawNormalNode(link.To.Node, true);
            if (!Selecteds.Contains(link.To))
            {
                continue;
            }
            if (childLinkTmp.Count > 1)
            {
                Rect btnSize = link.To.Node.Bounds;
                btnSize.position -= new Vector2(STACK_LEFT_WIDTH + 1, -3);
                btnSize.width     = STACK_LEFT_WIDTH;
                btnSize.height    = NODE_HEIGHT * 0.5f;
                if (i > 0)
                {
                    //上移按钮
                    if (Canvas.DrawButton(btnSize, "▲", StateGraphEditorStyles.TxtButtonStyle) && !ReadOnly)
                    {
                        ChildNodeMoveUp(link.To);
                    }
                }
                if (i < childLinkTmp.Count - 1)
                {
                    btnSize.position += new Vector2(0, NODE_HEIGHT * 0.5f);
                    //下移按钮
                    if (Canvas.DrawButton(btnSize, "▼", StateGraphEditorStyles.TxtButtonStyle) && !ReadOnly)
                    {
                        ChildNodeMoveDown(link.To);
                    }
                }
            }
        }
        Rect bottomRect = new Rect(node.Bounds.xMin, node.Bounds.yMax - STACK_BOTTOM_HEIGHT, STACK_NODE_WIDTH, STACK_BOTTOM_HEIGHT);

        if (Canvas.DrawRect(bottomRect, StackNodeColor, false, true))
        {
            if (Graph.CheckOutput(node))
            {
                Vector2 pos = GetOutputPin(node);
                Canvas.DrawCircle(pos, CircleWireColor, PIN_RADIUS, true);
                if (Graph.Links.Exists(it => !it.IsChild && it.From == node))
                {
                    Canvas.DrawCircle(pos, CircleSoldColor, PIN_RADIUS - 2, false);
                }
            }
        }
    }