示例#1
0
        public void Switch()
        {
            foreach (string objectName in objectsToDeactivate)
            {
                GameObject gameObject = DoFind(objectName);
                if (gameObject != null)
                {
                    SeamlessSceneLoader loader = gameObject.GetComponentInChildren <SeamlessSceneLoader>();
                    if (loader != null)
                    {
                        loader.Unload();
                    }

                    gameObject.SetActive(false);
                }
            }

            foreach (string objectName in objectsToActivate)
            {
                GameObject gameObject = DoFind(objectName);
                if (gameObject != null)
                {
                    gameObject.SetActive(true);
                }
            }

            for (int i = 0; i < charactersToBan.Length; i++)
            {
                BehaviorTreeController character = charactersToBan[i];
                if (character.isActiveAndEnabled)
                {
                    character.TeleportToBan(ban, Vector3.forward * i);
                }
            }
        }
示例#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);
                }
            }
        }
示例#3
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);
                }
            }
        }
示例#4
0
        void Start()
        {
            if (flowchart == null && flowchartName != null && flowchartName.Trim().Length != 0)
            {
                flowchart = GameObject.Find("/Fungus/Flowcharts/" + flowchartName).GetComponent <Fungus.Flowchart>();
            }

            behaviorTreeController = GetComponentInParent <BehaviorTreeController>();
            health       = GetComponentInParent <CustomHealth>();
            behaviorTree = GetComponentInParent <BehaviorTree>();
            navMeshAgent = GetComponentInParent <NavMeshAgent>();
        }
示例#5
0
 public AttackNode(BehaviorTreeController btController) : base(btController)
 {
 }
示例#6
0
 public SequenceNode(BehaviorTreeController btController) : base(btController)
 {
 }
 void Awake()
 {
     Instance = this;
 }
示例#8
0
 //constructor
 public TreeNode(BehaviorTreeController btController)
 {
     this.btController = btController;
 }
示例#9
0
    void Start()
    {
        _behaviorTreeController = new BehaviorTreeController();

        // rootとなるSequencer
        SequencerNode rootNode = new SequencerNode();

        rootNode.name = "rootノード";

        // 出発
        ActionNode departure = new ActionNode();

        departure.name = "出発する";
        departure.SetRunningFunc(() => {
            Debug.LogError("出発");
            return(NodeStatus.SUCCESS);
        });

        // HP確認のDecorator
        DecoratorNode confirmationHp = new DecoratorNode();

        confirmationHp.name = "HP確認するのDecorator";
        confirmationHp.SetConditionFunc(() => {
            return(_myHp >= 100 ? NodeStatus.SUCCESS : NodeStatus.FAILURE);
        });

        // 敵に寄る
        ActionNode enemyApproach = new ActionNode();

        enemyApproach.name = "敵に寄るアクションノード";
        enemyApproach.SetRunningFunc(() => {
            Debug.LogError("敵に寄る");
            return(NodeStatus.SUCCESS);
        });

        // HP確認のDecoratorの子供登録
        confirmationHp.AddChild(enemyApproach);

        // 友達2人を呼ぶParallelNode
        ParallelNode callFriendAB = new ParallelNode();

        callFriendAB.name = "友達2人を呼ぶParallelNode";

        // 友達A
        ActionNode friendA = new ActionNode();

        friendA.name = "友達Aを呼ぶ";
        friendA.SetRunningFunc(() => {
            Debug.LogError("友達A");
            return(NodeStatus.SUCCESS);
        });

        // 友達B
        ActionNode friendB = new ActionNode();

        friendB.name = "友達Bを呼ぶ";
        friendB.SetRunningFunc(() => {
            Debug.LogError("友達B");
            return(NodeStatus.SUCCESS);
        });

        // 友達2人を呼ぶParallelNodeの子供登録
        callFriendAB.AddChild(friendA);
        callFriendAB.AddChild(friendB);

        // スキルを繰り返し行うRepeaterNode
        RepeaterNode skillRepeater = new RepeaterNode();

        skillRepeater.name = "スキルを繰り返し行うRepeaterNode";

        // スキルを選択するSelector
        SelectorNode selectSkill = new SelectorNode();

        selectSkill.name = "スキルを選択するSelector";

        // スキルAの発動を確認するDecorator
        DecoratorNode triggerSkillA = new DecoratorNode();

        triggerSkillA.name = "スキルAの発動を確認するDecorator";
        triggerSkillA.SetConditionFunc(() => {
            int probability = Mathf.Clamp(probabilitySkillA, 0, 100);
            int random      = Random.Range(0, 100);
            return(probability > random ? NodeStatus.SUCCESS : NodeStatus.FAILURE);
        });

        // スキルA
        ActionNode skillA = new ActionNode();

        skillA.name = "skillA";
        skillA.SetRunningFunc(() => {
            Debug.LogError("skillA");
            _enemyHp -= 50;
            return(NodeStatus.SUCCESS);
        });

        // スキルAの発動を確認するDecoratorの子供登録
        triggerSkillA.AddChild(skillA);


        // スキルB
        ActionNode skillB = new ActionNode();

        skillB.name = "skillB";
        skillB.SetRunningFunc(() => {
            Debug.LogError("skillB");
            _enemyHp -= 60;
            return(NodeStatus.SUCCESS);
        });

        // スキルを選択するSelectorの子供登録
        selectSkill.AddChild(triggerSkillA);
        selectSkill.AddChild(skillB);

        // スキルを繰り返し行うRepeaterNodeの子供登録
        skillRepeater._repeatNum = 2;
        skillRepeater.AddChild(selectSkill);

        // 敵の生存を確認するSelector
        SelectorNode enemySurvial = new SelectorNode();

        enemySurvial.name = "敵の生存を確認するSelector";

        // 敵が死んでいるか確認するDecorator
        DecoratorNode enemyDied = new DecoratorNode();

        enemyDied.name = "敵が死んでいるか確認するDecorator";
        enemyDied.SetConditionFunc(() => {
            return(_enemyHp <= 0 ? NodeStatus.SUCCESS : NodeStatus.FAILURE);
        });

        // 敵が死んでいる
        ActionNode died = new ActionNode();

        died.name = "敵が死んでいる";
        died.SetRunningFunc(() => {
            Debug.LogError("End1");
            Debug.LogError("EnemyHp : " + _enemyHp);
            return(NodeStatus.SUCCESS);
        });

        // 敵が死んでいるか確認するDecoratorの子供登録
        enemyDied.AddChild(died);

        // 敵が生きているか確認するDecorator
        DecoratorNode enemyAlive = new DecoratorNode();

        enemyAlive.name = "敵が生きているか確認するDecorator";
        enemyAlive.SetConditionFunc(() => {
            return(_enemyHp > 0 ? NodeStatus.SUCCESS : NodeStatus.FAILURE);
        });

        // 敵が生きている
        ActionNode alive = new ActionNode();

        alive.name = "敵が生きている";
        alive.SetRunningFunc(() => {
            Debug.LogError("End2");
            Debug.LogError("EnemyHp : " + _enemyHp);
            return(NodeStatus.SUCCESS);
        });

        // 敵が生きているか確認するDecoratorの子供登録
        enemyAlive.AddChild(alive);

        // 敵の生存を確認するSelectorの子供登録
        enemySurvial.AddChild(enemyDied);
        enemySurvial.AddChild(enemyAlive);


        // rootノードの子供登録
        rootNode.AddChild(departure);
        rootNode.AddChild(confirmationHp);
        rootNode.AddChild(callFriendAB);
        rootNode.AddChild(skillRepeater);
        rootNode.AddChild(enemySurvial);

        // ツリー実行
        _behaviorTreeController.Initialize(rootNode);
        _behaviorTreeController.OnStart();
    }
示例#10
0
 public FindNearestResourceNode(BehaviorTreeController btController) : base(btController)
 {
 }
示例#11
0
 public Decorator(BehaviorTreeController btController) : base(btController)
 {
 }
示例#12
0
 public Compositor(BehaviorTreeController btController) : base(btController)
 {
 }
示例#13
0
 public SelectorNode(BehaviorTreeController btController) : base(btController)
 {
 }