コード例 #1
0
        void DrawMain()
        {
            if (_curFlowGraph == null)
            {
                if (GUI.Button(new Rect(_fSplitterX / 2f - 50f, position.height / 2f - 15f, 100f, 30f), "Create"))
                {
                    _curFlowGraph = CreateInstance <FlowGraph>();
                }
            }
            else
            {
                DrawMiniMap();

                if (_curFlowGraph.NodeCount > 0)
                {
                    Handles.BeginGUI();

                    foreach (FlowNode node in _curFlowGraph.NodeList)
                    {
                        if (node == null)
                        {
                            Debug.Log("[FlowEditorWindow]DrawMain node is null");
                            continue;
                        }

                        if (node.linkList == null)
                        {
                            continue;
                        }

                        FlowNode deleteNode = null;
                        foreach (int linkId in node.linkList)
                        {
                            FlowNode linkNode = _curFlowGraph.GetNode(linkId);
                            Rect     nodeRect = node.GetRectInGraph(_curFlowGraph);
                            Rect     linkRect = linkNode.GetRectInGraph(_curFlowGraph);
                            if (DrawBezier(new Vector2(nodeRect.x + nodeRect.width, nodeRect.y + fLinkIconWidth / 2f), new Vector2(linkRect.x, linkRect.y + fLinkIconWidth / 2f), Color.yellow))
                            {
                                deleteNode = linkNode;
                            }
                        }

                        if (deleteNode != null)
                        {
                            node.RemoveLinkNode(deleteNode);
                            deleteNode.RemovePreNode(node);
                        }
                    }

                    Handles.EndGUI();
                }

                BeginWindows();

                List <FlowNode> nodeList  = _curFlowGraph.NodeList;
                int             nodeCount = _curFlowGraph.NodeCount;
                for (int i = 0; i < nodeCount; i++)
                {
                    FlowNode node = nodeList[i];

                    Rect    rect        = node.GetRectInGraph(_curFlowGraph);
                    Vector2 topLeft     = new Vector2(rect.x, rect.y);
                    Vector2 topRight    = new Vector2(rect.x + node.NodeWidth, rect.y);
                    Vector2 bottomLeft  = new Vector2(rect.x, rect.y + node.NodeHeight);
                    Vector2 bottomRight = new Vector2(rect.x + node.NodeWidth, rect.y + node.NodeHeight);

                    if (_rectMain.Contains(topLeft) ||
                        _rectMain.Contains(topRight) ||
                        _rectMain.Contains(bottomLeft) ||
                        _rectMain.Contains(bottomRight))
                    {
                        if (node == _curSelectFlowNode)
                        {
                            GUI.color = nodeSelectedColor;
                        }
                        else
                        {
                            GUI.color = node.GetColor();
                        }

                        rect = GUI.Window(node.id, rect, DrawNode, node.NodeName);

                        GUI.color = Color.white;
                    }

                    node.SetRectInGraph(_curFlowGraph, rect.position);
                }

                DrawLinking();

                EndWindows();
            }
        }