示例#1
0
    // Start is called before the first frame update
    void Start()
    {
        m_Shooter = gameObject.GetComponent <Shooter_Move>(); //슈터무브 컴포넌트 받기
        root.AddChild(selector);                              //트리 구성
        selector.AddChild(seqDead);
        selector.AddChild(seqMovingAttack);

        moveForTarget.Shooter = m_Shooter;
        changeGun.Shooter     = m_Shooter;
        isCollision.Shooter   = m_Shooter; //isCollision Shooter추가
        detectPos.Shooter     = m_Shooter;
        m_OnAttack.Shooter    = m_Shooter;
        m_IsDead.Shooter      = m_Shooter;

        seqMovingAttack.AddChild(moveForTarget);    //자식
        seqMovingAttack.AddChild(m_OnAttack);
        seqMovingAttack.AddChild(changeGun);
        seqMovingAttack.AddChild(isCollision); //IsCollision 자식 노드 추가
        seqMovingAttack.AddChild(detectPos);   //detectPos 자식노드

        seqDead.AddChild(m_IsDead);

        behaviorProcess = BehaviorProcess();
        StartCoroutine(behaviorProcess);
    }
示例#2
0
    void Awake()
    {
        BehaviorTree tree = gameObject.AddComponent <BehaviorTree> ();

        tree.StartWhenEnabled = false;

        EntryTask entryTask = new EntryTask();

        entryTask.NodeData = new NodeData();
        tree.GetBehaviorSource().EntryTask = entryTask;

        Sequence rootTask = new Sequence();

        rootTask.NodeData = new NodeData();

        tree.GetBehaviorSource().RootTask = rootTask;

        Wait myWait = new Wait();

        myWait.NodeData = new NodeData();
        rootTask.AddChild(myWait, 0);

        PatrollTask patroll = new PatrollTask();

        patroll.NodeData = new NodeData();
        rootTask.AddChild(patroll, 1);

        tree.GetBehaviorSource().HasSerialized = true;
        tree.EnableBehavior();
    }
示例#3
0
    // Start is called before the first frame update
    void Start()
    {
        Debug.Log("Start Tree");
        m_tiger = gameObject.GetComponent <Tiger_Move>();
        root.AddChild(selector);
        selector.AddChild(seqInTheFarm);

        hungry.tiger      = m_tiger;
        poop.tiger        = m_tiger;
        play.tiger        = m_tiger;
        followMouse.tiger = m_tiger;
        follow_Food.tiger = m_tiger;
        follow_Egg.tiger  = m_tiger;
        follow_Milk.tiger = m_tiger;
        eat.tiger         = m_tiger;
        basicMove.tiger   = m_tiger;
        quarrel.tiger     = m_tiger;

        seqInTheFarm.AddChild(hungry);
        seqInTheFarm.AddChild(poop);
        seqInTheFarm.AddChild(play);
        seqInTheFarm.AddChild(followMouse);

        seqInTheFarm.AddChild(follow_Food);
        seqInTheFarm.AddChild(follow_Milk);
        seqInTheFarm.AddChild(follow_Egg);

        seqInTheFarm.AddChild(eat);
        seqInTheFarm.AddChild(basicMove);
        seqInTheFarm.AddChild(quarrel);

        behaviorProcess = BehaviorProcess();
        StartCoroutine(behaviorProcess);
    }
示例#4
0
    // Start is called before the first frame update
    void Start()
    {
        Debug.Log("Start Tree");
        m_Sonny = gameObject.GetComponent <SonnyMove>();
        root.AddChild(selector);
        selector.AddChild(seqDead);         // seqDead 노드를 selector의 자식 노드로 연결
        selector.AddChild(seqMovingAttack); // seqMovingAttack 노드를 selector의 자식 노드로 연결

        moveinmap.Enemy   = m_Sonny;        // m_Enemy를 넣어 초기화시킴
        m_OnAttack.Enemy  = m_Sonny;
        isCollision.Enemy = m_Sonny;
        detectPos.Enemy   = m_Sonny;
        m_IsDead.Enemy    = m_Sonny;

        seqMovingAttack.AddChild(m_OnAttack);

        seqMovingAttack.AddChild(moveinmap);    //seqMovingAttack 노드에 클래스 변수들을 자식으로 추가
        seqMovingAttack.AddChild(isCollision);
        seqMovingAttack.AddChild(detectPos);

        seqDead.AddChild(m_IsDead); //seqDead 노드에 클래스 변수를 자식으로 추가

        behaviorProcess = BehaviorProcess();
        StartCoroutine(behaviorProcess);
    }
示例#5
0
        IEnumerator Start()
        {
            Sequence root = new Sequence();

            Selector selector = new Selector();

            Sequence attackSequence = new Sequence();

            Node isAlivedBehavior = new IsAlivedBehavior(this);
            Node detectBehavior   = new DetectBehavior(this);
            Node attackBehavior   = new AttackBehavior(this);
            Node patrolBehavior   = new PatrolBehavior(this);

            root.AddChild(selector);

            root.AddChild(isAlivedBehavior);

            selector.AddChild(attackSequence);

            attackSequence.AddChild(detectBehavior);
            attackSequence.AddChild(attackBehavior);

            selector.AddChild(patrolBehavior);

            while (root.Invoke())
            {
                yield return(null);
            }
        }
示例#6
0
    private void Start()
    {
        agent = this.GetComponent <NavMeshAgent>();

        tree = new BehaviourTree();
        Sequence steal = new Sequence("Steal Something");
        // Node goToPoint = new Leaf("Go To Point", GoToPoint);
        Node     goToFrontDoor = new Leaf("Go To FrontDoor", GoToFrontDoor);
        Node     goToBackDoor  = new Leaf("Go To BackDoor", GoToBackDoor);
        Node     goToDiamond   = new Leaf("Go To Diamond", GoToDiamond);
        Node     goToVan       = new Leaf("Go To Van", GoToVan);
        Selector openDoor      = new Selector("Open Door");

        openDoor.AddChild(goToFrontDoor);
        openDoor.AddChild(goToBackDoor);

        //steal.AddChild(goToPoint);
        steal.AddChild(openDoor);
        steal.AddChild(goToFrontDoor);
        //steal.AddChild(goToBackDoor);
        steal.AddChild(goToDiamond);
        //steal.AddChild(goToBackDoor);
        steal.AddChild(goToVan);

        tree.AddChild(steal);

        tree.PrintTree();
    }
示例#7
0
    private void Init()
    {
        //Patrol

        //Chase
        selChase.AddChild(inSight);
        selChase.AddChild(isDamaged);

        seqChase.AddChild(chase);
        seqChase.AddChild(selChase);

        //Attack
        seqAttack.AddChild(attack);
        seqAttack.AddChild(inAttackRange);

        selMove.AddChild(patrol);
        selMove.AddChild(seqChase);
        selMove.AddChild(seqAttack);

        //Death
        seqDeath.AddChild(death);
        seqDeath.AddChild(isDead);

        root.AddChild(seqDeath);
        root.AddChild(selMove);
    }
示例#8
0
        public MiddleBT()
        {
            Selector selector =
                ScriptableObject.CreateInstance <Selector>();
            Sequence sequence =
                ScriptableObject.CreateInstance <Sequence>();
            ParallelSelector ps =
                ScriptableObject.CreateInstance <ParallelSelector>();
            CanISeePlayer c1 =
                ScriptableObject.CreateInstance <CanISeePlayer>();
            CanISeePlayer c2 =
                ScriptableObject.CreateInstance <CanISeePlayer>();
            TranslatetoARandomPosition t1 =
                ScriptableObject.CreateInstance <TranslatetoARandomPosition>();
            UntilSuccess untilSuccess =
                ScriptableObject.CreateInstance <UntilSuccess>();
            RotateByY r1 = ScriptableObject.CreateInstance <RotateByY>();

            selector.AddChild(sequence, 0);
            selector.AddChild(ps, 1);
            sequence.AddChild(c1, 0);
            sequence.AddChild(t1, 1);
            ps.AddChild(untilSuccess, 0);
            ps.AddChild(r1, 1);
            untilSuccess.AddChild(c2, 0);

            InitalBTStructureData(selector);
        }
示例#9
0
    public BTEnemy(Agent ownerBrain) : base(ownerBrain)
    {
        rootSelector = new Selector();

        enemyCheck          = new Sequence();
        patrolSequence      = new Sequence();
        suspiciousSequence  = new Sequence();
        ChaseSequence       = new Sequence();
        DistractionSequence = new Sequence();

        parallelDetection = new Parallel();
        checkInverter     = new Inverter();

        turnToPoint = new TurnToPoint(GetOwner());
        patrol      = new Patrol(GetOwner());
        wait        = new Wait(GetOwner());

        detection   = new Detection(GetOwner());
        distraction = new Distraction(GetOwner());

        suspicious      = new Suspicious(GetOwner());
        suspiciousAlert = new SuspiciousAlert(GetOwner());
        moveToLKP       = new MoveToLKP(GetOwner());

        seen  = new Seen(GetOwner());
        chase = new Chase(GetOwner());

        //Root -> Patrol and Check
        rootSelector.AddChild(parallelDetection);
        parallelDetection.AddChild(checkInverter);

        //A parallel to check for the player
        checkInverter.AddChild(detection);

        //Patrol alongside checking for the player
        parallelDetection.AddChild(patrolSequence);
        patrolSequence.AddChild(patrol);
        patrolSequence.AddChild(wait);
        patrolSequence.AddChild(turnToPoint);

        //Root -> Adding sequences
        rootSelector.AddChild(suspiciousSequence);
        rootSelector.AddChild(ChaseSequence);
        rootSelector.AddChild(DistractionSequence);

        //Distraction State
        DistractionSequence.AddChild(distraction);
        DistractionSequence.AddChild(wait);

        //Suspicious state
        suspiciousSequence.AddChild(suspicious);
        suspiciousSequence.AddChild(suspiciousAlert);
        suspiciousSequence.AddChild(moveToLKP);
        suspiciousSequence.AddChild(wait);

        //Chase state
        ChaseSequence.AddChild(seen);
        ChaseSequence.AddChild(chase);
        ChaseSequence.AddChild(wait);
    }
示例#10
0
    private void Init()
    {
        //Death
        seqDeath.AddChild(death);
        seqDeath.AddChild(isDead);

        root.AddChild(seqDeath);
        root.AddChild(inAttackRange);
    }
示例#11
0
    public MiddleBTRandom()
    {
        Selector                   selector     = ScriptableObject.CreateInstance <Selector>();
        Sequence                   sequence     = ScriptableObject.CreateInstance <Sequence>();
        ParallelSelector           ps           = ScriptableObject.CreateInstance <ParallelSelector>();
        CanISeePlayer              c1           = ScriptableObject.CreateInstance <CanISeePlayer>();
        CanISeePlayer              c2           = ScriptableObject.CreateInstance <CanISeePlayer>();
        TranslatetoARandomPosition t1           = ScriptableObject.CreateInstance <TranslatetoARandomPosition>();
        UntilSuccess               untilSuccess = ScriptableObject.CreateInstance <UntilSuccess>();
        RotateByY                  r1           = ScriptableObject.CreateInstance <RotateByY>();

        // 包含0,不包含3
        int    randomChoice = Random.Range(0, 3);
        string color        = "";

        switch (randomChoice)
        {
        case 0:
            RedAction redTask = ScriptableObject.CreateInstance <RedAction>();
            color = "red";
            sequence.AddChild(redTask, 0);
            break;

        case 1:
            BlueAction blueTask = ScriptableObject.CreateInstance <BlueAction>();
            color = "blue";
            sequence.AddChild(blueTask, 0);
            break;

        case 2:
            YellowAction yellowTask = ScriptableObject.CreateInstance <YellowAction>();
            color = "yellow";
            sequence.AddChild(yellowTask, 0);
            break;

        default:
            break;
        }

        if (null == UIBTInformationNotifier.instance)
        {
            UIBTInformationNotifier notifier = new UIBTInformationNotifier();
        }
        UIBTInformationNotifier.instance.NotifyColorInfoChangeEvent(color);


        selector.AddChild(sequence, 0);
        selector.AddChild(ps, 1);
        sequence.AddChild(c1, 1);
        sequence.AddChild(t1, 2);
        ps.AddChild(untilSuccess, 0);
        ps.AddChild(r1, 1);
        untilSuccess.AddChild(c2, 0);

        InitalBTStructureData(selector);
    }
示例#12
0
        public void SetupChild()
        {
            _sequence = new Sequence();

            _childA = CreateTaskStub();
            _sequence.AddChild(_childA);

            _childB = CreateTaskStub();
            _sequence.AddChild(_childB);
        }
示例#13
0
    public BTEnemy(Agent ownerBrain) : base(ownerBrain)
    {
        rootSelector      = new Selector();
        charging          = new Sequence();
        parallelDetection = new Parallel();
        //checkInverter = new Inverter();
        randomJob = new SelectorRandom();

        recharge      = new Recharge(GetOwner());
        needsCharging = new NeedsCharging(GetOwner());
        collectWood   = new CollectWood(GetOwner());
        collectRocks  = new CollectRocks(GetOwner());
        collectPower  = new CollectPower(GetOwner());

        ////////////////////////////////
        rootSelector.AddChild(charging);
        rootSelector.AddChild(randomJob);

        charging.AddChild(needsCharging);
        charging.AddChild(recharge);

        randomJob.AddChild(collectWood);
        randomJob.AddChild(collectRocks);
        randomJob.AddChild(collectPower);

        //A parallel to check for the player
        //checkInverter.AddChild(detection);

        //Patrol alongside checking for the player
        //parallelDetection.AddChild(patrolSequence);
        //patrolSequence.AddChild(patrol);
        //patrolSequence.AddChild(wait);
        //patrolSequence.AddChild(turnToPoint);
        //
        ////Root -> Adding sequences
        //rootSelector.AddChild(suspiciousSequence);
        //rootSelector.AddChild(ChaseSequence);
        //rootSelector.AddChild(DistractionSequence);
        //
        ////Distraction State
        ////DistractionSequence.AddChild(distraction);
        //DistractionSequence.AddChild(wait);
        //
        ////Suspicious state
        ////suspiciousSequence.AddChild(suspicious);
        //suspiciousSequence.AddChild(suspiciousAlert);
        ////suspiciousSequence.AddChild(moveToLKP);
        //suspiciousSequence.AddChild(wait);
        //
        ////Chase state
        ////ChaseSequence.AddChild(seen);
        ////ChaseSequence.AddChild(chase);
        //ChaseSequence.AddChild(wait);
    }
示例#14
0
文件: TesteHeap.cs 项目: Suike/Tools
    void Start()
    {
        tree = new BehaviourTree();
        teste = new TestBehaviourInstant(this);
        teste2 = new TestBehaviour5Times(this);
        sequence = new Sequence(tree);
        sequence.AddChild(teste);
        sequence.AddChild(teste2);

        tree.Insert(sequence, null);

        manager = new ActionManager();
    }
    public Node GetAnimationAction(string aniName, bool waiteForEnd, Node action, Condition condition, int priority)
    {
        var seq = new Sequence();

        seq.AddChild(condition);
        seq.AddChild(new Animate(animator, aniName, waiteForEnd));
        seq.AddChild(action);

        var dec = new Decorator(priority);

        dec.Node = seq;

        return(dec);
    }
示例#16
0
    // Start is called before the first frame update
    void Start()
    {
        agent = this.GetComponent <NavMeshAgent>();
        tree  = new BehaviorTree();
        Sequence steal         = new Sequence("Steal Something");
        Leaf     goToBackDoor  = new Leaf("Go To Back Door", () => GoToDoor(backDoor));
        Leaf     goToFrontDoor = new Leaf("Go To Front Door", () => GoToDoor(frontDoor));
        Leaf     goToDiamond   = new Leaf("Go To Diamond", () =>
        {
            Node.Status s = GoToLocation(diamond.transform.position);
            if (s == Node.Status.SUCCESS)
            {
                diamond.transform.parent = this.gameObject.transform;
            }
            return(s);
        });
        Leaf needsMoney = new Leaf("Needs Money", () => { if (money >= 500)
                                                          {
                                                              return(Node.Status.FAILURE);
                                                          }
                                                          else
                                                          {
                                                              return(Node.Status.SUCCESS);
                                                          } });
        Leaf goToVan = new Leaf("Go To Van", () =>
        {
            Node.Status s = GoToLocation(van.transform.position);
            if (s == Node.Status.SUCCESS)
            {
                money += 300;
                Destroy(diamond);
            }
            return(s);
        });
        Selector openDoor = new Selector("Open Door");

        openDoor.AddChild(goToBackDoor);
        openDoor.AddChild(goToFrontDoor);

        steal.AddChild(needsMoney);
        steal.AddChild(openDoor);
        steal.AddChild(goToDiamond);
        steal.AddChild(goToVan);
        tree.AddChild(steal);

        tree.PrintTree();
        Time.timeScale = 5;
    }
示例#17
0
    // Use this for initialization
    void Start()
    {
        MoveLocation = transform.position;

        //CREATING OUR ZOMBIE BEHAVIOUR TREE

        //Get reference to Zombie Blackboard
        ZombieBB bb = GetComponent <ZombieBB>();

        //Create our root selector
        Selector rootChild = new Selector(bb); // selectors will execute it's children 1 by 1 until one of them succeeds

        BTRootNode = rootChild;

        //Flee Sequence
        CompositeNode fleeSequence = new Sequence(bb);                    // The sequence of actions to take when Fleeing
        FleeDecorator fleeRoot     = new FleeDecorator(fleeSequence, bb); // defines the condition required to enter the flee sequence (see FleeDecorator)

        fleeSequence.AddChild(new CalculateFleeLocation(bb));             // calculate a destination to flee to (just random atm)
        fleeSequence.AddChild(new ZombieMoveTo(bb, this));                // move to the calculated destination
        fleeSequence.AddChild(new ZombieWaitTillAtLocation(bb, this));    // wait till we reached destination
        fleeSequence.AddChild(new ZombieStopMovement(bb, this));          // stop movement
        fleeSequence.AddChild(new DelayNode(bb, 2.0f));                   // wait for 2 seconds

        //Fight sequence
        CompositeNode  FightSequence = new Sequence(bb);                      // The sequence of actions to take when Fighting
        FightDecorator fightRoot     = new FightDecorator(FightSequence, bb); //defines the condition required to enter the fight sequence(see FightDecorator)

        //Defining a sequence for when the Zombie is to do it's combo attack, this is a nested within our FightSequence
        Sequence ZombieCombo = new Sequence(bb);

        ZombieCombo.AddChild(new ZombieClawPlayer(bb));           // claw the player
        ZombieCombo.AddChild(new DelayNode(bb, 0.8f));            // wait for 0.8 seconds
        ZombieCombo.AddChild(new ZombieBitePlayer(bb));           // bite the player
        ZombieCombo.AddChild(new DelayNode(bb, 1.5f));            // wait for 1.5 seconds

        FightSequence.AddChild(new ZombieMoveToPlayer(bb, this)); // constantly move to player until within range
        FightSequence.AddChild(new ZombieStopMovement(bb, this)); // stop movement
        FightSequence.AddChild(ZombieCombo);                      // perform combo sequence


        //Adding to root selector
        rootChild.AddChild(fleeRoot);
        rootChild.AddChild(fightRoot);

        //Execute our BT every 0.1 seconds
        InvokeRepeating("ExecuteBT", 0.1f, 0.1f);
    }
示例#18
0
    // Start is called before the first frame update
    void Start()
    {
        Debug.Log("생성");
        m_Slime = gameObject.GetComponent <GreenSlime>();
        root.AddChild(selector);
        selector.AddChild(seqDead);
        selector.AddChild(selectPattern);

        //노드
        m_Dead.Enemy        = m_Slime;
        m_Attack.Enemy      = m_Slime;
        m_MonsterMove.Enemy = m_Slime;
        m_Patrol.Enemy      = m_Slime;
        m_GetHit.Enemy      = m_Slime;

        seqDead.AddChild(m_Dead);

        selectPattern.AddChild(seqMove);
        selectPattern.AddChild(seqAttack);
        selectPattern.AddChild(seqPatrol);
        selectPattern.AddChild(seqGetHit);

        seqMove.AddChild(m_MonsterMove);
        seqAttack.AddChild(m_Attack);
        seqPatrol.AddChild(m_Patrol);
        seqGetHit.AddChild(m_GetHit);

        behaviorProcess = BehaviorProcess();
        StartCoroutine(behaviorProcess);
    }
示例#19
0
    void Start()
    {
        BehaviorTree behaviorTree = gameObject.AddComponent <BehaviorTree>();

        behaviorTree.StartWhenEnabled = false;

        var entryTask = new EntryTask();

#if UNITY_EDITOR
        entryTask.NodeData = new NodeData();
#endif
        behaviorTree.GetBehaviorSource().EntryTask = entryTask;

        var rootTask = new Sequence();
#if UNITY_EDITOR
        rootTask.NodeData = new NodeData();
#endif
        behaviorTree.GetBehaviorSource().RootTask = rootTask;

        Log log = new Log();
#if UNITY_EDITOR
        log.NodeData = new NodeData();
#endif
        log.logError = new SharedBool();
        rootTask.AddChild(log, 0);
        log.text = "try me!...";

        behaviorTree.GetBehaviorSource().HasSerialized = true;
        behaviorTree.EnableBehavior();
    }
示例#20
0
    public override void Init()
    {
        bossController = GetComponent <BossMonsterController>();
        bossController.Init();

        idle.Controller         = bossController;
        detectTarget.Controller = bossController;

        chaseTarget.Controller         = bossController;
        checkCloseTarget.Controller    = bossController;
        checkPossibleAttack.Controller = bossController;
        startAttack.Controller         = bossController;

        checkPossibleSkill.Controller = bossController;
        skillAction.Controller        = bossController;

        deadAction.Controller = bossController;
        isDie.Controller      = bossController;

        //Node 추가
        aiRoot.AddChild(seqNormal);

        seqNormal.AddChild(idle);
        seqNormal.AddChild(detectTarget);

        aiRoot.AddChild(selector);

        selector.AddChild(seqchaseAttack);
        selector.AddChild(seqSkill);
        selector.AddChild(seqDead);

        seqchaseAttack.AddChild(chaseTarget);
        seqchaseAttack.AddChild(checkCloseTarget);
        seqchaseAttack.AddChild(checkPossibleAttack);
        seqchaseAttack.AddChild(startAttack);

        seqSkill.AddChild(checkPossibleSkill);
        seqSkill.AddChild(skillAction);

        seqDead.AddChild(isDie);
        seqDead.AddChild(deadAction);

        behaviorProcess = BehaviorProcess();
    }
示例#21
0
        public SimpleBT()
        {
            Sequence         s1        = new Sequence();
            Parallel         p1        = new Parallel();
            Selector         selector1 = new Selector();
            ParallelSelector ps1       = new ParallelSelector();
            RedAction        a1        = new RedAction();
            //SimpleAction2 a2 = new SimpleAction2();
            YellowAction a2 = new YellowAction();

            s1.AddChild(a1, 0);
            s1.AddChild(a2, 1);
            p1.AddChild(a1, 0);
            p1.AddChild(a2, 1);
            selector1.AddChild(a1, 0);
            selector1.AddChild(a2, 1);
            ps1.AddChild(a1, 0);
            ps1.AddChild(a2, 1);
            // just test sequence
            // this.taskList.Add(s1);
            // just test parallel
            //this.taskList.Add(p1);
            // just test selector
            //this.taskList.Add(selector1);
            // just test ParallelSelecotr
            this.taskList.Add(ps1);
            this.taskList.Add(a1);
            this.taskList.Add(a2);
            this.parentIndexList.Add(0);
            // 其实组装一个action的东西是不是应该是AddTask方法封装好的呀,而用户只是传进来一个Type
            //SimpleAction2 a3 = new SimpleAction2();
            //this.AddTask(0, 0, a3);

            for (int i = 0; i < taskList.Count; i++)
            {
                NodeData nd = new NodeData();
                nd.ExecutionStatus   = TaskStatus.Inactive;
                taskList[i].NodeData = nd;
                taskList[i].OnAwake();
            }
        }
示例#22
0
    // Start is called before the first frame update
    void Start()
    {
        Debug.Log("Start Tree");
        m_Booster = gameObject.GetComponent <BoosterMove>();
        root.AddChild(selector);
        selector.AddChild(seqDead);                // seqDead 노드를 selector의 자식 노드로 연결
        selector.AddChild(seqMoving);              // seqMoving 노드를 selector의 자식 노드로 연결

        moveBooster.Booster           = m_Booster; // m_Enemy를 넣어 초기화시킴
        boosterTeamPosDetect.Booster  = m_Booster;
        boosterEnemyPosDetect.Booster = m_Booster;
        boosterIsDead.Booster         = m_Booster;

        seqMoving.AddChild(moveBooster);    //seqMoving 노드에 클래스 변수들을 자식으로 추가
        seqMoving.AddChild(boosterTeamPosDetect);
        seqMoving.AddChild(boosterEnemyPosDetect);

        seqDead.AddChild(boosterIsDead); //seqDead 노드에 클래스 변수를 자식으로 추가

        behaviorProcess = BehaviorProcess();
        StartCoroutine(behaviorProcess);
    }
示例#23
0
    // Start is called before the first frame update
    void Start()
    {
        Debug.Log("Start Tree");
        m_Healer = gameObject.GetComponent <HealerMove>();
        root.AddChild(selector);
        selector.AddChild(seqDead);           // seqDead 노드를 selector의 자식 노드로 연결
        selector.AddChild(seqMoving);         // seqMoving 노드를 selector의 자식 노드로 연결

        moveHealer.Healer         = m_Healer; // m_Enemy를 넣어 초기화시킴
        healerteamHpDetect.Healer = m_Healer;
        healermyHpDetect.Healer   = m_Healer;
        healerIsDead.Healer       = m_Healer;

        seqMoving.AddChild(moveHealer);    //seqMoving 노드에 클래스 변수들을 자식으로 추가
        seqMoving.AddChild(healerteamHpDetect);
        seqMoving.AddChild(healermyHpDetect);

        seqDead.AddChild(healerIsDead); //seqDead 노드에 클래스 변수를 자식으로 추가

        behaviorProcess = BehaviorProcess();
        StartCoroutine(behaviorProcess);
    }
示例#24
0
    // Start is called before the first frame update
    void Start()
    {
        Debug.Log("Start Tree");
        m_Enemy = gameObject.GetComponent <BastionMove>(); //BastionMove 객체
        root.AddChild(selector);                           //노드추가
        selector.AddChild(seqDead);                        //seqDead노드 추가
        selector.AddChild(seqMovingAttack);                //seqMovingAttack노드 추가

        moveForTarget.Enemy    = m_Enemy;
        bastionfindEnemy.Enemy = m_Enemy;
        m_OnAttack.Enemy       = m_Enemy;
        isBastion_Col.Enemy    = m_Enemy;
        m_IsDead.Enemy         = m_Enemy;

        seqMovingAttack.AddChild(moveForTarget);    //seqMovingAttack에 노드추가
        seqMovingAttack.AddChild(m_OnAttack);       //seqMovingAttack에 노드추가
        seqMovingAttack.AddChild(bastionfindEnemy); //seqMovingAttack에 노드추가
        seqMovingAttack.AddChild(isBastion_Col);    //seqMovingAttack에 노드추가
        seqDead.AddChild(m_IsDead);                 //seqDead에 노드추가

        behaviorProcess = BehaviorProcess();
        StartCoroutine(behaviorProcess);
    }
示例#25
0
    public override void init(Unit aUnit)
    {
        Unit unit = aUnit;

        root.AddChild(selector);
        root.AddChild(seqDead);

        selector.AddChild(seqAttack);
        selector.AddChild(seqMove);

        isEnemy.unit     = unit;
        attackEnemy.unit = unit;
        moveToEnemy.unit = unit;
        isUnitDead.unit  = unit;
        deadProcess.unit = unit;

        seqAttack.AddChild(isEnemy);
        seqAttack.AddChild(attackEnemy);
        seqMove.AddChild(moveToEnemy);
        seqDead.AddChild(isUnitDead);
        seqDead.AddChild(deadProcess);

        _behaviorProcess = behaviorProcess();
    }
示例#26
0
        /// <summary>
        /// targeting is blocked if pending spell on cursor, so this routine checks if a spell is on cursor
        /// awaiting target and if so clears
        /// </summary>
        /// <param name="finalResult">what result should be regardless of clearing spell</param>
        /// <returns>always finalResult</returns>
        private static Composite CreateClearPendingCursorSpell(RunStatus finalResult)
        {
            Sequence seq = new Sequence(
                new Action(r => Logger.WriteDebug(targetColor, "CancelPendingSpell: /cancelling Pending Spell {0}", Spell.GetPendingCursorSpell.Name)),
                new Action(ctx => Lua.DoString("SpellStopTargeting()"))
                );

            if (finalResult == RunStatus.Success)
            {
                return(new DecoratorContinue(ret => Spell.GetPendingCursorSpell != null, seq));
            }

            seq.AddChild(new ActionAlwaysFail());
            return(new Decorator(ret => Spell.GetPendingCursorSpell != null, seq));
        }
示例#27
0
    void Start()
    {
        root   = new Sequence();
        action = () => {
            Debug.Log("Test closure");

            if (P.position.x > 10)
            {
                return(Result.Success);
            }
            else
            {
                return(Result.Running);
            }
        };
        root.AddChild(new Action(action));
    }
    // Use this for initialization
    void Start()
    {
        root      = new Sequence();
        assertion = () => {
            if (i > 400)
            {
                Debug.Log("Success");
                return(true);
            }
            else
            {
                return(false);
            }
        };
        LeafAssert       asserttest = new LeafAssert(assertion);
        LoopUntilSuccess looptest   = new LoopUntilSuccess(asserttest, -1);

        root.AddChild(looptest);
    }
    public void Restart()
    {
        // Creating and setting some basic values for the blackboard
        m_Blackboard = new Blackboard();
        m_Blackboard.Trans = transform;
        m_Blackboard.StartPoint = transform.position;
        GameObject player = GameObject.FindGameObjectWithTag("Player");
        if (player) {
            m_Blackboard.Player = player.transform;
        }
        m_Blackboard.Destination = transform.position + new Vector3(10, 0, 5);
        m_Blackboard.LookAtObject = GetComponent<Looker>();

        //-------------------------------------------------------------------------
        // Higher level sequence/selectors which we'll add leaf behaviors to later
        //-------------------------------------------------------------------------
        Sequence randomMove = new Sequence();
        Sequence moveToBeacon = new Sequence();

        //----------------------------------------------------------------------------------
        // Create leaf behaviors. Should only need one of each.
        // Some of these get used often (MoveToPoint), others are specific (CheckForBeacon)
        //----------------------------------------------------------------------------------
        MoveToPoint moveToPoint = new MoveToPoint();
        PickRandomTarget pickRandomTarget = new PickRandomTarget();
        CheckForBeacon checkForBeacon = new CheckForBeacon();
        ChasePlayer chasePlayer = new ChasePlayer();
        Stunned stunned = new Stunned();

        //---------------------------------------------------------------------------------------
        // Building the subtrees.
        // Add children to subtrees in left to right order, since each AddChild is doing a push_back
        //----------------------------------------------------------------------------------------
        moveToBeacon.AddChild(checkForBeacon);
        moveToBeacon.AddChild(moveToPoint);

        randomMove.AddChild(pickRandomTarget);
        randomMove.AddChild(moveToPoint);

        //--------------------------------------------------
        // Add subtrees to the root.
        // Like before, add behaviors in left to right order
        //--------------------------------------------------
        m_Root.AddChild(stunned);
        m_Root.AddChild(moveToBeacon);
        m_Root.AddChild(chasePlayer);
        m_Root.AddChild(randomMove);

        //m_Blackboard.MovementPath = NavGraphConstructor.Instance.FindPathToLocation(m_Blackboard.Trans.position, m_Blackboard.Destination);
        //m_Blackboard.PathCurrentIdx = 0;

        //		repeat.m_Child = randomMove;
        //
        //		// Try out Chase behavior
        //		m_Chase = new Chase(moveBehavior, m_Bt);
        //		m_Flee = new Flee(moveBehavior, m_Bt);
        //
        //		List<Behavior> tree = new List<Behavior>();
        //		tree.Add(repeat);
        //		tree.Add(m_Chase);
        //
        //		root.m_Children = tree;
        //
        //		m_Bt.Start(root, this.SequenceComplete);
    }
示例#30
0
        /// <summary>
        /// targeting is blocked if pending spell on cursor, so this routine checks if a spell is on cursor
        /// awaiting target and if so clears
        /// </summary>
        /// <param name="finalResult">what result should be regardless of clearing spell</param>
        /// <returns>always finalResult</returns>
        private static Composite CreateClearPendingCursorSpell(RunStatus finalResult)
        {
            Sequence seq = new Sequence(
                new Action(r => Logger.WriteDebug(targetColor, "EnsureTarget: /cancel Pending Spell {0}", Spell.GetPendingCursorSpell.Name)),
                new Action(ctx => Lua.DoString("SpellStopTargeting()"))
                );

            if (finalResult == RunStatus.Success )
                return new DecoratorContinue(ret => Spell.GetPendingCursorSpell != null, seq);

            seq.AddChild( new ActionAlwaysFail() );
            return new Decorator(ret => Spell.GetPendingCursorSpell != null, seq);
        }
示例#31
0
    void setup_melee_ki()
    {
        root = new UtilFail();
        {
            var parallel = new ParralelNode();
            {
                var unitlfail4 = new UtilFail(true);
                {
                    var sequence01 = new Sequence();
                    {
                        var player_find = new find_player_task();
                        var unitlfail   = new UtilFail(true);
                        {
                            var sequence03 = new Sequence();
                            {
                                var selector01 = new Selector();
                                {
                                    var player_moved  = new target_moved_condition();
                                    var see_player    = new has_target_in_eyesigth_contiditon("Player");
                                    var next_waypoint = new  go_to_next_waypoint_task();
                                    selector01.AddChild(player_moved);
                                    selector01.AddChild(see_player);
                                    selector01.AddChild(next_waypoint);
                                }
                                var not_node = new Not();
                                {
                                    var see_player2 = new has_target_in_eyesigth_contiditon("Player");
                                    not_node.AddChild(see_player2);
                                }

                                sequence03.AddChild(selector01);
                                sequence03.AddChild(not_node);
                            }
                            unitlfail.AddChild(sequence03);
                        }
                        var unitlfail2 = new UtilFail(true);
                        {
                            var sequence02 = new Sequence();
                            {
                                var see_player = new has_target_in_eyesigth_contiditon("Player");
                                var charge     = new  charge_target_task("Player");
                                sequence02.AddChild(see_player);
                                sequence02.AddChild(charge);
                            }
                            unitlfail2.AddChild(sequence02);
                        }
                        sequence01.AddChild(unitlfail2);
                        sequence01.AddChild(player_find);
                        sequence01.AddChild(unitlfail);
                    }
                    unitlfail4.AddChild(sequence01);
                }
                var unitlfail3 = new UtilFail(true);
                {
                    var attack = new shoot_on_target_task("Player");
                    unitlfail3.AddChild(attack);
                }
                parallel.AddChild(unitlfail4);
                parallel.AddChild(unitlfail3);
            }
            root.AddChild(parallel);
        }
    }
示例#32
0
    void setup_normal_ki()
    {
        root = new UtilFail();
        {
            var selector00 = new Selector();
            {
                var parallel3 = new ParralelNode();
                {
                    var enough_health = new has_health_condition(health_max * 0.3f);
                    var selector      = new Selector();
                    {
                        var until_fail = new UtilFail(false);
                        {
                            var sequence = new Sequence();
                            {
                                var isnearnode   = new is_in_range(follow_range, "Player");
                                var iscoverdnode = new is_cover_blown_condition("Player");
                                var until_fail2  = new UtilFail(true);
                                var cover        = new cover_task();
                                var enough_ammo  = new has_ammo_condition(1);

                                sequence.AddChild(isnearnode);
                                sequence.AddChild(iscoverdnode);
                                sequence.AddChild(until_fail2);
                                sequence.AddChild(cover);
                                sequence.AddChild(enough_ammo);
                                {
                                    var sequence2 = new Sequence();
                                    {
                                        var dangernode = new shoot_on_me_condition();
                                        isnearnode = new is_in_range(follow_range, "Player");
                                        var shoottargetnode = new shoot_on_target_task("Player");
                                        enough_ammo = new has_ammo_condition(1);

                                        sequence2.AddChild(dangernode);
                                        sequence2.AddChild(isnearnode);
                                        sequence2.AddChild(shoottargetnode);
                                        sequence2.AddChild(enough_ammo);
                                    }
                                    until_fail2.AddChild(sequence2);
                                }
                            }
                            until_fail.AddChild(sequence);
                        }
                        selector.AddChild(until_fail);
                    }
                    {
                        var sequence1 = new Sequence();
                        {
                            var selector2 = new Selector();
                            {
                                var enough_ammo3 = new has_ammo_condition(1);
                                var sequence2    = new Sequence();
                                {
                                    var find_ammo   = new find_ammo_task();
                                    var until_fail2 = new UtilFail(true);
                                    {
                                        var next_waypoint = new go_to_next_waypoint_task();
                                        until_fail2.AddChild(next_waypoint);
                                    }
                                    sequence2.AddChild(find_ammo);
                                    sequence2.AddChild(until_fail2);
                                }
                                selector2.AddChild(enough_ammo3);
                                selector2.AddChild(sequence2);
                            }
                            var sequence3 = new Sequence();
                            {
                                var sgtask      = new search_and_go_to_cover_task(0.6f);
                                var until_fail3 = new UtilFail(true);
                                {
                                    var parralel = new ParralelNode();
                                    {
                                        var sequence4 = new Sequence();
                                        {
                                            var is_way_good   = new way_still_good_condition(0.6f);
                                            var next_waypoint = new go_to_next_waypoint_task();
                                            sequence4.AddChild(is_way_good);
                                            sequence4.AddChild(next_waypoint);
                                        }
                                        var selector3 = new Selector();
                                        {
                                            var sequence5 = new Sequence();
                                            {
                                                var isnearnode      = new is_in_range(follow_range, "Player");
                                                var shoottargetnode = new shoot_on_target_task("Player");
                                                sequence5.AddChild(isnearnode);
                                                sequence5.AddChild(shoottargetnode);
                                            }
                                            var enough_ammo4 = new has_ammo_condition(1);
                                            selector3.AddChild(sequence5);
                                            selector3.AddChild(enough_ammo4);
                                        }
                                        parralel.AddChild(sequence4);
                                        parralel.AddChild(selector3);
                                    }
                                    until_fail3.AddChild(parralel);
                                }
                                sequence3.AddChild(sgtask);
                                sequence3.AddChild(until_fail3);
                            }
                            sequence1.AddChild(selector2);
                            sequence1.AddChild(sequence3);
                        }
                        selector.AddChild(sequence1);
                    }
                    parallel3.AddChild(enough_health);
                    parallel3.AddChild(selector);
                }
                var sequence6 = new Sequence();
                {
                    var find_health = new find_heathpack_task();
                    var until_fail2 = new UtilFail(true);
                    {
                        var next_waypoint = new go_to_next_waypoint_task();
                        until_fail2.AddChild(next_waypoint);
                    }
                    sequence6.AddChild(find_health);
                    sequence6.AddChild(until_fail2);
                }
                selector00.AddChild(parallel3);
                selector00.AddChild(sequence6);
            }
            root.AddChild(selector00);
        }
    }
示例#33
0
文件: Vendoring.cs 项目: ipo/AGBA
        public Composite GenerateTownPortalBehavior()
        {
            CanRunDecoratorDelegate InTown = delegate
                                                 {
                                                     bool timeOut = (_lastTP + TPTimer < Environment.TickCount);
                if (ZetaDia.Me == null) return false;
                if (!ZetaWrap.IsInTown() && (ZetaDia.Me.CommonData.AnimationState != AnimationState.Channeling || timeOut))
                {
                    _lastTP = Environment.TickCount;
                    return true;
                }
                return false;
            };

            var pSequence = new Sequence();
            var PortHome = new Action(delegate
            {
                ZetaDia.Me.UseTownPortal();
                return RunStatus.Success;
            });
            pSequence.AddChild(PortHome);
            return new DecoratorContinue(InTown, PortHome);
        }
示例#34
0
文件: GenericCombat.cs 项目: ipo/AGBA
        public Composite GenerateAttackBehavior()
        {
            Sequence AttackSequence = new Sequence();

            AttackSequence.AddChild(new Action((ActionSucceedDelegate)DetermineBestAttackAndTarget));
            AttackSequence.AddChild(new Action((ActionSucceedDelegate)ExecuteAttack));
            AttackSequence.AddChild(new Sleep(100));

            return AttackSequence;
        }
    private Task getBTfromGenotype(BTNode subTree)
    {
        string taskName = subTree.taskName;

        if (subTree.isLeafNode())
        {
            // Actions
            if (taskName.Equals("Jump"))
            {
                Jump temp = new Jump();
#if UNITY_EDITOR || UNITY_STANDALONE_OSX || UNITY_STANDALONE_WIN
                temp.NodeData = new NodeData();
#endif
                return(temp);
            }
            else if (taskName.Equals("MoveLeftForSeconds"))
            {
                MoveLeftForSeconds temp = new MoveLeftForSeconds();
#if UNITY_EDITOR || UNITY_STANDALONE_OSX || UNITY_STANDALONE_WIN
                temp.NodeData = new NodeData();
#endif
                return(temp);
            }
            else if (taskName.Equals("MoveRightForSeconds"))
            {
                MoveRightForSeconds temp = new MoveRightForSeconds();
#if UNITY_EDITOR || UNITY_STANDALONE_OSX || UNITY_STANDALONE_WIN
                temp.NodeData = new NodeData();
#endif
                return(temp);
            }
            else if (taskName.Equals("MoveRightForDistance"))
            {
                MoveRightForDistance temp = new MoveRightForDistance();
#if UNITY_EDITOR || UNITY_STANDALONE_OSX || UNITY_STANDALONE_WIN
                temp.NodeData = new NodeData();
#endif
                return(temp);
            }
            else if (taskName.Equals("ShootBullet"))
            {
                ShootBullet temp = new ShootBullet();
#if UNITY_EDITOR || UNITY_STANDALONE_OSX || UNITY_STANDALONE_WIN
                temp.NodeData = new NodeData();
#endif
                return(temp);
            }
            else if (taskName.Equals("MoveLeftForDistance"))
            {
                MoveLeftForDistance temp = new MoveLeftForDistance();
                #if UNITY_EDITOR || UNITY_STANDALONE_OSX || UNITY_STANDALONE_WIN
                temp.NodeData = new NodeData();
#endif
                return(temp);
            }
            // TO DO add conditionals
            else if (taskName.Equals("AtEdge"))
            {
                AtEdge temp = new AtEdge();
#if UNITY_EDITOR || UNITY_STANDALONE_OSX || UNITY_STANDALONE_WIN
                temp.NodeData = new NodeData();
#endif
                return(temp);
            }
            else if (taskName.Equals("HittingWall"))
            {
                HittingWall temp = new HittingWall();
#if UNITY_EDITOR || UNITY_STANDALONE_OSX || UNITY_STANDALONE_WIN
                temp.NodeData = new NodeData();
#endif
                return(temp);
            }
            else if (taskName.Equals("LowLife"))
            {
                LowLife temp = new LowLife();
#if UNITY_EDITOR || UNITY_STANDALONE_OSX || UNITY_STANDALONE_WIN
                temp.NodeData = new NodeData();
#endif
                return(temp);
            }
            else if (taskName.Equals("PlayerInRange"))
            {
                PlayerInRange temp = new PlayerInRange();
#if UNITY_EDITOR || UNITY_STANDALONE_OSX || UNITY_STANDALONE_WIN
                temp.NodeData = new NodeData();
#endif
                return(temp);
            }
            else
            {
                Grounded temp = new Grounded();
#if UNITY_EDITOR || UNITY_STANDALONE_OSX || UNITY_STANDALONE_WIN
                temp.NodeData = new NodeData();
#endif
                return(temp);
            }
        }
        else
        {
            if (taskName.Equals("Selector"))
            {
                Selector temp = new Selector();
#if UNITY_EDITOR || UNITY_STANDALONE_OSX || UNITY_STANDALONE_WIN
                temp.NodeData = new NodeData();
#endif
                List <BTNode> children = subTree.children;
                for (int i = 0; i < children.Count; i++)
                {
                    BTNode child = children[i];
                    temp.AddChild(getBTfromGenotype(child), i);
                }
                return(temp);
            }
            else if (taskName.Equals("Sequence"))
            {
                Sequence temp = new Sequence();
#if UNITY_EDITOR || UNITY_STANDALONE_OSX || UNITY_STANDALONE_WIN
                temp.NodeData = new NodeData();
#endif
                List <BTNode> children = subTree.children;
                for (int i = 0; i < children.Count; i++)
                {
                    BTNode child = children[i];
                    temp.AddChild(getBTfromGenotype(child), i);
                }
                return(temp);
            }
            else if (taskName.Equals("RandomSelector"))
            {
                RandomSelector temp = new RandomSelector();
#if UNITY_EDITOR || UNITY_STANDALONE_OSX || UNITY_STANDALONE_WIN
                temp.NodeData = new NodeData();
#endif
                List <BTNode> children = subTree.children;
                for (int i = 0; i < children.Count; i++)
                {
                    BTNode child = children[i];
                    temp.AddChild(getBTfromGenotype(child), i);
                }
                return(temp);
            }
            else if (taskName.Equals("RandomSequence"))
            {
                RandomSequence temp = new RandomSequence();
#if UNITY_EDITOR || UNITY_STANDALONE_OSX || UNITY_STANDALONE_WIN
                temp.NodeData = new NodeData();
#endif
                List <BTNode> children = subTree.children;
                for (int i = 0; i < children.Count; i++)
                {
                    BTNode child = children[i];
                    temp.AddChild(getBTfromGenotype(child), i);
                }
                return(temp);
            }
            else
            {
                Parallel temp = new Parallel();
#if UNITY_EDITOR || UNITY_STANDALONE_OSX || UNITY_STANDALONE_WIN
                temp.NodeData = new NodeData();
#endif
                List <BTNode> children = subTree.children;
                for (int i = 0; i < children.Count; i++)
                {
                    BTNode child = children[i];
                    temp.AddChild(getBTfromGenotype(child), i);
                }
                return(temp);
            }
        }
    }