/// <summary> /// Step to the next dialogue entry /// </summary> /// <returns>true if successfully stepped to the next dialogue or trigger some events</returns> public bool Step() { Assert.IsNotNull(currentNode, "Call Step before the game start"); if (CheckActionRunnig()) { return(false); } if (state != State.Normal) { return(false); // can step forward only when state is normal } // if have a next dialogue entry in the current node, directly step to the next if (currentIndex + 1 < currentNode.DialogueEntryCount) { currentIndex += 1; UpdateGameState(); return(true); } // Reach the end of a node, do something regards on the flow chart node type switch (currentNode.type) { case FlowChartNodeType.Normal: // for normal node, just step directly to the next node MoveToNextNode(currentNode.Next); // successfully move to the next node return(true); case FlowChartNodeType.Branching: // A branch occurs, inform branch event listeners state = State.IsBranching; if (BranchOccurs != null) { BranchOccurs.Invoke(new BranchOccursData(currentNode.GetAllBranches())); } break; case FlowChartNodeType.End: state = State.Ended; var endName = flowChartTree.GetEndName(currentNode); if (!checkpointManager.IsReached(endName)) { // mark the end as reached checkpointManager.SetReached(endName); } if (CurrentRouteEnded != null) { CurrentRouteEnded.Invoke(new CurrentRouteEndedData(endName)); } break; default: throw new ArgumentOutOfRangeException(); } return(true); }
/// <summary> /// Step to the next dialogue entry /// </summary> public void Step() { if (currentNode == null) { Debug.LogError("Call Step before the game start"); return; } // if have a next dialogue entry in the current node, directly step to the next if (currentIndex + 1 < currentNode.DialogueEntryCount) { currentIndex += 1; UpdateGameState(); return; } // Reach the end of a node, do something regards on the flow chart node type switch (currentNode.type) { case FlowChartNodeType.Normal: // for normal node, just step directly to the next node MoveToNode(currentNode.Next); break; case FlowChartNodeType.Branching: // A branch occurs, inform branch event listeners if (isBranching) { // A branching is happening, but the player have not decided which branch to select yet // Break directly to avoid duplicated invocations of the same branching event break; } isBranching = true; BranchOccurs.Invoke(new BranchOccursEventData(currentNode.GetAllBranches())); break; case FlowChartNodeType.End: CurrentRouteEnded.Invoke(new CurrentRouteEndedEventData(flowChartTree.GetEndName(currentNode))); break; default: throw new ArgumentOutOfRangeException(); } }