public override void Trigger() { for (int i = 0; i < trigger.Length; i++) { trigger[i].Invoke(); } NodePort port = GetOutputPort("output"); if (!port.IsConnected) { Debug.Log("!port.isconnected event"); } if (port == null) { return; } NodePort connection; if (port.ConnectionCount > 1) { int ran = Random.Range(0, port.ConnectionCount); connection = port.GetConnection(ran); } else { connection = port.GetConnection(0); } (connection.node as DialogueBaseNode).Trigger(); }
public void UpdateConnectionTransforms() { if (port.IsInput) { return; } while (connections.Count < port.ConnectionCount) { AddConnection(); } while (connections.Count > port.ConnectionCount) { Destroy(connections[0].gameObject); connections.RemoveAt(0); } // Loop through connections for (int i = 0; i < port.ConnectionCount; i++) { NodePort other = port.GetConnection(i); UGUIMathBaseNode otherNode = graph.GetRuntimeNode(other.node); if (!otherNode) { Debug.LogWarning(other.node.name + " node not found", this); } Transform port2 = otherNode.GetPort(other.fieldName).transform; if (!port2) { Debug.LogWarning(other.fieldName + " not found", this); } connections[i].SetPosition(transform.position, port2.position); } }
public static void DrawOutputs(XNode.Node target, SerializedObject serializedObject) { NodePort outputPort = target.GetOutputPort("output"); serializedObject.FindProperty("outputFoldout").boolValue = EditorGUILayout.Foldout(serializedObject.FindProperty("outputFoldout").boolValue, "Outputs [" + outputPort.ConnectionCount + "]", true); bool outputFoldout = serializedObject.FindProperty("outputFoldout").boolValue; GUIStyle labelStyle = new GUIStyle(EditorStyles.label); GUIStyle buttonStyle = new GUIStyle(EditorStyles.miniButton); labelStyle.wordWrap = true; if (outputFoldout) { for (int i = 0; i < outputPort.ConnectionCount; i++) { EditorGUILayout.BeginHorizontal(); NodePort outputConnectionPort = outputPort.GetConnection(i); Node outputConnectionNode = outputPort.GetConnection(i).node; if (outputConnectionNode is State) { string label = outputConnectionNode.name; label = label.Replace("\n", ""); label = label.Substring(0, Mathf.Min(32, label.Length)); EditorGUILayout.LabelField(string.Format("[{0}] {1}", "Answer", label, labelStyle)); } if (GUILayout.Button("^", GUILayout.MaxHeight(20), GUILayout.MaxWidth(20))) { if (i <= 0) { return; } outputPort.SwitchConnections(i, i - 1); } if (GUILayout.Button("v", GUILayout.MaxHeight(20), GUILayout.MaxWidth(20))) { if (i >= outputPort.ConnectionCount - 1) { return; } outputPort.SwitchConnections(i, i + 1); } EditorGUILayout.EndHorizontal(); } } }
public bool GetNextNodeFromCurrent(NodeBase current, out NodeBase nextNode) { if (current.ConditionsAreValid()) { NodePort port = current.GetOutputPort("output"); for (int i = 0; i < port.ConnectionCount; i++) { NodePort connection = port.GetConnection(i); NodeBase connectedNode = connection.node as NodeBase; if (connectedNode != null) { nextNode = connectedNode; return(true); } } nextNode = current; return(false); } else { nextNode = current; return(false); } }
private bool Valid(NodePort port, out BaseFlow flowNode) { foreach (var item in port.GetConnections()) { if (item.node != null && item.node is IValidatable validatable) { if (validatable.Valid) { NodePort outPort = item.node.GetOutputPort("Out"); if (outPort.IsConnected) { NodePort connection = outPort.GetConnection(0); if (connection.node is BaseFlow) { flowNode = connection.node as BaseFlow; return(true); } else { Debug.LogError("Attached node is not a FlowNode"); } } else { Debug.LogError("Rule 'Out' not connected to FlowNode"); } } } } flowNode = null; return(false); }
public void AnswerQuestion(int index) { NodePort port = null; if (answers.Count == 0) { port = GetOutputPort("output"); } else { if (answers.Count <= index) { return; } port = GetOutputPort("answers " + index); } if (port == null) { return; } for (int i = 0; i < port.ConnectionCount; i++) { NodePort connection = port.GetConnection(i); (connection.node as DialogueBaseNode).Trigger(); } }
public void AnswerQuestion(int index) { NodePort port = null; if (answers.Count == 0) { port = GetOutputPort("output"); } else { if (answers.Count <= index) { return; } port = GetOutputPort("answers " + index); } if (port == null) { return; } bool flag = false; for (int i = 0; i < port.ConnectionCount; i++) { NodePort connection = port.GetConnection(i); (connection.node as DialogueBaseNode).Trigger(); flag = true; } if (!flag) { (graph as DialogueGraph).current = null; } }
public void Exit() { if (active != this) { Debug.LogWarning("Exiting from a non-active node. Aborted."); return; } active = false; OnExit(); NodePort exitPort = GetOutputPort("exit"); if (exitPort.IsConnected) { for (int i = 0; i < exitPort.ConnectionCount; i++) { StateNodeBase nextNode = exitPort.GetConnection(i).node as StateNodeBase; if (nextNode != null) { nextNode.Enter(); } } } }
private void GetAnswersRecursively(ref List <Answer> validAnswers, ref List <Group> validGroups, NodePort port) { for (int i = 0; i < port.ConnectionCount; i++) { NodePort connection = port.GetConnection(i); if (connection.node is Answer) { Answer answer = (connection.node as Answer); if (answer.ConditionsAreValid()) { validAnswers.Add(answer as Answer); } } else if (connection.node is Group) { Group group = (connection.node as Group); if (group.ConditionsAreValid()) { validGroups.Add(connection.node as Group); NodePort groupPort = group.GetOutputPort("output"); GetAnswersRecursively(ref validAnswers, ref validGroups, groupPort); } } } }
public void DialogueReply(int i) { NodePort port = null; if (answers.Count == 0) { port = GetOutputPort("output"); } else { if (answers.Count <= i) { return; } port = GetOutputPort(answers[i].portName); } if (port == null) { return; } for (int h = 0; h < port.ConnectionCount; h++) { NodePort connection = port.GetConnection(h); (connection.node as DialogueNode).setCurrentNode(); } }
protected override void CheckConditions() { // Store the active state because we want to evaluate all conditions, not just the first one bool activeCache = active; for (int i = 0; i < conditions.Length; i++) { // We evaluate first because we want the lastState in the condition to update regardless of 'active' if (conditions[i].Evaluate(value) && activeCache) { NodePort triggerPort = GetOutputPort("conditions " + i); if (triggerPort.IsConnected) { for (int k = 0; k < triggerPort.ConnectionCount; k++) { StateNodeBase nextNode = triggerPort.GetConnection(k).node as StateNodeBase; active = false; if (nextNode != null) { nextNode.Enter(); } } } } } }
protected bool DoDisConnectToList <T>(NodePort port, ref List <T> condList, NodePort.IO dir = NodePort.IO.Input) where T : Node { if (port.direction != dir) { return(false); } if (port.ValueType != typeof(List <T>)) { return(false); } if (condList != null) { condList.Clear(); } else { condList = new List <T> (); } for (int i = 0; i < port.ConnectionCount; ++i) { T cc = port.GetConnection(i).node as T; if (cc != null) { condList.Add(cc); } } return(true); }
protected void Forward(GameObject obj) { NodePort target = GetOutputPort("target"); int c = target.ConnectionCount; for (int i = 0; i < c; i++) { NodePort port = target.GetConnection(i); if (port == null) { continue; } StyleNode styleNode = port.node as StyleNode; if (styleNode == null) { continue; } styleNode.Apply(obj); } }
public override BTResult Execute() { NodePort inPort = GetPort("inResult"); if (inPort != null && inPort.GetConnections().Count != 0) { NodePort connection = inPort.GetConnection(0); if (connection != null) { BTResult result = (BTResult)connection.GetOutputValue(); if (result == BTResult.SUCCESS) { BehaviourTreeRuntimeData.RemoveRunningNode(context, this); } else if (result == BTResult.RUNNING) { return(BTResult.RUNNING); } else { BehaviourTreeRuntimeData.AddRunningNode(context, this); return(BTResult.RUNNING); } } } return(BTResult.SUCCESS); }
protected override void RemoveAt(TList collection, int index) { NodePort indexPort = GetNodePort(index); if (indexPort == null) { Debug.LogWarning($"No port found at index {index}"); } lastRemovedConnections.Clear(); if (indexPort != null) { lastRemovedConnections.AddRange(indexPort.GetConnections()); // Clear the removed ports connections indexPort.ClearConnections(); } // Cache the last port because I'm about to remove it NodePort lastPort = GetNodePort(ChildCount - 1); // Move following connections one step up to replace the missing connection for (int k = index + 1; k < ChildCount; k++) { NodePort kPort = GetNodePort(k); if (kPort == null) { continue; } NodePort k1Port = GetNodePort(k - 1); // Port k - 1 missing means I need to actually rename a port instead // Create k -1, add all the correct connections ... leave K alone because he existed if (k1Port == null) { k1Port = ReplaceNodeForRemove(k - 1); } for (int j = 0; j < kPort.ConnectionCount; j++) { NodePort other = kPort.GetConnection(j); kPort.Disconnect(other); k1Port.Connect(other); } } // Remove the last dynamic port, to avoid messing up the indexing if (lastPort != null) { lastPort.node.RemoveDynamicPort(lastPort); } base.RemoveAt(collection, index); this.ForceUpdateChildCount(); }
protected override void InsertAt(TList collection, int index, object value) { int newChildCount = this.ChildCount + 1; int nextId = this.ChildCount; // Remove happens before insert and we lose all the connections // Add a new port at the end if (nodePortInfo.Port.IsInput) { nodePortInfo.Node.AddDynamicInput(typeof(TElement), nodePortInfo.ConnectionType, nodePortInfo.TypeConstraint, string.Format("{0} {1}", nodePortInfo.BaseFieldName, nextId)); } else { nodePortInfo.Node.AddDynamicOutput(typeof(TElement), nodePortInfo.ConnectionType, nodePortInfo.TypeConstraint, string.Format("{0} {1}", nodePortInfo.BaseFieldName, nextId)); } // Move everything down to make space - if something is missing just pretend we moved it? for (int k = newChildCount - 1; k > index; --k) { NodePort k1Port = GetNodePort(k - 1); if (k1Port == null) // It is missing, I have nothing to move { continue; } for (int j = 0; j < k1Port.ConnectionCount; j++) { NodePort other = k1Port.GetConnection(j); k1Port.Disconnect(other); NodePort kPort = GetNodePort(k); if (kPort == null) { continue; } kPort.Connect(other); } } // Let's just re-add connections to this node that were probably his foreach (var c in lastRemovedConnections) { NodePort indexPort = GetNodePort(index); if (indexPort != null) { indexPort.Connect(c); } } lastRemovedConnections.Clear(); //if ( noDataResolver == null ) base.InsertAt(collection, index, value); this.ForceUpdateChildCount(); }
public void ExecuteNext(NodePort nextPort, GameObject context) { for (int i = 0; i < nextPort.ConnectionCount; i++) { NodePort connection = nextPort.GetConnection(i); ExecutableNode next = (ExecutableNode)connection.node; next.Execute(context); } }
public void AnswerQuestion(int index) { NodePort port = null; if (answers.Count == 0) { port = GetOutputPort("output"); } else { if (answers.Count <= index) { return; } port = GetOutputPort("answers " + index); } if (!port.IsConnected) { Debug.Log("isn't connected"); } if (port == null) { return; } /*for (int i = 0; i < port.ConnectionCount; i++) { * NodePort connection = port.GetConnection(i); * (connection.node as DialogueBaseNode).Trigger(); * } */ NodePort connection; if (port.ConnectionCount > 1) { int ran = Random.Range(0, port.ConnectionCount); connection = port.GetConnection(ran); } else { connection = port.GetConnection(0); } (connection.node as DialogueBaseNode).Trigger(); }
public new void ExecuteNext(NodePort nextPort, GameObject context) { ((InteractionGraph)graph).activeNodes.Remove(this); for (int i = 0; i < nextPort.ConnectionCount; i++) { NodePort connection = nextPort.GetConnection(i); ExecutableNode next = (ExecutableNode)connection.node; ((InteractionGraph)graph).activeNodes.Add(next); next.Execute(context); } }
/// <summary> /// Chequea si hay una wave siguiente /// </summary> /// <param name="node">Nodo a chequear</param> /// <returns>Si hay una wave mas</returns> public bool NextWaveIsConnected(WaveNode node) { if (node.GetOutputPort("nextWave").IsConnected) { NodePort output = node.GetOutputPort("nextWave"); if (output.GetConnection(0).node.GetOutputPort("nextWave").GetConnections().Count > 0) { return(true); } } return(false); }
void ExecuteExitNode() { NodePort inPort = GetPort("onNodeExit"); if (inPort != null && inPort.GetConnections().Count != 0) { NodePort connection = inPort.GetConnection(0); if (connection != null) { connection.GetOutputValue(); } } }
public override object GetValue(GameObject context) { NodePort inputPort = GetInputPort("input"); int result = 0; for (int i = 0; i < inputPort.ConnectionCount; i++) { if ((bool)((ProcessorNode)inputPort.GetConnection(i).node).GetValue(context) == CountTrues) { result++; } } return(result); }
/** * The coroutine that triggers an output with a delay */ private IEnumerator TriggerOutputWithDelay(int index) { // Retrieve the corresponding output NodePort NodePort port = GetOutputPort("delays " + index); // Wait for the value for the value of the delay in seconds yield return(new WaitForSeconds(delays[index])); // Trigger each Node connected to the NodePort for (int j = 0; j < port.ConnectionCount; j++) { NodePort connection = port.GetConnection(j); ((DialogueNode)connection.node).Trigger(); } }
public IEnumerable <StateNodeBase> GetPreviousNodes() { NodePort enterPort = GetInputPort("enter"); int connectionCount = enterPort.ConnectionCount; NodePort[] otherPorts = new NodePort[connectionCount]; for (int i = 0; i < connectionCount; i++) { NodePort otherPort = enterPort.GetConnection(i); if (otherPort != null) { yield return(otherPort.node as StateNodeBase); } } }
public override object GetValue(GameObject context) { NodePort inputPort = GetInputPort("input"); for (int i = 0; i < inputPort.ConnectionCount; i++) { if (!(bool)((ProcessorNode)inputPort.GetConnection(i).node).GetValue(context)) { output = false; return(output); } } output = true; return(output); }
public override void Trigger() { NodePort port = GetOutputPort("output"); if (port == null) { return; } for (int i = 0; i < port.ConnectionCount; i++) { NodePort connection = port.GetConnection(i); ((DialogueNode)connection.node).Trigger(); } }
public void TryToComplete() { NodePort port = null; port = GetOutputPort("output"); if (port == null) { return; } for (int i = 0; i < port.ConnectionCount; i++) { NodePort connection = port.GetConnection(i); (connection.node as TaskBaseNode)?.Trigger(); } }
private void RefreshParent() { NodePort parentPort = GetPort(nameof(Parent)); if (parentPort != null && parentPort.ConnectionCount > 0) { var parentConnection = parentPort.GetConnection(0); if (parentConnection != null) { Parent = (BtNode)parentConnection.node; return; } } Parent = null; }
private void RefreshChild() { NodePort childPort = GetPort(nameof(child)); if (childPort != null && childPort.ConnectionCount > 0) { var connection = childPort.GetConnection(0); if (connection != null) { child = (BtNode)connection.node; return; } } child = null; }
public void AnswerQuestion(int index) { NodePort port = GetOutputPort("output"); bool flag = false; for (int i = 0; i < port.ConnectionCount; i++) { NodePort connection = port.GetConnection(i); (connection.node as DialogueBaseNode).Trigger(); flag = true; } if (!flag) { (graph as DialogueGraph).current = null; } }