// Validate connection / prevent loopbacks // If valid, apply // Return result public bool AddConnection( SynthGraphEditorGraphConnection connection ) { if ( ValidateConnection( connection ) ) { DataNode.SetSourceNode( connection.m_from.DataNode, connection.m_toSlot ); return true; } return false; }
public SynthGraphEditorGraphWindow( int windowId, string windowTitle, Rect windowRect ) : base(windowId, windowTitle, windowRect) { m_graphCache = new Dictionary<ISynthGraphNode, NodeGUIBase>(); m_floatingSelection = new Dictionary<ISynthGraphNode, NodeGUIBase>(); NodeGUIBase.OnNodeConnectorSelected += HandleNodeConnectorSelected; m_cursorConnection = new SynthGraphEditorGraphConnection(); m_connectionCache = new List<SynthGraphEditorGraphConnection>(); SetDirty( true ); }
private void CacheConnection( ISynthGraphNode node ) { ISynthGraphNode[] inputs = node.GetSourceNodes(); for( int i = 0; i < inputs.Length; i++ ) { if ( inputs[ i ] != null ) { SynthGraphEditorGraphConnection connection = new SynthGraphEditorGraphConnection(); connection.SetFrom( GetGUIForNode( inputs[ i ] ) ); connection.SetTo( GetGUIForNode( node ), i ); m_connectionCache.Add( connection ); CacheConnection( inputs[ i ] ); } } }
void HandleNodeConnectorSelected(NodeGUIBase node, int connectorIndex, NodeGUIBase.NodeConnectorType connectorType) { switch( connectorType ) { case NodeGUIBase.NodeConnectorType.DATA_IN: m_cursorConnection.SetTo( node, connectorIndex ); break; case NodeGUIBase.NodeConnectorType.DATA_OUT: m_cursorConnection.SetFrom( node ); break; } switch( m_cursorConnection.State ) { case SynthGraphEditorGraphConnection.ConnectionState.NO_CONNECTED: SetRequiresContiniousUpdates( false ); break; case SynthGraphEditorGraphConnection.ConnectionState.CONNECTING: SetRequiresContiniousUpdates( true ); break; case SynthGraphEditorGraphConnection.ConnectionState.CONNECTED: SetRequiresContiniousUpdates( false ); if ( m_cursorConnection.m_to.AddConnection( m_cursorConnection ) ) { SetDirty( true ); } m_cursorConnection = new SynthGraphEditorGraphConnection(); break; } }
private bool ValidateConnection( SynthGraphEditorGraphConnection connection ) { if ( connection.m_from.DataNode == DataNode ) { return false; // Loopback } if ( connection.m_toSlot >= DataNode.GetSourceCount() ) { return false; // Out of input range } return true; }