Пример #1
0
        public override void Action(FSMBase fsm)
        {
            base.Action(fsm);

            //如果到达目标点
            if (Vector3.Distance(fsm.transform.position, fsm.wapPoints[index].position) <= fsm.patrolArrivalDistance)
            {
                //最后一个路点
                if (index == fsm.wapPoints.Length - 1)
                {
                    switch (fsm.patrolMode)
                    {
                    case PatrolMode.Once:
                        fsm.isPatrolComplete = true;    //完成巡逻
                        return;

                    case PatrolMode.PingPong:
                        Array.Reverse(fsm.wapPoints);
                        break;
                    }
                }
                //索引增加
                index = (index + 1) % fsm.wapPoints.Length;
            }
            //移动
            fsm.MoveToTarget(fsm.wapPoints[index].position, fsm.patrolSpeed, fsm.patrolArrivalDistance);
            //旋转
            Vector3 lookPos = fsm.wapPoints[index].position;

            lookPos.y = fsm.transform.position.y;
            fsm.transform.LookPosition(lookPos, fsm.rotateSpeed);
        }
 public override void EnterState(FSMBase fsm)
 {
     base.EnterState(fsm);
     Debug.Log("闲置");
     //播放动画
     //fsm.anim.SetBool(fsm.chStatus.chparams.idle, true);
 }
Пример #3
0
 public override void ExitState(FSMBase fsm)
 {
     base.ExitState(fsm);
     //停止移动
     fsm.StopMove();
     fsm.anim.SetBool(fsm.status.chPrams.move, false);
 }
Пример #4
0
 public override void ActionState(FSMBase fsm)
 {
     base.ActionState(fsm);
     Debug.DrawLine(fsm.transform.position, fsm.targetTF.position);
     //fsm.MoveToTarget(fsm.targetTF.position, fsm.status.attackDistance - 0.1f, fsm.runSpeed);
     fsm.MoveToTarget(fsm.targetTF, fsm.status.attackDistance - 0.1f, fsm.runSpeed);
 }
Пример #5
0
 public override void EnterState(FSMBase fsm)
 {
     base.EnterState(fsm);
     Debug.Log("进入玩家死亡状态");
     fsm.chAnim.SetBool(fsm.chStatus.animParams.Death, false);
     fsm.enabled = false;//禁用状态机组件
 }
 public override bool HandleTrigger(FSMBase fsm)
 {
     if (fsm.targetTF == null)
     {
         return(false);
     }
     return(Vector3.Distance(fsm.targetTF.position, fsm.transform.position) > fsm.status.attackDistance);
 }
 public override bool HandleTrigger(FSMBase fsm)
 {
     if (fsm.targetTF == null)
     {
         return(false);
     }
     return(fsm.targetTF.GetComponent <Stats>().health <= 0);
 }
Пример #8
0
 public override bool HandleTrigger(FSMBase fsm)
 {
     foreach (var item in fsm.allTargetTF)
     {
         return(Vector3.Distance(item.Value.position, fsm.transform.position) < fsm.minDistance);
     }
     return(false);
 }
Пример #9
0
 public override void ActionState(FSMBase fsm)
 {
     base.ActionState(fsm);
     if (attackTime <= Time.time)
     {
         fsm.anim.SetBool(fsm.status.chPrams.attack, true);
         attackTime = Time.time + fsm.status.attackInterval;
     }
 }
 private void LoopPatrolling(FSMBase fsm)
 {
     if (fsm.wayPoints[index].GetComponent <Collider2D>().OverlapPoint(fsm.transform.position))
     {
         index = (index + 1) % fsm.wayPoints.Length;
     }
     fsm.canMove = true;
     fsm.MoveToTarget(fsm.wayPoints[index].position, 0, fsm.walkSpeed);
 }
Пример #11
0
 public override bool HandleTrigger(FSMBase fsm)
 {
     if (!fsm.targetTF)
     {
         return(false);
     }
     return(Vector3.Distance(fsm.transform.position, fsm.targetTF.position) >= fsm.chStatus.attackDistance &&
            !fsm.chStatus.IsAttacking());
 }
Пример #12
0
 public override void Action(FSMBase fsm)
 {
     base.Action(fsm);
     if (fsm.targetTF == null)
     {
         return;
     }
     fsm.MoveToTarget(fsm.targetTF.position, fsm.moveSpeed, fsm.chStatus.attackDistance);
 }
Пример #13
0
 private void PatrolLoop(FSMBase fsm)
 {
     //循环 A B C A B C
     if (Vector3.Distance(fsm.transform.position, fsm.wayPoints[index].position) <= 0.5f)
     {
         index = (index + 1) % fsm.wayPoints.Length;
     }
     //fsm.MoveToTarget(fsm.wayPoints[index].position, 0, fsm.walkSpeed);
     fsm.MoveToTarget(fsm.wayPoints[index], 0, fsm.walkSpeed);
 }
Пример #14
0
 public override void EnterState(FSMBase fsm)
 {
     base.EnterState(fsm);
     Debug.Log("进入追逐状态");
     if (fsm.targetTF == null)
     {
         return;
     }
     fsm.chAnim.SetBool(fsm.chStatus.animParams.Run, true);
 }
Пример #15
0
 public override void ActionState(FSMBase fsm)
 {
     base.ActionState(fsm);
     Debug.DrawLine(fsm.transform.position, fsm.targetTF.position);
     if (attackTime <= Time.time)
     {
         fsm.LookRotation(fsm.targetTF.position - fsm.transform.position);
         fsm.anim.SetBool(fsm.status.chPrams.attack, true);
         attackTime = Time.time + fsm.status.attackInterval;
     }
 }
Пример #16
0
 /// <summary>
 /// 检测是否要切换状态
 /// </summary>
 /// <param name="fsm">使用的状态机</param>
 public void Reason(FSMBase fsm)
 {
     for (int i = 0; i < Triggers.Count; ++i)
     {
         if (Triggers[i].HandleTrigger(fsm))
         {
             FSMStateID stateID = map[Triggers[i].TriggerID];
             fsm.ChangeActiveState(stateID);
             return;
         }
     }
 }
Пример #17
0
 /// <summary>
 /// 条件检测(状态机每帧调用)
 /// </summary>
 public void Reason(FSMBase fsm)
 {
     foreach (var item in triggerList)
     {
         if (item.HandleTrigger(fsm))
         {
             FSMStateID stateId = map[item.TriggerID];
             //通过状态机切换状态
             fsm.ChangeState(stateId);
             return;
         }
     }
 }
 private void OncePatrolling(FSMBase fsm)
 {
     if (fsm.wayPoints[index].GetComponent <Collider2D>().OverlapPoint(fsm.transform.position))
     {
         if (index == fsm.wayPoints.Length - 1)
         {
             fsm.isPatrolComplete = true;
             return;
         }
         index++;
     }
     fsm.canMove = true;
     fsm.MoveToTarget(fsm.wayPoints[index].position, 0, fsm.walkSpeed);
 }
Пример #19
0
 //检测当前状态的条件是否满足
 public void Reason(FSMBase fsm)
 {
     for (int i = 0; i < triggers.Count; i++)
     {
         //发现条件满足
         if (triggers[i].HandleTrigger(fsm))
         {
             //从映射表中获取输出状态
             FSMStateID stateID = map[triggers[i].TriggerID];
             //切换状态
             fsm.ChangeActiveState(stateID);
             return;
         }
     }
 }
Пример #20
0
        private void PatrolOnce(FSMBase fsm)
        {
            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, 0, fsm.walkSpeed);
            fsm.MoveToTarget(fsm.wayPoints[index], 0, fsm.walkSpeed);
        }
Пример #21
0
        private void PatrolOnlyOnce(FSMBase fsm)
        {
            int randomIndex;

            while (true)
            {
                randomIndex = UnityEngine.Random.Range(0, fsm.wayPoints.Length);
                if (currentIndex != randomIndex)
                {
                    break;
                }
            }
            currentIndex = randomIndex;
            fsm.MoveToTarget(fsm.wayPoints[currentIndex], 0, fsm.walkSpeed);
        }
Пример #22
0
 /// <summary>
 /// *检测当前状态是否满足
 /// </summary>
 public void Reason(FSMBase fsm)
 {
     for (int i = 0; i < Triggers.Count; i++)
     {
         //如果返回值为true
         if (Triggers[i].HandleTrigger(fsm))
         {
             //从表中获取输出状态
             FSMStateID stateID = map[Triggers[i].TriggerID];
             //切换状态
             fsm.ChangeActiveState(stateID);
             return;
         }
     }
 }
Пример #23
0
 private void PatrolPingPong(FSMBase fsm)
 {
     //—— 往返 A B C B A
     if (Vector3.Distance(fsm.transform.position, fsm.wayPoints[index].position) <= 0.5f)
     {
         if (index == fsm.wayPoints.Length - 1)
         {
             //数组反转
             Array.Reverse(fsm.wayPoints);
             index++;
         }
         index = (index + 1) % fsm.wayPoints.Length;
     }
     //fsm.MoveToTarget(fsm.wayPoints[index].position, 0, fsm.walkSpeed);
     fsm.MoveToTarget(fsm.wayPoints[index], 0, fsm.walkSpeed);
 }
Пример #24
0
        public override bool HandleTrigger(FSMBase fsm)
        {
            Transform tf = fsm.targetTF;

            if (!tf)
            {
                return(false);
            }
            CharacterStatus cs = tf.GetComponent <CharacterStatus>();

            if (!cs)
            {
                return(false);
            }
            return(cs.HP <= 0);
        }
        public override bool HandleTrigger(FSMBase fsm)
        {   //
            if (fsm.targetTF == null)
            {
                return(false);
            }
            rayDirection3 = fsm.targetTF.position - fsm.transform.position;
            LayerMask    mask = 1 << 9 | 1 << 8;
            RaycastHit2D hit  = Physics2D.Raycast(fsm.transform.position, rayDirection3, 115, mask);

            if (hit)
            {
                //Debug.Log("检测到物体" + hit.collider.name);
                isPlayer3 = hit.transform.CompareTag("Player");
            }
            return(isPlayer3 && Vector3.Distance(fsm.transform.position, fsm.targetTF.position) <= fsm.attackDistance);
        }
Пример #26
0
        public override bool HandleTrigger(FSMBase fsm)
        {
            if (!fsm.targetTF)
            {
                return(false);
            }
            //Debug.Log("发现player");
            rayDirection = fsm.targetTF.position - fsm.transform.position;
            LayerMask    mask = 1 << 9 | 1 << 8;
            RaycastHit2D hit  = Physics2D.Raycast(fsm.transform.position, rayDirection, 115, mask);

            if (hit)
            {
                //Debug.Log("检测到物体" + hit.collider.name);
                isPlayer = hit.transform.CompareTag("Player");
            }
            return(isPlayer);
        }
        public override bool HandleTrigger(FSMBase fsm)
        {
            if (!fsm.targetTF)
            {
                return(false);
            }

            rayDirection2 = fsm.targetTF.position - fsm.transform.position;
            LayerMask    mask2 = 1 << 9 | 1 << 8;
            RaycastHit2D hit   = Physics2D.Raycast(fsm.transform.position, rayDirection2, 150, mask2);

            if (hit)
            {
                isPlayer2 = hit.transform.CompareTag("Player");
            }
            ischange2 = !isPlayer2 || (Vector3.Distance(fsm.transform.position, fsm.targetTF.position) > fsm.attackDistance);
            return(ischange2);
        }
Пример #28
0
 public override void Action(FSMBase fsm)
 {
     base.Action(fsm);
     if (!fsm.targetTF)
     {
         return;
     }
     //如果到了攻击时间
     if (attackTime <= Time.time)
     {
         //随机攻击
         fsm.skillSystem.UseRandomSkill();
         //设置下次攻击时间
         attackTime = Time.time + fsm.chStatus.attackInterval;
         //朝向目标
     }
     fsm.transform.LookPosition(fsm.targetTF.position, 30);
 }
Пример #29
0
        public override void ActionState(FSMBase fsm)
        {
            base.ActionState(fsm);
            //fsm.timer += Time.deltaTime;
            fsm.anim.SetBool("isAttack", true);

            //if (fsm.timer > fsm.holdingTime && !fsm.isAttacking)
            //{
            //    fsm.isAttacking = true;
            //    //Vector3 direction = fsm.targetTF.position - fsm.transform.position;
            //    //fsm.shootingBehavior.Shoot(direction);
            //}
            //else if (fsm.timer > fsm.attackTime && fsm.isAttacking)
            //{
            //    fsm.timer = 0;
            //    fsm.isAttacking = false;
            //    fsm.anim.SetBool("isAttack", false);
            //}
        }
        public override void ActionState(FSMBase fsm)
        {
            base.ActionState(fsm);

            switch (fsm.patrolMode)
            {
            case PatrolMode.Once:
                OncePatrolling(fsm);
                break;

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

            case PatrolMode.PingPong:
                PingPongPatrolling(fsm);
                break;
            }
        }