protected void SetFieldValue(NodePort port) { var spaceIndex = port.fieldName.IndexOf(" "); var field = GetType().GetField(port.fieldName.Contains(" ") ? port.fieldName.Substring(0, spaceIndex) : port.fieldName, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance); if (field.FieldType.IsArray) { if (port.IsInput) { var result = port.GetConnections().Select(nodePort => nodePort.node).ToArray(); Array fieldValue = (Array)field.GetValue(this); if (!fieldValue.Length.Equals(result.Length)) { Resize(ref fieldValue, result.Length); } Array.Copy(result, fieldValue, result.Length); field.SetValue(this, fieldValue); } else { Array fieldValue = (Array)field.GetValue(this); if (fieldValue.GetType().GetElementType().IsAssignableFrom(port.ValueType.GetElementType())) { var result = port.GetConnections().Select(nodePort => nodePort.node).FirstOrDefault(); var portIndex = int.Parse(port.fieldName.Substring(spaceIndex)); var portsCount = port.node.Ports.Count(nodePort => nodePort.fieldName.StartsWith(field.Name)) - 1; if (!fieldValue.Length.Equals(portsCount)) { Resize(ref fieldValue, portsCount); } fieldValue.SetValue(result, portIndex); field.SetValue(this, fieldValue); } } } else { var result = port.GetConnections().Select(nodePort => nodePort.node).FirstOrDefault(); field.SetValue(this, result); } }
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 override BTResult Execute() { NodePort inPort = GetPort("inResults"); if (inPort != null) { List <NodePort> connections = inPort.GetConnections(); foreach (NodePort port in connections) // Goes through each connected node until one returns failure { BTResult result = (BTResult)port.GetOutputValue(); if (result == BTResult.FAILURE) { return(BTResult.FAILURE); } if (result == BTResult.RUNNING) { return(BTResult.RUNNING); } } return(BTResult.SUCCESS); } else { return(BTResult.FAILURE); } }
public override object GetValue(GameObject context) { NodePort firstPort = GetInputPort("value"); if (operation == Operation.AbsoluteValue) { float val = firstPort.ConnectionCount == 0 ? value : float.Parse(((ProcessorNode)firstPort.GetConnection(0).node).GetValue(context).ToString()); return(Mathf.Abs(val)); } else { List <NodePort> ports = firstPort.GetConnections(); List <float> vals = new List <float>(); foreach (NodePort port in ports) { vals.Add(float.Parse(((ProcessorNode)port.node).GetValue(context).ToString())); } switch (operation) { case Operation.Min: return(vals.Min()); case Operation.Max: return(vals.Max()); case Operation.Sum: return(vals.Sum()); default: return(false); } } }
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); }
public void PlayerInput() { if (inCutscene) { if (Input.GetButtonDown("Submit")) { SFXManager.Main.StopAll(); if (CGWaitingForInput) { if (currentCGNode.GetOutputPort("output").IsConnected) { dialoguePanel.SetActive(true); _charactersInScene.SetActive(true); NodePort _port = currentCGNode.GetOutputPort("output"); GetNodeFunction(_port.GetConnections()); CGWaitingForInput = false; } } else {//when not relying on CG input and simply waiting on dialogue if (currentDialogue.GetOutputPort("output").IsConnected) { NodePort _port = currentDialogue.GetOutputPort("output"); GetNodeFunction(_port.GetConnections()); //GetConnections returns the list of ports connected to _port } } } } }
private bool GetDecisionResult(FSMBehaviour fsm) { if (intpuPort.ConnectionCount <= 0) { return(false); } bool result = false; List <NodePort> connectionPorts = intpuPort.GetConnections(); List <NodeBase_Decision> list = new List <NodeBase_Decision>(); foreach (NodePort p in connectionPorts) { list.Add((NodeBase_Decision)p.node); } result = !list.Exists(r => r.Execute(fsm) == false); //Clear garbage connectionPorts.Clear(); list.Clear(); connectionPorts = null; list = null; return(result); }
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 void Update(NodePort port) { foreach (var item in port.GetConnections()) { if (item.node != null && item.node is IUpdatable updatable) { updatable.Update(); } } }
protected void Stop(NodePort port) { foreach (var item in port.GetConnections()) { if (item.node != null && item.node is IStoppable stoppable) { stoppable.Stop(); } } }
public void OnUse() { SFXManager.Main.Play(VoiceClip, 0.1f); ClipGroup group = new ClipGroup(); NodePort _port = GetOutputPort("output"); if (_port.IsConnected) { CutsceneManager.Instance.GetNodeFunction(_port.GetConnections()); } }
IEnumerator WaitToAdvance(WaitFor _waitFor) { yield return(new WaitForSeconds(_waitFor.TimeToPause)); NodePort _port = _waitFor.GetOutputPort("output"); if (_port.IsConnected) { GetNodeFunction(_port.GetConnections()); } }
/// <summary> /// Chequea si la wave tiene enemigos ??????????????????????????????????????????????? /// </summary> /// <param name="node">Nodo a chequear</param> /// <returns>Si tiene o no enemigos</returns> public bool WaveHaveEnemies(WaveNode node) { if (node.GetOutputPort("enemies").IsConnected) { NodePort output = node.GetOutputPort("enemies"); if (output.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(); } } }
List <NodeBase_Decision> GetAllInputDecisions() { NodePort inputPort = GetInputPort("inputDecisions"); List <NodePort> connectionPorts = inputPort.GetConnections(); List <NodeBase_Decision> result = new List <NodeBase_Decision>(); foreach (NodePort p in connectionPorts) { result.Add((NodeBase_Decision)p.node); } return(result); }
protected void BuildChildConnections(NodePort thisPort) { TreeCompositeNode compositeNode = thisTreeNode as TreeCompositeNode; Debug.Assert(compositeNode != null, nameof(compositeNode) + " != null"); var connections = thisPort.GetConnections(); List <TreeBaseNode> treeNodes = new List <TreeBaseNode>(); foreach (var connector in connections) { treeNodes.Add(((BaseNode)connector.node).thisTreeNode); } compositeNode.SetChildren(treeNodes); }
public void PlayCutscene(Cutscene cutscene) { inCutscene = true; CutsceneRootNode _rootNode = cutscene.GetRootNode(); NodePort _port = _rootNode.GetOutputPort("beginScene"); if (_port.IsConnected) { GetNodeFunction(_port.GetConnections()); } else { Debug.Log("No root node"); } }
public override ConversationNode GetNext() { NodePort outPort = GetOutputPort("next"); List <NodePort> nextOptions = outPort.GetConnections(); for (int i = 0; i < nextOptions.Count; ++i) { ConversationNode nextNode = nextOptions[i].node as ConversationNode; if (nextNode.isRequirementMet) { return(nextNode); } } return(null); }
public static void CallActionsOnPort(NodePort exitPort) { var nextConnections = exitPort.GetConnections(); for (int i = 0; i < nextConnections.Count; i++) { var currentConnection = nextConnections[i].node; ActionNode actionNode = currentConnection as ActionNode; if (actionNode) { actionNode.Action(); } } }
private void RefreshChildren() { children.Clear(); NodePort port = GetPort(nameof(children)); if (port == null) { return; } List <NodePort> connections = port.GetConnections(); foreach (var connection in connections) { children.Add((BtNode)connection.node); } }
public static List <NarrativeNode> GetNextNode(this NarrativeNode currentNode, string fieldName) { NodePort exitPort = currentNode.GetOutputPort(fieldName); if (!exitPort.IsConnected) { Debug.LogWarning("Node isn't connected"); return(null); } List <NarrativeNode> nodes = new List <NarrativeNode>(); var connections = exitPort.GetConnections(); for (int i = 0; i < connections.Count; i++) { nodes.Add(connections[i].node as NarrativeNode); } return(nodes); }
/// <summary> /// Returns the list of all nodes connected /// </summary> /// <param name="node"></param> /// <param name="fieldName"></param> /// <returns></returns> public static List <Node> GetInputNodesConnected(this Node node, string fieldName) { // Access node port NodePort port = node.GetPort(fieldName); // If we have connections... if (port != null && port.IsConnected) { var portsConnected = port.GetConnections().ToList(); List <Node> nodesConnected = new List <Node>(); foreach (var connection in portsConnected) { nodesConnected.Add(connection.node); } // Return the nodes from all the connections return(nodesConnected); } // If we don't have any connections, we return null else { return(null); } }
public void GetNodeFunction(List <NodePort> _ports) { //cannot find a way to use a switch, so we'll have to stick with a bunch of if statements :notlikethis: foreach (NodePort _nodePort in _ports) { XNode.Node _node = _nodePort.node; if (_node.GetType() == typeof(DialogueNode)) { dialoguePanel.SetActive(true); currentDialogue = _node as DialogueNode; ShowDialogue(currentDialogue); return; //do NOT grab the node after this, and wait for the player to advance the dialogue } if (_node.GetType() == typeof(VoiceClipNode)) { VoiceClipNode voiceClipNode = _node as VoiceClipNode; voiceClipNode.OnUse(); return; } if (_node.GetType() == typeof(EndSceneNode)) { EndCutscene(); return; } else if (_node.GetType() == typeof(EndBattleSceneNode)) { EndCutscene(); BattleManager BM = GameObject.Find("BattleManager").GetComponent <BattleManager>(); BM.EnableUI(); BM.StartActor(); //Move Battle UI Back In? return; } if (_node is MovementNode movementNode) { movementNode.CharacterMovement(); } if (_node.GetType() == typeof(CloseDialogue)) { dialoguePanel.SetActive(false); speakerPanel.SetActive(false); } if (_node.GetType() == typeof(CG)) { CG scopedCGNode = _node as CG; showCG(_node as CG); if (scopedCGNode.waitForInput) { currentCGNode = scopedCGNode; dialoguePanel.gameObject.SetActive(false); _charactersInScene.SetActive(false); CGWaitingForInput = true; return; } } if (_node.GetType() == typeof(SetSpriteNode)) { SetImage(_node as SetSpriteNode); } if (_node.GetType() == typeof(CGHide)) { _cgGraphic.enabled = false; } if (_node.GetType() == typeof(WaitFor)) { WaitFor _waitForNode = _node as WaitFor; StartCoroutine(WaitToAdvance(_waitForNode)); //do not get next node automatically return; } if (_node.GetType() == typeof(Choices)) { ChoicePanel.SetActive(true); nodeOptions = new List <Node>(); int listIndex = 0; Choices _choiceNode = _node as Choices; NodePort _choicePort = _choiceNode.GetOutputPort("output"); List <NodePort> _nodePorts = _choicePort.GetConnections(); foreach (NodePort _NP in _nodePorts) { nodeOptions.Add(_NP.node); Button _newOption = Instantiate(choiceButton) as Button; _newOption.transform.SetParent(ChoicePanel.transform); listIndex++;//on this button it where on the list it is, using this //ChoiceOptionHolder _holder = _newOption.GetComponent<ChoiceOptionHolder>(); OptionNode optionNode = _NP.node as OptionNode; _newOption.GetComponentInChildren <Text>().text = optionNode.optionText; _newOption.GetComponent <ChoiceOptionHolder>().node = _NP.node; // _holder.node = _NP.node; // _holder.indexOfOptions = listIndex; } return; //do not load next node, since we want the player input to decide the branch to go down } if (_node.GetType() == typeof(TimelineNode)) { TimelineNode timelineNode = _node as TimelineNode; timelineNode.PlayTimeLine(); } //get next node(s) NodePort _port = _node.GetOutputPort("output"); if (_port.IsConnected) { GetNodeFunction(_port.GetConnections()); } } }
public void NextDialogue() { // get a reference to the graph Conversation conversation = graph as Conversation; // Make sure we're actually the current node if (conversation.current != this) { Debug.LogWarning("Node isn't active"); } // Get exit port NodePort exitPort = GetOutputPort("exit"); DialogueNode nextDialogue = null; Conversation.CallActionsOnPort(exitPort); var nextConnections = exitPort.GetConnections(); for (int i = 0; i < nextConnections.Count; i++) { var currentConnection = nextConnections[i].node; // otherwise, get the exit node DialogueNode dialogueNode = currentConnection as DialogueNode; LogicNode logicNode = currentConnection as LogicNode; if (dialogueNode) { if (nextDialogue != null) { Debug.LogWarning("Multiple dialogues connected to this exit."); } // and tell it to set itself to current nextDialogue = dialogueNode; } if (logicNode) { if (nextDialogue != null) { Debug.LogWarning("Multiple dialogues connected to this exit."); } nextDialogue = logicNode.RecurseToDialogue(); } } if (nextDialogue) { nextDialogue.OnEnter(); } else { Debug.LogWarning("Node isn't connected to another dialogue"); // if it's not, set current to null so we know we've reached an endpoint conversation.current = null; } }