Esempio n. 1
0
        /// <summary> Swap connections with another node </summary>
        public void SwapConnections(NodePort targetPort)
        {
            int aConnectionCount = connections.Count;
            int bConnectionCount = targetPort.connections.Count;

            List <NodePort> portConnections       = new List <NodePort>();
            List <NodePort> targetPortConnections = new List <NodePort>();

            // Cache port connections
            for (int i = 0; i < aConnectionCount; i++)
            {
                portConnections.Add(connections[i].Port);
            }

            // Cache target port connections
            for (int i = 0; i < bConnectionCount; i++)
            {
                targetPortConnections.Add(targetPort.connections[i].Port);
            }

            ClearConnections();
            targetPort.ClearConnections();

            // Add port connections to targetPort
            for (int i = 0; i < portConnections.Count; i++)
            {
                targetPort.Connect(portConnections[i]);
            }

            // Add target port connections to this one
            for (int i = 0; i < targetPortConnections.Count; i++)
            {
                Connect(targetPortConnections[i]);
            }
        }
Esempio n. 2
0
        /// <summary> Show right-click context menu for hovered port </summary>
        void ShowPortContextMenu(XNode.NodePort hoveredPort)
        {
            GenericMenu contextMenu = new GenericMenu();

            contextMenu.AddItem(new GUIContent("Clear Connections"), false, () => hoveredPort.ClearConnections());
            contextMenu.DropDown(new Rect(Event.current.mousePosition, Vector2.zero));
            if (NodeEditorPreferences.GetSettings().autoSave)
            {
                AssetDatabase.SaveAssets();
            }
        }
Esempio n. 3
0
        public bool RemoveInstancePort(string fieldName)
        {
            NodePort port = GetPort(fieldName);

            if (port == null || port.IsStatic)
            {
                return(false);
            }
            port.ClearConnections();
            ports.Remove(fieldName);
            return(true);
        }
Esempio n. 4
0
 /// <summary> Remove an instance port from the node </summary>
 public void RemoveInstancePort(NodePort port)
 {
     if (port == null)
     {
         throw new ArgumentNullException("port");
     }
     else if (port.IsStatic)
     {
         throw new ArgumentException("cannot remove static port");
     }
     port.ClearConnections();
     ports.Remove(port.fieldName);
 }
Esempio n. 5
0
        /// <summary> Connect this <see cref="NodePort"/> to another </summary>
        /// <param name="port">The <see cref="NodePort"/> to connect to</param>
        public void Connect(NodePort port)
        {
            if (connections == null)
            {
                connections = new List <PortConnection>();
            }
            if (port == null)
            {
                Debug.LogWarning("Cannot connect to null port"); return;
            }
            if (port == this)
            {
                Debug.LogWarning("Cannot connect port to self."); return;
            }
            if (IsConnectedTo(port))
            {
                Debug.LogWarning("Port already connected. "); return;
            }
            if (direction == port.direction)
            {
                Debug.LogWarning("Cannot connect two " + (direction == IO.Input ? "input" : "output") + " connections"); return;
            }
#if UNITY_EDITOR
            UnityEditor.Undo.RecordObject(node, "Connect Port");
            UnityEditor.Undo.RecordObject(port.node, "Connect Port");
#endif
            if (port.connectionType == Node.ConnectionType.Override && port.ConnectionCount != 0)
            {
                port.ClearConnections();
            }
            if (connectionType == Node.ConnectionType.Override && ConnectionCount != 0)
            {
                ClearConnections();
            }
            connections.Add(new PortConnection(port));
            if (port.connections == null)
            {
                port.connections = new List <PortConnection>();
            }
            if (!port.IsConnectedTo(this))
            {
                port.connections.Add(new PortConnection(this));
            }

#if UNITY_EDITOR
            UnityEditor.EditorUtility.SetDirty(node);
            UnityEditor.EditorUtility.SetDirty(port.node);
#endif
            node.OnCreateConnection(this, port);
            port.node.OnCreateConnection(this, port);
        }
Esempio n. 6
0
        /// <summary> Show right-click context menu for hovered port </summary>
        void ShowPortContextMenu(XNode.NodePort hoveredPort)
        {
            GenericMenu contextMenu = new GenericMenu();

            foreach (var port in hoveredPort.GetConnections())
            {
                var name  = port.node.name;
                var index = hoveredPort.GetConnectionIndex(port);
                contextMenu.AddItem(new GUIContent($"Disconnect({name})"), false, () => hoveredPort.Disconnect(index));
            }
            contextMenu.AddItem(new GUIContent("Clear Connections"), false, () => hoveredPort.ClearConnections());
            contextMenu.DropDown(new Rect(Event.current.mousePosition, Vector2.zero));
            if (NodeEditorPreferences.GetSettings().autoSave)
            {
                AssetDatabase.SaveAssets();
            }
        }
Esempio n. 7
0
        /// <summary> Connect this <see cref="NodePort"/> to another </summary>
        /// <param name="port">The <see cref="NodePort"/> to connect to</param>
        public void Connect(NodePort port)
        {
            if (connections == null)
            {
                connections = new List <PortConnection>();
            }
            if (port == null)
            {
                Debug.LogWarning("Cannot connect to null port"); return;
            }
            if (port == this)
            {
                Debug.LogWarning("Cannot connect port to self."); return;
            }
            if (IsConnectedTo(port))
            {
                Debug.LogWarning("Port already connected. "); return;
            }
            if (direction == port.direction)
            {
                Debug.LogWarning("Cannot connect two " + (direction == IO.Input ? "input" : "output") + " connections"); return;
            }
            if (port.connectionType == Node.ConnectionType.Override && port.ConnectionCount != 0)
            {
                port.ClearConnections();
            }
            if (connectionType == Node.ConnectionType.Override && ConnectionCount != 0)
            {
                ClearConnections();
            }
            connections.Add(new PortConnection(port));
            if (port.connections == null)
            {
                port.connections = new List <PortConnection>();
            }
            if (!port.IsConnectedTo(this))
            {
                port.connections.Add(new PortConnection(this));
            }
            NodePort output = IsOutput ? this : port;
            NodePort input  = IsOutput ? port : this;

            node.OnCreateConnection(output, input);
            port.node.OnCreateConnection(output, input);
        }