示例#1
0
        /// <summary>
        /// Applies a connection between between this port and the specified port.
        /// 'CanApplyConnection' has to be checked before to avoid interferences!
        /// </summary>
        public void ApplyConnection(ConnectionPort port, bool silent = false)
        {
            if (port == null)
            {
                return;
            }

            Undo.RecordObjects(new [] { this, port }, "NodeEditor_连接保存");
            if (maxConnectionCount == ConnectionCount.Single && connections.Count > 0)
            {
                // Respect maximum connection count on this port
                RemoveConnection(connections[0], silent);
                connections.Clear();
            }

            connections.Add(port);

            if (port.maxConnectionCount == ConnectionCount.Single && port.connections.Count > 0)
            {
                // Respect maximum connection count on the other port
                port.RemoveConnection(port.connections[0], silent);
                port.connections.Clear();
            }

            port.connections.Add(this);

            if (!silent)
            {
                // Callbacks
                port.body.OnAddConnection(port, this);
                body.OnAddConnection(this, port);
                NodeEditorCallbacks.IssueOnAddConnection(this, port);
            }
        }
示例#2
0
        /// <summary>
        /// Applies a connection between between this port and the specified port.
        /// 'CanApplyConnection' has to be checked before to avoid interferences!
        /// </summary>
        public void ApplyConnection(ConnectionPort port, bool silent = false)
        {
            if (port == null)
            {
                return;
            }

            if (maxConnectionCount == ConnectionCount.Single && connections.Count > 0)
            {             // Respect maximum connection count on this port
                RemoveConnection(connections[0], silent);
                connections.Clear();
            }
            connections.Add(port);

            if (port.maxConnectionCount == ConnectionCount.Single && port.connections.Count > 0)
            {             // Respect maximum connection count on the other port
                port.RemoveConnection(port.connections[0], silent);
                port.connections.Clear();
            }
            port.connections.Add(this);

            if (!silent)
            {             // Callbacks
                port.body.OnAddConnection(port, this);
                body.OnAddConnection(this, port);
                NodeEditorCallbacks.IssueOnAddConnection(this, port);
                NodeEditor.curNodeCanvas.OnNodeChange(direction == Direction.In? port.body : body);
            }
        }
 public static void DeleteConnection(ConnectionPort port1, ConnectionPort port2)
 {
     if (port1 == null || port2 == null)
     {             // Not critical. Happens when undo records are triggered, but it's canvas has been unloaded
         // Debug.LogWarning("Lost reference to Undo SO 'port'!");
         return;
     }
     port1.RemoveConnection(port2, true);
 }
示例#4
0
        /// <summary>
        /// Applies a connection between between this port and the specified port.
        /// 'CanApplyConnection' has to be checked before to avoid interferences!
        /// </summary>
        public void ApplyConnection(ConnectionPort port, bool silent = false)
        {
            if (port == null)
            {
                return;
            }

            if (maxConnectionCount == ConnectionCount.Single && connections.Count > 0)
            {             // Respect maximum connection count on this port
                RemoveConnection(connections[0], silent);
                connections.Clear();
            }
            connections.Add(port);

            if (port.maxConnectionCount == ConnectionCount.Single && port.connections.Count > 0)
            {             // Respect maximum connection count on the other port
                port.RemoveConnection(port.connections[0], silent);
                port.connections.Clear();
            }
            port.connections.Add(this);

#if UNITY_EDITOR
            if (!silent)
            {             // Create Undo record
                          // Important: Copy variables used within anonymous functions within same level (this if block) for correct serialization!
                ConnectionPort port1 = this, port2 = port;
                UndoPro.UndoProManager.RecordOperation(
                    () => NodeEditorUndoActions.CreateConnection(port1, port2),
                    () => NodeEditorUndoActions.DeleteConnection(port1, port2),
                    "Create Connection");
            }
#endif

            if (!silent)
            {             // Callbacks
                port.body.OnAddConnection(port, this);
                body.OnAddConnection(this, port);
                NodeEditorCallbacks.IssueOnAddConnection(this, port);
                body.canvas.OnNodeChange(direction == Direction.In? port.body : body);
            }
        }