public override void MoveNext() { DialogueGraph fmGraph = graph as DialogueGraph; if (fmGraph.current != this) { Debug.LogWarning("Node isn't active"); return; } int totalWeight = 0; for (int i = 0; i < exits.Count; i++) { totalWeight += exits[i]; } int randomWeight = Random.Range(0, totalWeight + 1); string exitName = "exits 0"; for (int i = 0; i < exits.Count; i++) { randomWeight -= exits[i]; if (randomWeight <= 0) { exitName = "exits " + i; break; } } var exitPort = this.GetOutputPort(exitName); if (exitPort == null) { Debug.Log("Invalid exit port '" + exitPort + "' for node " + name); } if (!exitPort.IsConnected) { fmGraph.current = null; return; } int index = Random.Range(0, exitPort.ConnectionCount); var exitNode = exitPort.GetConnection(index); DialogueNodeBase node = exitNode.node as DialogueNodeBase; node.OnEnter(); }
public void Execute() { if (state == RunningState.Stop) { return; } if (_entryNode == null) { Debug.LogWarning("EntryNode Can't Find"); return; } if (_currentNode == null) { var entryOutput = _entryNode.GetOutputPort().Connection; if (entryOutput != null) { _currentNode = entryOutput.node as DialogueNodeBase; _currentNode.OnEnter(); } } if (_currentNode == null) { Debug.LogWarning("CurrentNode Can't Find"); return; } if (_currentNode.Execute()) { var outPut = _currentNode.GetOutputPort().Connection; if (outPut != null) { _currentNode.OnExit(); _currentNode = outPut.node as DialogueNodeBase; _currentNode.OnEnter(); } else { state = RunningState.Stop; } } }
public override void MoveNext() { DialogueGraph fmGraph = graph as DialogueGraph; if (fmGraph.current != this) { Debug.LogWarning("Node isn't active"); return; } var exitPort = this.GetOutputPort("exit"); if (exitPort == null) { Debug.Log("Invalid exit port '" + exitPort + "' for node " + name); fmGraph.current = null; return; } if (!exitPort.IsConnected) { fmGraph.current = null; return; } int index = Random.Range(0, exitPort.ConnectionCount); var exitNode = exitPort.GetConnection(index); if (exitNode == null) { Debug.Log("Could not find ending for random branch"); fmGraph.current = null; return; } DialogueNodeBase node = exitNode.node as DialogueNodeBase; node.OnEnter(); }