Пример #1
0
        public static void ChoiceTimeoutSuccess()
        {
            var rumor = new Rumor(
                new Dictionary <string, List <Node> >
            {
                { Rumor.MainIdentifier, new List <Node>()
                  {
                      new AddChoiceNode("choice1", "Hello?")
                      , new AddChoiceNode("choice2", "World?")
                      , new ChooseNode(
                          new NumberLiteral(2),
                          MoveType.Jump,
                          "choice2"
                          )
                  } },
                { "choice1", new List <Node>()
                  {
                      new SetDialogNode("Alice", "Choice 1!")
                  } },
                { "choice2", new List <Node>()
                  {
                      new SetDialogNode("Eve", "Choice 2!")
                  } }
            }
                );

            rumor.Start();
            Assert.IsTrue(rumor.Executing);
            Assert.AreEqual(
                new Dictionary <string, string>()
            {
                { "choice1", "Hello?" },
                { "choice2", "World?" },
            },
                rumor.State.GetChoices()
                );

            rumor.Update(2);
            Assert.IsTrue(rumor.Executing);
            Assert.AreEqual(
                new Dictionary <string, string>()
            {
            },
                rumor.State.GetChoices()
                );
            Assert.AreEqual(
                new Dictionary <string, string>()
            {
                { "Eve", "Choice 2!" }
            },
                rumor.State.GetDialog()
                );

            rumor.Advance();
            Assert.IsFalse(rumor.Executing);
            Assert.AreEqual(1, rumor.FinishCount);
            Assert.AreEqual(0, rumor.CancelCount);
        }
        public static void AutoAdvanceNormal()
        {
            var rumor = new Rumor(
                new Dictionary <string, List <Node> >
            {
                { Rumor.MainIdentifier, new List <Node>()
                  {
                      new SetDialogNode("Alice", "Hello world!")
                      , new SetDialogNode("Alice", "How are you?")
                  } }
            }
                );

            rumor.Start();
            rumor.SetAutoAdvance(1);
            Assert.IsTrue(rumor.Executing);
            Assert.AreEqual(
                new Dictionary <string, string>()
            {
                { "Alice", "Hello world!" }
            },
                rumor.State.GetDialog()
                );

            rumor.Update(1);
            Assert.IsTrue(rumor.Executing);
            Assert.AreEqual(
                new Dictionary <string, string>()
            {
                { "Alice", "How are you?" }
            },
                rumor.State.GetDialog()
                );

            rumor.Update(1);
            Assert.IsFalse(rumor.Executing);
            Assert.AreEqual(1, rumor.FinishCount);
            Assert.AreEqual(0, rumor.CancelCount);
        }
Пример #3
0
        public static void PauseSuccess()
        {
            var rumor = new Rumor(
                new Dictionary <string, List <Node> >
            {
                { Rumor.MainIdentifier, new List <Node>()
                  {
                      new PauseNode(1d)
                  } },
            }
                );

            rumor.Start();
            Assert.IsTrue(rumor.Executing);

            rumor.Update(0.5f);
            Assert.IsTrue(rumor.Executing);

            rumor.Update(0.5f);
            Assert.IsFalse(rumor.Executing);
            Assert.AreEqual(1, rumor.FinishCount);
            Assert.AreEqual(0, rumor.CancelCount);
        }
Пример #4
0
        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);
            }
        }
 // Update is called once per frame
 void Update()
 {
     rumor.Update(Time.deltaTime);
 }