diff --git a/Source/Editor/Surface/Archetypes/Animation.StateMachine.cs b/Source/Editor/Surface/Archetypes/Animation.StateMachine.cs index 0b2c6b01d..6b555360e 100644 --- a/Source/Editor/Surface/Archetypes/Animation.StateMachine.cs +++ b/Source/Editor/Surface/Archetypes/Animation.StateMachine.cs @@ -476,6 +476,7 @@ namespace FlaxEditor.Surface.Archetypes var state = (StateMachineState)other; FirstState = state; + Surface?.OnNodesConnected(this, other); } } @@ -1383,6 +1384,7 @@ namespace FlaxEditor.Surface.Archetypes var action = new AddRemoveTransitionAction(this, state); Surface?.Undo.AddAction(action); action.Do(); + Surface?.OnNodesConnected(this, other); } } diff --git a/Source/Editor/Surface/Elements/Box.cs b/Source/Editor/Surface/Elements/Box.cs index 6a8745fa6..271ff0c28 100644 --- a/Source/Editor/Surface/Elements/Box.cs +++ b/Source/Editor/Surface/Elements/Box.cs @@ -110,6 +110,10 @@ namespace FlaxEditor.Surface.Elements Connections.Add(targetBox); targetBox.Connections.Add(this); } + else + { + Surface?.OnNodesDisconnected(this, targetBox); + } targetBox.OnConnectionsChanged(); } @@ -316,6 +320,7 @@ namespace FlaxEditor.Surface.Elements targetBox.Connections.Remove(this); toUpdate.Add(targetBox); targetBox.OnConnectionsChanged(); + Surface?.OnNodesDisconnected(this, targetBox); } Connections.Clear(); OnConnectionsChanged(); @@ -367,6 +372,7 @@ namespace FlaxEditor.Surface.Elements box.ConnectionTick(); OnConnectionsChanged(); box.OnConnectionsChanged(); + Surface?.OnNodesDisconnected(this, box); } /// @@ -393,6 +399,7 @@ namespace FlaxEditor.Surface.Elements box.ConnectionTick(); OnConnectionsChanged(); box.OnConnectionsChanged(); + Surface?.OnNodesConnected(this, box); } /// @@ -572,7 +579,7 @@ namespace FlaxEditor.Surface.Elements if (!IsOutput && HasSingleConnection) { var connectedBox = Connections[0]; - if (Surface.Undo != null) + if (Surface.Undo != null && Surface.Undo.Enabled) { var action = new ConnectBoxesAction((InputBox)this, (OutputBox)connectedBox, false); BreakConnection(connectedBox); @@ -766,16 +773,11 @@ namespace FlaxEditor.Surface.Elements { var start = this; var end = (Box)other; - - // Check if boxes are connected - bool areConnected = start.AreConnected(end); + var areConnected = start.AreConnected(end); // Check if boxes are different or (one of them is disabled and both are disconnected) if (end.IsOutput == start.IsOutput || !((end.Enabled && start.Enabled) || areConnected)) - { - // Back return; - } // Cache Input and Output box (since connection may be made in a different way) InputBox iB; @@ -795,7 +797,7 @@ namespace FlaxEditor.Surface.Elements if (areConnected) { // Break link - if (Surface.Undo != null) + if (Surface.Undo != null && Surface.Undo.Enabled) { var action = new ConnectBoxesAction(iB, oB, false); start.BreakConnection(end); @@ -807,6 +809,7 @@ namespace FlaxEditor.Surface.Elements start.BreakConnection(end); } Surface.MarkAsEdited(); + Surface?.OnNodesDisconnected(this, other); return; } @@ -830,7 +833,7 @@ namespace FlaxEditor.Surface.Elements else { // Connect directly - if (Surface.Undo != null) + if (Surface.Undo != null && Surface.Undo.Enabled) { var action = new ConnectBoxesAction(iB, oB, true); iB.CreateConnection(oB); diff --git a/Source/Editor/Surface/VisjectSurface.cs b/Source/Editor/Surface/VisjectSurface.cs index 52aa37bf4..6a35d6404 100644 --- a/Source/Editor/Surface/VisjectSurface.cs +++ b/Source/Editor/Surface/VisjectSurface.cs @@ -320,6 +320,16 @@ namespace FlaxEditor.Surface /// public event Action NodeBreakpointEdited; + /// + /// Occurs when two nodes gets connected (via UI). + /// + public event Action NodesConnected; + + /// + /// Occurs when two nodes gets disconnected (via UI). + /// + public event Action NodesDisconnected; + /// /// Initializes a new instance of the class. /// @@ -934,6 +944,23 @@ namespace FlaxEditor.Surface NodeDeleted?.Invoke(node); } + /// + /// Called when two nodes gets connected (via UI). + /// + public virtual void OnNodesConnected(IConnectionInstigator a, IConnectionInstigator b) + { + NodesConnected?.Invoke(a, b); + MarkAsEdited(); + } + + /// + /// Called when two nodes gets disconnected (via UI). + /// + public virtual void OnNodesDisconnected(IConnectionInstigator a, IConnectionInstigator b) + { + NodesDisconnected?.Invoke(a, b); + } + /// public override void OnDestroy() {