Ejemplo n.º 1
0
        public void TestInvalidVariable()
        {
            var treeManagerOwner = new BehaviorTreeManagerOwner();
            var treeManager      = new BehaviorTreeManager(treeManagerOwner);
            var treeOwner        = new BehaviorTreeOwner();
            var tree             = treeManager.CreateTree(treeOwner, "ConditionEvaluator1", null);

            while (tree.RootTask.LastResult == TaskResult.Running)
            {
                tree.Update();
                treeOwner.Tick(100);
            }
        }
        public static void RunBehaviorTree(string path)
        {
            var treeManagerOwner = new BehaviorTreeManagerOwner();
            var treeManager      = new BehaviorTreeManager(treeManagerOwner);
            var treeOwner        = new BehaviorTreeOwner();
            var tree             = treeManager.CreateTree(treeOwner, path, null);

            while (tree.RootTask.LastResult == TaskResult.Running)
            {
                tree.Update();

                treeOwner.Tick(100);
            }
        }
Ejemplo n.º 3
0
        public void TestRestore()
        {
            BehaviorTreeSerializer.Initialize(new FlatBuffersSerializer());

            var treeManagerOwner = new BehaviorTreeManagerOwner();
            var treeManager      = new BehaviorTreeManager(treeManagerOwner);
            var treeOwner        = new BehaviorTreeOwner();
            var tree1            = treeManager.CreateTree(treeOwner, "WaitTimer", null);

            Console.WriteLine("============ Tree1 ============");

            for (int i = 0; i < 20; i++)
            {
                tree1.Update();
                treeOwner.Tick(100);
            }

            var snapshot1 = tree1.CreateSnapshot();

            var data1     = BehaviorTreeSerializer.SerializeProps(snapshot1);
            var snapshot2 = BehaviorTreeSerializer.DeserializeProps(data1);

            Console.WriteLine("============ Tree2 ============");

            var tree2 = treeManager.CreateTree(treeOwner, "WaitTimer", null);

            for (int i = 0; i < 30; i++)
            {
                tree2.Update();
                treeOwner.Tick(100);
            }

            Console.WriteLine("============ Tree2 Restore ============");

            tree2.RestoreSnapshot(snapshot2);

            for (int i = 0; i < 1000 && tree2.RootTask.LastResult == TaskResult.Running; i++)
            {
                tree2.Update();

                treeOwner.Tick(100);
            }
        }