private void resetState() { _bIsAreaSelecting = false; _bIsDragging = false; _bIsMakingConnection = false; _draggingNode = null; _outputKnobToConnect = null; }
private void handleNodeConnection(Event e) { // Start a connection action. if (e.type == EventType.MouseDown && e.button == 0) { Action <BonsaiOutputKnob> outputCallback = (output) => { e.Use(); _bIsMakingConnection = true; _outputKnobToConnect = output; }; // Check to see if we are making connection starting from output knob. bool bResult = _window.editor.OnMouseOverOutput(outputCallback); // Check if we are making connection starting from input if (!bResult) { Action <BonsaiInputKnob> inputCallback = (input) => { // Starting a connection from input means that its connected // output will change its input. if (input.outputConnection != null) { e.Use(); _bIsMakingConnection = true; _outputKnobToConnect = input.outputConnection; // We disconnect the input since we want to change it to a new input. input.outputConnection.RemoveInputConnection(input); } }; _window.editor.OnMouseOverInput(inputCallback); } } // Finish making the connection. else if (e.type == EventType.MouseUp && e.button == 0 && _bIsMakingConnection) { Action <BonsaiNode> callback = (node) => { _outputKnobToConnect.Add(node.Input); // When a connection is made, we need to make sure the positional // ordering reflects the internal tree structure. node.NotifyParentOfPostionalReordering(); }; _window.editor.OnMouseOverNode_OrInput(callback); _bIsMakingConnection = false; _outputKnobToConnect = null; } }
/// <summary> /// Create a new node for the first time. /// </summary> /// <param name="parentCanvas">The canvas that the node belongs to.</param> /// <param name="bCreateInput">If the node should have an input.</param> /// <param name="bCreateOuput">If the node should have an output.</param> public BonsaiNode(BonsaiCanvas parentCanvas, bool bCreateInput, bool bCreateOuput, bool bCanHaveMultipleChildren) { bodyRect = new Rect(Vector2.zero, kDefaultSize); if (bCreateInput) { _inputKnob = new BonsaiInputKnob(); _inputKnob.parentNode = this; } if (bCreateOuput) { _outputKnob = new BonsaiOutputKnob(); _outputKnob.parentNode = this; } this.bCanHaveMultipleChildren = bCanHaveMultipleChildren; }