GetKnob() public method

Get the rect of the knob left to the input
public GetKnob ( ) : Rect
return Rect
Beispiel #1
0
    /// <summary>
    /// Draws the node curves as well as the knobs
    /// </summary>
    public void DrawConnectors()
    {
        for (int outCnt = 0; outCnt < Outputs.Count; outCnt++)
        {
            NodeOutput output = Outputs [outCnt];

            for (int conCnt = 0; conCnt < output.connections.Count; conCnt++)
            {
                if (output.connections [conCnt] != null)
                {
                    Node_Editor.DrawNodeCurve(output.GetKnob().center,
                                              output.connections [conCnt].GetKnob().center);
                }
                else
                {
                    output.connections.RemoveAt(conCnt);
                }
            }

            GUI.DrawTexture(output.GetKnob(), Node_Editor.ConnectorKnob);
        }

        for (int inCnt = 0; inCnt < Inputs.Count; inCnt++)
        {
            GUI.DrawTexture(Inputs [inCnt].GetKnob(), Node_Editor.ConnectorKnob);
        }
    }
Beispiel #2
0
 /// <summary>
 /// Draws the node curves as well as the knobs
 /// </summary>
 public void DrawConnectors()
 {
     for (int outCnt = 0; outCnt < outputs.Count; outCnt++)
     {
         NodeOutput output = outputs [outCnt];
         for (int conCnt = 0; conCnt < output.connections.Count; conCnt++)
         {
             if (output.connections[conCnt] != null)
             {
                 Node_Editor.DrawNodeCurve(output.GetKnob().center, output.connections[conCnt].GetKnob().center);
             }
             else
             {
                 output.connections.RemoveAt(conCnt);
             }
         }
         GUI.DrawTexture(output.GetKnob(), Node_Editor.ConnectorKnob);
     }
     for (int inCnt = 0; inCnt < inputs.Count; inCnt++)
     {
         //GUI.DrawTexture (inputs [inCnt].GetKnob (), Node_Editor.ConnectorKnob);
         GUI.DrawTextureWithTexCoords(inputs[inCnt].GetKnob(), Node_Editor.ConnectorKnob, new Rect(1, 0, -1, 1));
     }
 }
Beispiel #3
0
 /// <summary>
 /// Draws the node curves as well as the knobs
 /// </summary>
 public void DrawConnectors()
 {
     for (int outCnt = 0; outCnt < Outputs.Count; outCnt++)
     {
         NodeOutput output = Outputs [outCnt];
         for (int conCnt = 0; conCnt < output.connections.Count; conCnt++)
         {
             Color lineColor = Color.black;
             if (output.connections[conCnt] != null)
             {
                 if (output.connections[conCnt].type == IOtype.ObjectOnly)
                 {
                     lineColor = Color.blue;
                 }
                 else if (output.connections[conCnt].type == IOtype.ItemOnly)
                 {
                     lineColor = Color.green;
                 }
                 else if (output.connections[conCnt].type == IOtype.SelectionOnly)
                 {
                     lineColor = Color.red;
                 }
                 Node_Editor.DrawNodeCurve(output.GetKnob().center, output.connections [conCnt].GetKnob().center, lineColor);
             }
             else
             {
                 output.connections.RemoveAt(conCnt);
             }
         }
         GUI.DrawTexture(output.GetKnob(), Node_Editor.ConnectorKnob);
     }
     for (int inCnt = 0; inCnt < Inputs.Count; inCnt++)
     {
         GUI.DrawTexture(Inputs [inCnt].GetKnob(), Node_Editor.ConnectorKnob);
     }
 }
    /// <summary>
    /// Processes input events
    /// </summary>
    protected void InputEvents()
    {
        Event e = Event.current;

        mousePos = e.mousePosition;

        Node clickedNode = null;

        if (e.type == EventType.MouseDown || e.type == EventType.MouseUp)
        {
            clickedNode = NodeAtPosition(e.mousePosition);
        }

        if (e.type == EventType.Repaint)
        {
            // Draw background when repainting
            Vector2 offset = new Vector2(_nodeCanvas.scrollOffset.x % Background.width - Background.width,
                                         _nodeCanvas.scrollOffset.y % Background.height - Background.height);
            int tileX = Mathf.CeilToInt((position.width + (Background.width - offset.x)) / Background.width);
            int tileY = Mathf.CeilToInt((position.height + (Background.height - offset.y)) / Background.height);

            for (int x = 0; x < tileX; x++)
            {
                for (int y = 0; y < tileY; y++)
                {
                    Rect texRect = new Rect(offset.x + x * Background.width,
                                            offset.y + y * Background.height,
                                            Background.width, Background.height);
                    GUI.DrawTexture(texRect, Background);
                }
            }
        }

        if (e.type == EventType.MouseDown)
        {
            activeNode    = clickedNode;
            connectOutput = null;

            if (clickedNode != null)
            {
                // A click on a node
                if (e.button == 1)
                {
                    // Right click -> Node Context Click
                    GenericMenu menu = new GenericMenu();

                    menu.AddItem(new GUIContent("Delete Node"), false, ContextCallback, "deleteNode");

                    menu.ShowAsContext();
                    e.Use();
                }
                else if (e.button == 0)
                {
                    /* // Handled by Unity. For new Windowing System
                     * // Left click -> check for drag on the header and for transition edits, else let it pass for gui elements
                     * if (new Rect (clickedNode.rect.x, clickedNode.rect.y, clickedNode.rect.width, 40).Contains (mousePos))
                     * { // We clicked the header, so we'll drag the node
                     *      dragNode = true;
                     *      e.delta = new Vector2 (0, 0);
                     * }*/

                    // If a Connection was left clicked, try edit it's transition
                    NodeOutput nodeOutput = clickedNode.GetOutputAtPos(mousePos);

                    if (nodeOutput != null)
                    {                     // Output Node -> New Connection drawn from this
                        connectOutput = nodeOutput;
                        e.Use();
                    }
                    else
                    {                     // no output clicked, check input
                        NodeInput nodeInput = clickedNode.GetInputAtPos(mousePos);

                        if (nodeInput != null && nodeInput.connection != null)
                        {                         // Input node -> Loose and edit Connection
                            connectOutput = nodeInput.connection;
                            nodeInput.connection.connections.Remove(nodeInput);
                            nodeInput.connection = null;
                            RecalculateFrom(clickedNode);
                            e.Use();
                        }                         // Nothing interesting for us in the node clicked, so let the event pass to gui elements
                    }
                }
            }
            else if (!sideWindowRect.Contains(mousePos))
            {
                // A click on the empty canvas
                if (e.button == 2 || e.button == 0)
                {
                    // Left/Middle Click -> Start scrolling
                    scrollWindow = true;
                    e.delta      = new Vector2(0, 0);
                }
                else if (e.button == 1)
                {
                    // Right click -> Editor Context Click
                    GenericMenu menu = new GenericMenu();

                    AddRightClickMenuItems(menu);

                    menu.ShowAsContext();
                    e.Use();
                }
            }
        }
        else if (e.type == EventType.MouseUp)
        {
            if (connectOutput != null)
            {
                // Apply a connection if theres a clicked input
                if (clickedNode != null && !clickedNode.Outputs.Contains(connectOutput))
                {
                    // If an input was clicked, it'll will now be connected
                    NodeInput clickedInput = clickedNode.GetInputAtPos(mousePos);

                    if (Node.CanApplyConnection(connectOutput, clickedInput))
                    {
                        // If it can connect (type is equals, it does not cause recursion, ...)
                        Node.ApplyConnection(connectOutput, clickedInput);
                    }
                }
                e.Use();
            }
            else if (e.button == 2 || e.button == 0)
            {
                // Left/Middle click up -> Stop scrolling
                scrollWindow = false;
            }

            connectOutput = null;
        }
        else if (e.type == EventType.KeyDown)
        {
            if (e.keyCode == KeyCode.N)             // Start Navigating (curve to origin)
            {
                navigate = true;
            }
        }
        else if (e.type == EventType.KeyUp)
        {
            if (e.keyCode == KeyCode.N)             // Stop Navigating
            {
                navigate = false;
            }
        }
        else if (e.type == EventType.Repaint)
        {
            if (navigate)
            {
                // Draw a curve to the origin/active node for orientation purposes
                DrawNodeCurve(_nodeCanvas.scrollOffset, (activeNode != null? activeNode.rect.center : e.mousePosition));
                Repaint();
            }
            if (connectOutput != null)
            {
                // Draw the currently drawn connection
                DrawNodeCurve(connectOutput.GetKnob().center, e.mousePosition);
                Repaint();
            }
        }
        if (scrollWindow)
        {
            // Scroll everything with the current mouse delta
            _nodeCanvas.scrollOffset += e.delta / 2;

            for (int nodeCnt = 0; nodeCnt < _nodeCanvas.nodes.Count; nodeCnt++)
            {
                _nodeCanvas.nodes [nodeCnt].rect.position += e.delta / 2;
            }

            Repaint();
        }

        /* // Handled by Unity. For new Windowing System
         * if (dragNode)
         * { // Drag the active node with the current mouse delt
         *      activeNode.rect.position += e.delta / 2;
         *      Repaint ();
         * }*/
    }