コード例 #1
0
        private void SetPassage()
        {
            passageText.text = _runtime.Active.text;
            foreach (var link in _runtime.Links)
            {
                var instance = Object.Instantiate(actionsTemplate, actionsArea.transform);
                instance.OnPress = () =>
                {
                    Debug.Log($"Did an action: {link.link}");
                    _runtime.GoToPassage(link.passage);
                    ApplyStoryUpdate();
                };
                instance.text.text = link.name;
                _actions.Add(instance);
            }

            if (_runtime.HasHistory)
            {
                var instance = Object.Instantiate(actionsTemplate, actionsArea.transform);
                instance.OnPress = () =>
                {
                    Debug.Log($"Did an action: Go back");
                    _runtime.GoToPreviousPassage();
                    ApplyStoryUpdate();
                };
                instance.text.text = "Back";
                _actions.Add(instance);
            }
        }
コード例 #2
0
        public void TestFilteredLinksBehaviour()
        {
            var story   = new TwisonLoader().Load(ExampleStory);
            var tracker = new TwisonTagFilterBehaviour();
            var runtime = new TwisonRuntime(story, tracker, true);

            // Before seeing restricted tag, cannot see link
            Assert.False(runtime.Links.Any(i => i.name == "North forest"));

            // Act
            Assert.True(runtime.GoToPassage("Rumors"));
            Assert.True(runtime.GoToPassage("Goblins"));
            Assert.True(runtime.GoToPreviousPassage());
            Assert.True(runtime.GoToPreviousPassage());
            Assert.AreEqual(runtime.Active.name, "Dialog.VillagerGeneric1.Hello");

            // Assert: After seeing tag, can see link
            Assert.True(runtime.Links.Any(i => i.name == "North forest"));
        }