Exemplo n.º 1
0
        public YarnEngine(
            String ConversationFile,
            String StartNode,
            Yarn.MemoryVariableStore Memory,
            IYarnPlayerInterface PlayerInterface)
        {
            this.PlayerInterface = PlayerInterface;
            this.Memory          = Memory;

            CommandGrammar = new YarnCommandGrammar();

            foreach (var method in AssetManager.EnumerateModHooks(typeof(YarnCommandAttribute), typeof(void), new Type[]
            {
                typeof(YarnEngine),
                typeof(List <Ancora.AstNode>),
                typeof(Yarn.MemoryVariableStore)
            }))
            {
                var attribute = method.GetCustomAttributes(false).FirstOrDefault(a => a is YarnCommandAttribute) as YarnCommandAttribute;
                if (attribute == null)
                {
                    continue;
                }
                CommandHandlers[attribute.CommandName] = new CommandHandler
                {
                    Action   = (state, args, mem) => method.Invoke(null, new Object[] { state, args, mem }),
                    Settings = attribute
                };
            }

            Dialogue = new Yarn.Dialogue(Memory);

            Dialogue.LogDebugMessage = delegate(string message) { Console.WriteLine(message); };
            Dialogue.LogErrorMessage = delegate(string message) { Console.WriteLine("Yarn Error: " + message); };

            //try
            {
                Dialogue.LoadFile(AssetManager.ResolveContentPath(ConversationFile), false, false, null);
            }
            //catch (Exception e)
            {
                //  Console.Error.WriteLine(e.ToString());
            }

            Runner = Dialogue.Run(StartNode).GetEnumerator();
        }
Exemplo n.º 2
0
        public void TestNodeExists()
        {
            dialogue.LoadFile("../Unity/Assets/Yarn Spinner/Examples/Demo Assets/Space.json");

            dialogue.Compile();

            Assert.True(dialogue.NodeExists("Sally"));

            // Test clearing everything
            dialogue.UnloadAll();

            // Load an empty node
            dialogue.LoadString("// Test, this is empty");
            dialogue.Compile();

            Assert.False(dialogue.NodeExists("Sally"));
        }