private void TurretQuery(Entity entity,
                                 ref VirtualArmy.Component army,
                                 ref TurretHub.Component turret,
                                 ref BaseUnitStatus.Component status)
        {
            if (status.State != UnitState.Alive)
            {
                return;
            }

            var trans = EntityManager.GetComponentObject <Transform>(entity);
            var pos   = trans.position;

            var unit = getNearestPlayer(pos, HexDictionary.HexEdgeLength, selfId: null);

            if (unit == null)
            {
                if (army.IsActive == false)
                {
                    VirtualizeTurrests(ref army, turret.TurretsDatas);
                }
            }
            else
            {
                if (army.IsActive)
                {
                    RealizeTurrets(ref army, turret.TurretsDatas);
                }
                else
                {
                    AlarmTurrets(ref army, turret.TurretsDatas);
                }
            }
        }
        private void RealizeTurrets(ref VirtualArmy.Component army, Dictionary <EntityId, TurretInfo> turretsDatas)
        {
            army.IsActive = false;
            var inter = IntervalCheckerInitializer.InitializedChecker(MovementDictionary.AlarmInter);

            UpdateLastChecked(ref inter);
            army.AlarmInter = inter;
            SendSleepOrdersToTurret(turretsDatas, SleepOrderType.WakeUp);
        }
        private void AlarmTurrets(ref VirtualArmy.Component army, Dictionary <EntityId, TurretInfo> turrets)
        {
            var inter = army.AlarmInter;

            if (CheckTime(ref inter) == false)
            {
                return;
            }

            army.AlarmInter = inter;
            foreach (var kvp in turrets)
            {
                SendSleepOrder(kvp.Key, SleepOrderType.WakeUp);
            }
        }
        private void AlarmUnits(ref VirtualArmy.Component army, List <EntityId> followers)
        {
            var inter = army.AlarmInter;

            if (CheckTime(ref inter) == false)
            {
                return;
            }

            UnityEngine.Profiling.Profiler.BeginSample("AlarmUnits");
            army.AlarmInter = inter;
            foreach (var id in followers)
            {
                SendSleepOrder(id, SleepOrderType.WakeUp);
            }
            UnityEngine.Profiling.Profiler.EndSample();
        }
        private void VirtualizeUnits(ref VirtualArmy.Component army, Transform trans, List <EntityId> followers)
        {
            UnityEngine.Profiling.Profiler.BeginSample("VirtualizeUnits");
            army.IsActive = true;
            var units = army.SimpleUnits;

            units.Clear();

            var inverse = Quaternion.Inverse(trans.rotation);
            var pos     = trans.position;

            foreach (var id in followers)
            {
                Transform t = null;
                if (TryGetComponentObject(id, out t) == false)
                {
                    continue;
                }

                Rigidbody r = null;
                if (TryGetComponentObject(id, out r))
                {
                    r.Sleep();
                }

                var simple = new SimpleUnit();

                simple.RelativePos = (inverse * (t.position - pos)).ToFixedPointVector3();
                simple.RelativeRot = (t.rotation * inverse).ToCompressedQuaternion();

                units.Add(id, simple);

                SendSleepOrder(id, SleepOrderType.Sleep);
            }

            army.SimpleUnits = units;
            var inter = IntervalCheckerInitializer.InitializedChecker(MovementDictionary.AlarmInter);

            UpdateLastChecked(ref inter);
            army.AlarmInter = inter;
            UnityEngine.Profiling.Profiler.EndSample();
        }
        private void RealizeUnits(ref VirtualArmy.Component army, Transform trans)
        {
            UnityEngine.Profiling.Profiler.BeginSample("RealizeUnits");
            army.IsActive = false;
            SyncTroop(army.SimpleUnits, trans);

            foreach (var kvp in army.SimpleUnits)
            {
                Rigidbody r = null;
                if (TryGetComponentObject(kvp.Key, out r))
                {
                    r.WakeUp();
                }

                SendSleepOrder(kvp.Key, SleepOrderType.WakeUp);
            }

            army.SimpleUnits.Clear();
            UnityEngine.Profiling.Profiler.EndSample();
        }
        private void CommanderQuery(Entity entity,
                                    ref VirtualArmy.Component army,
                                    ref CommanderTeam.Component team,
                                    ref BaseUnitStatus.Component status)
        {
            if (status.State != UnitState.Alive)
            {
                return;
            }

            var trans = EntityManager.GetComponentObject <Transform>(entity);
            var pos   = trans.position;

            var unit = getNearestPlayer(pos, HexDictionary.HexEdgeLength, selfId: null);

            if (unit == null)
            {
                var followers = team.FollowerInfo.Followers;
                if (army.IsActive && army.SimpleUnits.Count == followers.Count)
                {
                    SyncTroop(army.SimpleUnits, trans);
                }
                else
                {
                    VirtualizeUnits(ref army, trans, team.FollowerInfo.Followers);
                }
            }
            else
            {
                if (army.IsActive)
                {
                    RealizeUnits(ref army, trans);
                }
                else
                {
                    AlarmUnits(ref army, team.FollowerInfo.Followers);
                }
            }
        }
 private void VirtualizeTurrests(ref VirtualArmy.Component army, Dictionary <EntityId, TurretInfo> turretsDatas)
 {
     army.IsActive = true;
     SendSleepOrdersToTurret(turretsDatas, SleepOrderType.Sleep);
 }