Esempio n. 1
0
        public float tolerance = 1f;      // 相对自己停止距离的容差

        public override void Act(StateController controller)
        {
            // 有目标、没有正在计算路程、眼前捕获到敌人(避免拐角处两个卡死)、两者距离在停留范围内
            if (controller.instancePrefs.Contains(CommonCode.ChaseEnemy) &&
                !controller.navMeshAgent.pathPending &&
                (bool)controller.statePrefs[CommonCode.CatchEnemy] == true &&
                GameMathf.TwoPosInRange(((Transform)controller.instancePrefs[CommonCode.ChaseEnemy]).position, controller.transform.position, controller.navMeshAgent.stoppingDistance - tolerance))
            {
                controller.rigidbodySelf.position += -1 * controller.transform.forward.normalized * controller.navMeshAgent.speed * Time.deltaTime;
            }
        }
        public float distance = 30f;                //停止追逐的最远距离

        public override bool Decide(StateController controller)
        {
            if (!controller.instancePrefs.Contains(CommonCode.ChaseEnemy))
            {
                controller.UpdateNextWayPoint(true);
                return(true);
            }
            if (!GameMathf.TwoPosInRange(controller.transform.position, ((Transform)controller.instancePrefs[CommonCode.ChaseEnemy]).position, distance))
            {
                controller.instancePrefs.Remove(CommonCode.ChaseEnemy);
                controller.UpdateNextWayPoint(true);
                return(true);
            }
            return(false);
        }
Esempio n. 3
0
        public override void Act(StateController controller)
        {
            controller.statePrefs.AddIfNotContains(CommonCode.SoucePos, controller.transform.position);
            controller.statePrefs.AddIfNotContains(CommonCode.FrozenActionCD, new CountDownTimer(checkTime, true));

            // 更新倒计时
            if (!((CountDownTimer)controller.statePrefs[CommonCode.FrozenActionCD]).IsTimeUp)
            {
                return;
            }

            // 判断如果过了检测时间后,当前位置和之前位置的距离是否小于限定距离

            if (GameMathf.TwoPosInRange((Vector3)controller.statePrefs[CommonCode.SoucePos], controller.transform.position, maxRadius))
            {
                controller.UpdateNextWayPoint(true);
            }

            controller.statePrefs[CommonCode.SoucePos] = controller.transform.position;
        }
Esempio n. 4
0
        /// <summary>
        /// 查找半径范围内所有符合条件的对象,并发送信息
        /// </summary>
        private IEnumerator FindAndSend(StateController controller, SignalExpand signal)
        {
            while (!signal.Timer.IsTimeUp)
            {
                for (int i = 0; i < AllPlayerManager.Instance.Count; i++)
                {
                    if (AllPlayerManager.Instance[i] != controller.playerManager &&
                        AllPlayerManager.Instance[i].gameObject.activeInHierarchy &&
                        GameMathf.TwoPosInRange(controller.transform.position, AllPlayerManager.Instance[i].transform.position, signal.CurrentPercent * radius))
                    {
                        TankManager target = AllPlayerManager.Instance[i] as TankManager;
                        if (target == null)
                        {
                            continue;
                        }
                        switch (acceptType)
                        {
                        case AcceptType.All:
                            break;

                        case AcceptType.Teammates:
                            if (AllPlayerManager.Instance[i].Team != controller.Team)
                            {
                                continue;
                            }
                            break;

                        case AcceptType.Enemy:
                            if (AllPlayerManager.Instance[i].Team == controller.Team)
                            {
                                continue;
                            }
                            break;
                        }
                        target.stateController.statePrefs.AddIfNotContains(CommonCode.BroadcastMessage, messages);
                    }
                }
                yield return(null);
            }
        }