Exemplo n.º 1
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);
    }
Exemplo n.º 2
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();
            }
        }
Exemplo n.º 3
0
    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);
            }
        }
    }