Exemplo n.º 1
0
        ///Sets the source node of the connection
        public int SetSourceNode(Node newSource, int index = -1)
        {
            if (sourceNode == newSource)
            {
                return(-1);
            }

            if (graph != null)
            {
                graph.RecordUndo("Set Source");
            }

            //relink
            if (sourceNode != null && sourceNode.outConnections.Contains(this))
            {
                var i = sourceNode.outConnections.IndexOf(this);
                sourceNode.OnChildDisconnected(i);
                sourceNode.outConnections.Remove(this);
            }

            index = index == -1 ? newSource.outConnections.Count : index;
            newSource.outConnections.Insert(index, this);
            newSource.OnChildConnected(index);
            sourceNode = newSource;

#if UNITY_EDITOR
            if (sourceNode != null && targetNode != null)
            {
                targetNode.TrySortConnectionsByPositionX();
            }
#endif

            return(index);
        }
Exemplo n.º 2
0
        ///<summary>Sets the source node of the connection</summary>
        public int SetSourceNode(Node newSource, int index = -1)
        {
            if (sourceNode == newSource)
            {
                return(-1);
            }

            UndoUtility.RecordObject(graph, "Set Source");

            //relink
            if (sourceNode != null && sourceNode.outConnections.Contains(this))
            {
                var i = sourceNode.outConnections.IndexOf(this);
                sourceNode.OnChildDisconnected(i);
                sourceNode.outConnections.Remove(this);
            }

            index = index == -1 ? newSource.outConnections.Count : index;
            newSource.outConnections.Insert(index, this);
            newSource.OnChildConnected(index);
            sourceNode = newSource;

#if UNITY_EDITOR
            if (sourceNode != null && targetNode != null)
            {
                targetNode.TrySortConnectionsByPositionX();
            }
#endif

            OnValidate(index, targetNode != null ? targetNode.inConnections.IndexOf(this) : -1);
            UndoUtility.SetDirty(graph);
            return(index);
        }
Exemplo n.º 3
0
        ///Connect two nodes together to a specific port index of the source node
        public Connection ConnectNodes(Node sourceNode, Node targetNode, int indexToInsert)
        {
            if (targetNode.IsNewConnectionAllowed(sourceNode) == false)
            {
                return(null);
            }

            RecordUndo("New Connection");

            var newConnection = Connection.Create(sourceNode, targetNode, indexToInsert);

            sourceNode.OnChildConnected(indexToInsert);
            targetNode.OnParentConnected(targetNode.inConnections.IndexOf(newConnection));

            UpdateNodeIDs(false);
            return(newConnection);
        }
Exemplo n.º 4
0
        ///Relinks the source node of the connection
        public void SetSource(Node newSource, bool isRelink = true)
        {
                        #if UNITY_EDITOR
            if (!Application.isPlaying && graph != null)
            {
                UnityEditor.Undo.RecordObject(graph, "Set Source");
            }
                        #endif

            if (isRelink)
            {
                var i = sourceNode.outConnections.IndexOf(this);
                sourceNode.OnChildDisconnected(i);
                newSource.OnChildConnected(i);

                sourceNode.outConnections.Remove(this);
            }
            newSource.outConnections.Add(this);

            sourceNode = newSource;
        }
Exemplo n.º 5
0
        ///Relinks the source node of the connection
        public void SetSource(Node newSource, bool isRelink = true)
        {
            if (sourceNode == newSource)
            {
                return;
            }

            if (graph != null)
            {
                graph.RecordUndo("Set Source");
            }

            if (isRelink)
            {
                var i = sourceNode.outConnections.IndexOf(this);
                sourceNode.OnChildDisconnected(i);
                newSource.OnChildConnected(i);
                sourceNode.outConnections.Remove(this);
            }
            newSource.outConnections.Add(this);
            sourceNode = newSource;
        }
Exemplo n.º 6
0
        ///Relinks the source node of the connection
        public void SetSource(Node newSource, bool isRelink = true, int index = -1)
        {
            if (sourceNode == newSource)
            {
                return;
            }

            if (graph != null)
            {
                graph.RecordUndo("Set Source");
            }

            if (isRelink)
            {
                var i = sourceNode.outConnections.IndexOf(this);
                sourceNode.OnChildDisconnected(i);
                newSource.OnChildConnected(i);
                sourceNode.outConnections.Remove(this);
            }

            index = index == -1? newSource.outConnections.Count : index;
            newSource.outConnections.Insert(index, this);
            sourceNode = newSource;
        }
Exemplo n.º 7
0
		///Relinks the source node of the connection
		public void SetSource(Node newSource, bool isRelink = true){
			
			#if UNITY_EDITOR
			if (!Application.isPlaying && graph != null){
				UnityEditor.Undo.RecordObject(graph, "Set Source");
			}
			#endif

			if (isRelink){
				var i = sourceNode.outConnections.IndexOf(this);
				sourceNode.OnChildDisconnected(i);
				newSource.OnChildConnected(i);

				sourceNode.outConnections.Remove(this);
			}
			newSource.outConnections.Add(this);

			sourceNode = newSource;			
		}