예제 #1
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);
                }
            }
        }
예제 #2
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);
                }
            }
        }
예제 #3
0
        /// <summary>
        /// 演示行为树用法,使用时可以删除
        /// </summary>
        private static void TestBehaviorTree()
        {
            // 全局共享变量用法
            Game.Scene.AddComponent <BehaviorTreeVariableComponent>().SetVariable("全局变量", 1);

            var runtimeBehaivorTree = UnityEngine.Object.Instantiate(ResourcesHelper.Load("Cube") as GameObject).GetComponent <BehaviorDesigner.Runtime.BehaviorTree>();

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

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

                (GameObjectHelper.Ensure(runtimeBehaivorTree.gameObject, typeof(BehaviorTreeController)) as 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);
        }