public override void OnUpdate(Rumor rumor, float delta) { base.OnUpdate(rumor, delta); // Return early if there are no choices left if (rumor != null && rumor.State.Choices.Count == 0) { Finished = true; } if (!doUpdate || Finished) { return; } if (secondsLeft > 0) { secondsLeft -= delta; } if (secondsLeft <= 0) { if (rumor != null) { rumor.Choose(@default); } Finished = true; } }
void Update() { if (rumor == null) { text.text = ""; return; } if (rumor.Choosing) { int num = 1; text.text = ""; foreach (var choice in rumor.State.Choices) { text.text += num + ") " + choice + "\n"; num++; } } else { text.text = rumor.State.Dialog["Narrator"]; } rumor.Update(Time.deltaTime); if (Input.GetMouseButtonDown(0) || Input.GetKeyDown(KeyCode.Space)) { rumor.Advance(); } if (Input.GetKeyDown(KeyCode.Alpha1)) { rumor.Choose(0); } if (Input.GetKeyDown(KeyCode.Alpha2)) { rumor.Choose(1); } }
public static void ChoiceSuccess() { var rumor = new Rumor( new Dictionary <string, List <Node> > { { Rumor.MainIdentifier, new List <Node>() { new AddChoiceNode("choice1", "Hello?") , new ChooseNode() } }, { "choice1", new List <Node>() { new SetDialogNode("Alice", "Choice 1!") } } } ); rumor.Start(); Assert.IsTrue(rumor.Executing); Assert.AreEqual( new Dictionary <string, string>() { { "choice1", "Hello?" }, }, rumor.State.GetChoices() ); rumor.Choose("choice1"); Assert.IsTrue(rumor.Executing); Assert.AreEqual( new Dictionary <string, string>() { { "Alice", "Choice 1!" } }, rumor.State.GetDialog() ); rumor.Advance(); Assert.IsFalse(rumor.Executing); Assert.AreEqual(1, rumor.FinishCount); Assert.AreEqual(0, rumor.CancelCount); }