Ejemplo n.º 1
0
		///Create a new Connection. Use this for constructor
		public static Connection Create(Node source, Node target, int sourceIndex){
			
			if (source == null || target == null){
				Debug.LogError("Can't Create a Connection without providing Source and Target Nodes");
				return null;
			}

			if (source is MissingNode){
				Debug.LogError("Creating new Connections from a 'MissingNode' is not allowed. Please resolve the MissingNode node first");
				return null;
			}

			var newConnection = (Connection)System.Activator.CreateInstance(source.outConnectionType);

			#if UNITY_EDITOR
			if (!Application.isPlaying){
				UnityEditor.Undo.RecordObject(source.graph, "Create Connection");
			}
			#endif

			newConnection.sourceNode = source;
			newConnection.targetNode = target;
			source.outConnections.Insert(sourceIndex, newConnection);
			target.inConnections.Add(newConnection);
			newConnection.OnValidate(sourceIndex, target.inConnections.IndexOf(newConnection));
			return newConnection;
		}
Ejemplo n.º 2
0
		///Duplicate the connection providing a new source and target
		public Connection Duplicate(Node newSource, Node newTarget){

			if (newSource == null || newTarget == null){
				Debug.LogError("Can't Duplicate a Connection without providing NewSource and NewTarget Nodes");
				return null;
			}
			
			//deep clone
			var newConnection = JSONSerializer.Deserialize<Connection>(  JSONSerializer.Serialize(typeof(Connection), this)  );

			#if UNITY_EDITOR
			if (!Application.isPlaying){
				UnityEditor.Undo.RecordObject(newSource.graph, "Duplicate Connection");
			}
			#endif

			newConnection.SetSource(newSource, false);
			newConnection.SetTarget(newTarget, false);

			var assignable = this as ITaskAssignable;
			if (assignable != null && assignable.task != null)
				(newConnection as ITaskAssignable).task = assignable.task.Duplicate(newSource.graph);

			newConnection.OnValidate(newSource.outConnections.IndexOf(newConnection), newTarget.inConnections.IndexOf(newConnection));
			return newConnection;
		}
Ejemplo n.º 3
0
		///Relinks the target node of the connection
		public void SetTarget(Node newTarget, bool isRelink = true){
			
			#if UNITY_EDITOR
			if (!Application.isPlaying){
				UnityEditor.Undo.RecordObject(graph, "Set Target");
			}
			#endif

			if (isRelink){
				var i = targetNode.inConnections.IndexOf(this);
				targetNode.OnParentDisconnected(i);
				newTarget.OnParentConnected(i);

				targetNode.inConnections.Remove(this);
			}
			newTarget.inConnections.Add(this);

			targetNode = newTarget;
		}
Ejemplo 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;			
		}
 public override void OnGraphStarted()
 {
     targetNode = graph.GetNodeWithTag<Node>(targetNodeTag);
 }
        ///Relinks the target node of the connection
        public void SetTarget(Node newTarget)
        {
            #if UNITY_EDITOR
            if (!Application.isPlaying){
                UnityEditor.Undo.RecordObject(graph, "Relink Target");
            }
            #endif

            newTarget.inConnections.Add(this);
            targetNode.inConnections.Remove(this);
            targetNode = newTarget;
        }
        ///Relinks the source node of the connection
        public void SetSource(Node newSource)
        {
            #if UNITY_EDITOR
            if (!Application.isPlaying && graph != null){
                UnityEditor.Undo.RecordObject(graph, "Relink Target");
            }
            #endif

            newSource.outConnections.Add(this);
            sourceNode.outConnections.Remove(this);
            sourceNode = newSource;
        }
Ejemplo n.º 8
0
		///Returns if a new connection should be allowed with the source node.
		public bool IsNewConnectionAllowed(Node sourceNode){
			
			if (this == sourceNode){
				Debug.LogWarning("Node can't connect to itself");
				return false;
			}

			if (sourceNode.outConnections.Count >= sourceNode.maxOutConnections && sourceNode.maxOutConnections != -1){
				Debug.LogWarning("Source node can have no more out connections.");
				return false;
			}

			if (this == graph.primeNode && maxInConnections == 1){
				Debug.LogWarning("Target node can have no more connections");
				return false;
			}

			if (maxInConnections <= inConnections.Count && maxInConnections != -1){
				Debug.LogWarning("Target node can have no more connections");
				return false;
			}

			return true;
		}