Пример #1
0
 public TopInfo(GameObject obj, TopInfoShow show, CharacterStatus statu)
 {
     charObj = obj;
     topShow = show;
     status  = statu;
     charTf  = obj.transform;
     fsm     = obj.GetComponent <AI.FSM.BaseFSM>();
 }
Пример #2
0
        protected override bool Evaluate(BaseFSM fsm)
        {
            if (fsm.targetPlayer == null)
            {
                return(false);
            }

            //玩家离开攻击范围
            if (Vector3.Distance(fsm.transform.position, fsm.targetPlayer.transform.position) > fsm.sightDistance)
            {
                return(true);
            }

            return(false);
        }
Пример #3
0
 ///<summary>条件检测</summary>
 public virtual void Reason(BaseFSM fsm)
 {
     for (int i = 0; i < triggers.Count; i++)
     {
         //如果当前条件满足,则切换到对应的状态
         if (triggers[i].HandleTrigger(fsm))
         {
             //根据条件获取状态ID
             var stateID = GetOutputState(triggers[i].triggerid);
             //通过状态机切换状态
             fsm.ChangActiveState(stateID);
             return;
         }
     }
 }
Пример #4
0
 //往返
 private void PingPongPatrolling(BaseFSM fsm)
 {
     //A   B   C   ……  A   B   C
     if (Vector3.Distance(fsm.transform.position, fsm.wayPoints[index].position) < 0.5f)
     {
         //索引反转:0    1    2   ……    1   0
         //             A    B   C   …… C   B   A
         //数组反转:0   1   2  ……  0   1   2
         Array.Reverse(fsm.wayPoints);
         index++;
         index = (index + 1) % fsm.wayPoints.Length;
     }
     //移动
     fsm.MoveToTarget(fsm.wayPoints[index].position, fsm.walkSpeed, 0);
 }
Пример #5
0
        public override bool HandleTrigger(BaseFSM basefsm)
        {
            bool b = true;

            if (basefsm.targetObj != null)
            {
                b = Vector3.Distance(basefsm.transform.position, basefsm.targetObj.position) > basefsm.sightDistance;

                if (b)
                {
                    basefsm.targetObj = null;
                }
                return(b);
            }
            return(b);
        }
        public override void Action(BaseFSM fsm)
        {
            base.Action(fsm);

            if (Vector3.Distance(fsm.transform.position, fsm.wayPoints[index]) <= 0.5)
            {
                if (index == fsm.wayPoints.Length - 1)
                {
                    fsm.isPathfindingComplete = true;
                    return;
                }
                index = (index + 1) % fsm.wayPoints.Length;
            }
            fsm.transform.LookPosition(fsm.wayPoints[index], 50);
            fsm.transform.position = Vector3.MoveTowards(fsm.transform.position, fsm.wayPoints[index], fsm.runSpeed * Time.deltaTime);
        }
Пример #7
0
        public override void Action(BaseFSM basefsm)
        {
            //1.条件需要有追逐的目标
            if (basefsm.targetObj != null)
            {
                //2.播放追逐动画
                basefsm.PlayAnimation(basefsm.animParams.Run);
                basefsm.MoveToTarget(basefsm.targetObj.position, basefsm.moveSpeed, basefsm.chState.attackDistance);

                //3.主要控制追的速度,靠近的距离==攻击距离
            }
            else
            {
                return;
            }
        }
Пример #8
0
 //单次
 private void OncePatrolling(BaseFSM fsm)
 {
     //A   B   C
     if (Vector3.Distance(fsm.transform.position, fsm.wayPoints[index].position) < 0.5f)
     {
         if (index == fsm.wayPoints.Length - 1)
         {
             //巡逻完成
             fsm.isPatrolComplete = true;
             return;
         }
         index++;
     }
     //移动
     fsm.MoveToTarget(fsm.wayPoints[index].position, fsm.walkSpeed, 0);
 }
Пример #9
0
        //检查子条件
        protected bool CheckSubTriggers(BaseFSM fsm)
        {
            if (subTriggers.Count == 0)
            {
                return(true);
            }

            for (int i = 0; i < subTriggers.Count; i++)
            {
                if (subTriggers[i].Evaluate(fsm))
                {
                    return(true);
                }
            }
            return(false);
        }
Пример #10
0
        public override bool HandleTrigger(BaseFSM basefsm)
        {
            bool b = true;

            if (basefsm.targetObj != null)
            {
                b = basefsm.targetObj.GetComponent <ARPGDemo.Character.CharacterStatus>().HP <= 0;
                if (b)
                {
                    basefsm.targetObj = null;//!!!
                }
                return(b);
            }


            return(b);
        }
Пример #11
0
 public override void Action(BaseFSM fsm)
 {
     //是否到达当前路点
     if (Vector3.Distance(fsm.transform.position, fsm.wayPath[currentIndex]) < fsm.patrolArrivalDistance)
     {
         //如果是最后一个路点
         if (currentIndex == fsm.wayPath.Length - 1)
         {
             fsm.IsPatrolComplete = true;
             return;
         }
         currentIndex++;
     }
     //移动
     fsm.transform.position = Vector3.MoveTowards(fsm.transform.position, fsm.wayPath[currentIndex], fsm.runSpeed * Time.deltaTime);
     fsm.transform.LookPosition(fsm.wayPath[currentIndex], fsm.rotateSpeed);
 }
Пример #12
0
        /// <summary>
        /// 条件检测
        /// </summary>
        public void Reason(BaseFSM fsm)
        {
            //?1.如何去将状态和对应条件关联起来
            //   状态->条件->状态
            //?2.条件列表
            //调用条件类当中的HandleTrigger

            for (int i = 0; i < triggerList.Count; i++)
            {
                //检测当前状态对应的条件是否满足
                if (triggerList[i].HandleTrigger(fsm))
                {
                    //fsm.ChangActiveState()
                    fsm.ChangeActiveState(fsmMap[triggerList[i].triggerID]);
                }
            }
        }
Пример #13
0
        //循环
        private void LoopPatrolling(BaseFSM fsm)
        {
            //A   B   C   ……  A   B   C

            if (Vector3.Distance(fsm.transform.position, fsm.wayPoints[index].position) < 0.5f)
            {
                //if (index == fsm.wayPoints.Length - 1)
                //    index = -1;
                //index++;
                //0   +   1     %   3
                //1   +   1           3
                //2   +   1           3
                index = (index + 1) % fsm.wayPoints.Length;
            }
            //移动
            fsm.MoveToTarget(fsm.wayPoints[index].position, fsm.walkSpeed, 0);
        }
Пример #14
0
        public override void Action(BaseFSM basefsm)
        {
            if (attackTime > basefsm.chState.attackSpeed)
            {
                //播放攻击动画


                basefsm.AutoUseSkill();
                attackTime = 0;
            }
            attackTime = attackTime + Time.deltaTime;
            basefsm.transform.LookAt(basefsm.targetObj);

            basefsm.transform.localEulerAngles -= new Vector3(basefsm.transform.rotation.x, 0, 0);


            basefsm.transform.localEulerAngles -= new Vector3(0, 0, basefsm.transform.rotation.z);
        }
Пример #15
0
        public override void Action(BaseFSM fsm)
        {
            base.Action(fsm);
            switch (fsm.patrolMode)
            {
            case PatrolMode.Once:
                OncePatrolling(fsm);
                break;

            case PatrolMode.Loop:
                LoopPatrolling(fsm);
                break;

            case PatrolMode.PingPong:
                PingPongPatrolling(fsm);
                break;
            }
        }
Пример #16
0
 public override void EnterState(BaseFSM fsm)
 {
     fsm.anim.SetBool(fsm.enemyStatus.animParams.idle, true);
 }
Пример #17
0
 public override void ExitState(BaseFSM fsm)
 {
     fsm.anim.SetBool(fsm.enemyStatus.animParams.idle, false);
 }
Пример #18
0
 public override void EnterState(BaseFSM fsm)
 {
     base.EnterState(fsm);
     fsm.enabled = false;//禁用状态机脚本
 }
Пример #19
0
 public override bool HandleTrigger(BaseFSM fsm)
 {
     return(fsm.chStatus.chBase.HP <= 0);
 }
 public override bool HandleTrigger(BaseFSM fsm)
 {
     return(fsm.isPathfindingComplete);
 }
 public override bool HandleTrigger(BaseFSM fsm)
 {
     return(fsm.isBeAttack);
 }
Пример #22
0
 public override void ExitState(BaseFSM fsm)
 {
 }
Пример #23
0
 public override bool HandleTrigger(BaseFSM fsm)
 {
     return(fsm.targetTF != null);
 }
Пример #24
0
 public override void Action(BaseFSM fsm)
 {
 }
Пример #25
0
 public override void OnStateExit(BaseFSM fsm)
 {
     fsm.PlayAnimation(AnimationName.idle);
 }
Пример #26
0
 public override void ExitState(BaseFSM fsm)
 {
     base.ExitState(fsm);
     fsm.GetComponentInChildren <AnimationEventBehaviour>().attackHandler -= DoFiring;
 }
Пример #27
0
 public override void EnterState(BaseFSM fsm)
 {
     base.EnterState(fsm);
     gun = fsm.GetComponent <wzx.Gun>();
     fsm.GetComponentInChildren <AnimationEventBehaviour>().attackHandler += DoFiring;
 }
Пример #28
0
 public override void EnterState(BaseFSM fsm)
 {
     fsm.enabled = false;
 }
Пример #29
0
 /// <summary>
 /// 条件的逻辑处理
 /// </summary>
 /// <returns></returns>
 public abstract bool HandleTrigger(BaseFSM fsm);
Пример #30
0
 public override void OnStateEnter(BaseFSM fsm)
 {
     fsm.PlayAnimation(AnimationName.beAttack);
 }