Esempio n. 1
0
    void DrawConnections(MarrowNode node)
    {
        for (int i = 0; i < node.GetOutputSize(); i++)
        {
            MarrowNode connectTo = node.GetOutput(i);
            if (connectTo == null)
            {
                break;
            }

            Handles.BeginGUI();
            Handles.color = Color.black;

            Rect    startBox = GetConnectionBox(false, i, node);
            Vector3 startPos = new Vector3(node.editorPosition.xMax,
                                           node.editorPosition.y + startBox.center.y - 5, 0);

            Rect    endBox = GetConnectionBox(true, node.GetOutputConnection(i), node);
            Vector3 endPos = new Vector3(connectTo.editorPosition.x,
                                         connectTo.editorPosition.y + endBox.center.y - 5, 0);

            Vector3 startTangent = startPos + Vector3.right * (Vector3.Distance(startPos, endPos) / 3F);
            Vector3 endTangent   = endPos + Vector3.left * (Vector3.Distance(startPos, endPos) / 3F);

            Handles.DrawBezier(startPos, endPos, startTangent, endTangent, Color.black, null, 2);
            Handles.EndGUI();
        }
    }
Esempio n. 2
0
    void DrawNode(int nodeID)
    {
        MarrowNode node = nodes[nodeID];

        for (int i = 0; i < node.GetInputSize(); i++)
        {
            Rect connectionBox = GetConnectionBox(true, i, node);

            if (ClickBox(new Rect(0, connectionBox.y + 3, 10, 10), node.editorPosition))
            {
                link.input       = node;
                link.inputNumber = i;
                OnLink();
            }
            GUI.Label(new Rect(12, connectionBox.y, connectionBox.width, connectionBox.height),
                      node.InputLabels[i]);
        }

        for (int i = 0; i < node.GetOutputSize(); i++)
        {
            Rect connectionBox = GetConnectionBox(false, i, node);

            if (ClickBox(new Rect(connectionBox.xMax - 10, connectionBox.y + 3, 10, 10), node.editorPosition))
            {
                link.output       = node;
                link.outputNumber = i;
                OnLink();
            }
            GUI.Label(new Rect(0, connectionBox.y, connectionBox.width, connectionBox.height),
                      node.OutputLabels[i]);
        }

        NodeSelect(node);

        GUI.DragWindow();
        if (snap)
        {
            node.editorPosition.x = Mathf.Floor(node.editorPosition.x / gridSize) * gridSize;
            node.editorPosition.y = Mathf.Floor(node.editorPosition.y / gridSize) * gridSize;
        }
        node.editorPosition.width  = 100;
        node.editorPosition.height = 30 + ((node.GetOutputSize() + node.GetInputSize()) * 18);
    }