Beispiel #1
0
        private void BindHotfixConditionals(BehaviorTreeController tasks, Entity parent)
        {
            foreach (var hotfixConditional in tasks.hotfixConditionals)
            {
                var component = BehaviorTreeFactory.Create(parent, hotfixConditional);

                if (component != null)
                {
                    behaviorTreeConditionalComponents.Add(hotfixConditional, component);
                }
            }
        }
Beispiel #2
0
        private void BindHotfixDecorators(BehaviorTreeController tasks, Entity parent)
        {
            foreach (var hotfixDecorator in tasks.hotfixDecorators)
            {
                var component = BehaviorTreeFactory.Create(parent, hotfixDecorator);

                if (component != null)
                {
                    behaviorTreeDecoratorComponents.Add(hotfixDecorator, component);
                }
            }
        }
Beispiel #3
0
        /// <summary>
        /// 演示行为树用法,使用时可以删除
        /// </summary>
        private static void TestBehaviorTree()
        {
            // 全局共享变量用法
            Game.Scene.AddComponent <BehaviorTreeVariableComponent>().SetVariable("全局变量", 1);

            var runtimeBehaivorTree = UnityEngine.GameObject.Find("Cube").GetComponent <BehaviorDesigner.Runtime.BehaviorTree>();

            if (runtimeBehaivorTree)
            {
                //建议在资源预加载时进行初始化,以免游戏对局中反序列化GC卡顿
                BehaviorTreeHelper.Init(runtimeBehaivorTree.gameObject);

                //动态加载外部行为树用法
                //UnityEngine.Object externalBehavior = 加载("外部行为树资源");
                //BehaviorTreeHelper.Init(externalBehavior);
                //runtimeBehaivorTree.Ensure<BehaviorTreeController>().SetExternalBehavior(externalBehavior);

                runtimeBehaivorTree.Ensure <BehaviorTreeController>().Init();
            }

            var behaviorTree = BehaviorTreeFactory.Create(Game.Scene, runtimeBehaivorTree);

            // 新增行为树共享变量用法
            var p1 = behaviorTree.GetComponent <BehaviorTreeVariableComponent>().GetVariable <int>("变量1");

            Log.Info($"行为树变量:{p1}");

            behaviorTree.GetComponent <BehaviorTreeVariableComponent>().SetVariable("变量1", 2);

            p1 = behaviorTree.GetComponent <BehaviorTreeVariableComponent>().GetVariable <int>("变量1");

            Log.Info($"行为树变量:{p1}");

            behaviorTree.GetComponent <BehaviorTreeVariableComponent>().SetVariable("变量2", "");
            behaviorTree.GetComponent <BehaviorTreeVariableComponent>().SetVariable("变量3", behaviorTree);
            behaviorTree.GetComponent <BehaviorTreeVariableComponent>().SetVariable("变量4", runtimeBehaivorTree);
        }