示例#1
0
        protected override int onExecute(TBTWorkingData wData)
        {
            AIEntityWorkingData thisData   = wData.As <AIEntityWorkingData>();
            Vector3             targetPos  = TMathUtils.Vector3ZeroY(thisData.entity.GetBBValue <Vector3>(AIEntity.BBKEY_NEXTMOVINGPOSITION, Vector3.zero));
            Vector3             currentPos = TMathUtils.Vector3ZeroY(thisData.entityTF.position);

            if (TMathUtils.IsZero((targetPos - currentPos).sqrMagnitude))
            {
                return(TBTRunningStatus.FINISHED);
            }
            else
            {
                Vector3 toTarget   = TMathUtils.GetDirection2D(targetPos, currentPos);
                Vector3 curFacing  = thisData.entityTF.forward;
                float   dotV       = Vector3.Dot(toTarget, curFacing);
                float   deltaAngle = Mathf.Acos(Mathf.Clamp(dotV, -1f, 1f));
                if (deltaAngle < 0.1f)
                {
                    thisData.entityTF.forward = toTarget;
                    return(TBTRunningStatus.FINISHED);
                }
                else
                {
                    Vector3 crossV      = Vector3.Cross(curFacing, toTarget);
                    float   angleToTurn = Mathf.Min(3f * thisData.deltaTime, deltaAngle);
                    if (crossV.y < 0)
                    {
                        angleToTurn = -angleToTurn;
                    }
                    thisData.entityTF.Rotate(Vector3.up, angleToTurn * Mathf.Rad2Deg, Space.World);
                }
            }
            return(TBTRunningStatus.EXECUTING);
        }
示例#2
0
        protected override int onExecute(TBTWorkingData wData)
        {
            AIEntityWorkingData thisData   = wData.As <AIEntityWorkingData>();
            Vector3             targetPos  = TMathUtils.Vector3ZeroY(thisData.entity.GetBBValue <Vector3>(AIEntity.BBKEY_NEXTMOVINGPOSITION, Vector3.zero));
            Vector3             currentPos = TMathUtils.Vector3ZeroY(thisData.entityTF.position);
            float distToTarget             = TMathUtils.GetDistance2D(targetPos, currentPos);

            if (distToTarget < 1f)
            {
                //thisData.entityTF.position = targetPos;
                thisData.entity.EnabledAutoMove(false);
                return(TBTRunningStatus.FINISHED);
            }
            else
            {
                int ret = TBTRunningStatus.EXECUTING;
//                Vector3 toTarget = TMathUtils.GetDirection2D(targetPos, currentPos);
//                float movingStep = 0.5f * thisData.deltaTime;
//                if(movingStep > distToTarget)
//                {
//                    movingStep = distToTarget;
//                    ret = TBTRunningStatus.FINISHED;
//                }
//                thisData.entityTF.position = thisData.entityTF.position + toTarget * movingStep;
                thisData.entity.AutoMove(targetPos);

                return(ret);
            }
        }
示例#3
0
        public override bool IsTrue(TBTWorkingData wData)
        {
            AIEntityWorkingData thisData   = wData.As <AIEntityWorkingData>();
            Vector3             targetPos  = TMathUtils.Vector3ZeroY(thisData.entity.GetBBValue <Vector3>(AIEntity.BBKEY_NEXTMOVINGPOSITION, Vector3.zero));
            Vector3             currentPos = TMathUtils.Vector3ZeroY(thisData.entityTF.position);

            return(TMathUtils.GetDistance2D(targetPos, currentPos) < 1f);
        }
示例#4
0
        protected override void onEnter(TBTWorkingData wData)
        {
            AIEntityWorkingData thisData = wData.As <AIEntityWorkingData>();

            if (thisData.entityAnimator)
            {
                thisData.entityAnimator.CrossFade("walk", 0.2f);
            }
        }
示例#5
0
        protected override void onEnter(TBTWorkingData wData)
        {
            AIEntityWorkingData thisData = wData.As <AIEntityWorkingData>();
            UserContextData     userData = getUserContexData <UserContextData>(wData);

            userData.attackingTime = DEFAULT_WAITING_TIME;
            if (thisData.entityAnimator)
            {
                thisData.entityAnimator.CrossFade("attack", 0.2f);
            }
        }
示例#6
0
        protected override int onExecute(TBTWorkingData wData)
        {
            AIEntityWorkingData thisData = wData.As <AIEntityWorkingData>();
            UserContextData     userData = getUserContexData <UserContextData>(wData);

            if (userData.attackingTime > 0)
            {
                userData.attackingTime -= thisData.deltaTime;
                if (userData.attackingTime <= 0)
                {
                    if (thisData.entityAnimator)
                    {
                        thisData.entityAnimator.CrossFade(ENDING_ANIM[Random.Range(0, ENDING_ANIM.Length)], 0.2f);
                    }
                    return(TBTRunningStatus.FINISHED);
                }
            }
            return(TBTRunningStatus.EXECUTING);
        }
示例#7
0
        public AIEntity Init(GameObject targetObj)
        {
            _behaviorTree = AIEntityBehaviorTreeFactory.GetBehaviorTreeAction();

            _behaviorWorkingData                = new AIEntityWorkingData();
            _behaviorWorkingData.entity         = this;
            _behaviorWorkingData.entityTF       = this.transform;
            _behaviorWorkingData.entityAnimator = GetComponent <Animator>();

            _blackboard = new TBlackBoard();

            _nextTimeToGenMovingTarget = 0;

            _targetDummyObject = targetObj;

            _navagent = GetComponent <UnityEngine.AI.NavMeshAgent>();


            return(this);
        }