Example #1
0
    /// <summary>
    /// 筛选目标列表
    /// </summary>
    protected override void FiltrateTheTargets(float delta)
    {
        m_LockedTargetList.Clear();
        if (m_State == GunState.Fire)
        {
            BaseEntity fentiy = GetForwardEntity();//屏幕中心单位
            if (IsThereSurplusMissile() && fentiy != null)
            {
                TryToLockThisTarget(fentiy.EntityId());
            }
            //清除不在虚拟相机内的单位
            ClearAlreadyNoInVirtualCameraTargets();

            //更新锁定中的单位状态
            UpdateTheLocking(delta);

            //设置技能需要的目标列表结构数据
            SetSkillTargets();
        }
        // 通知UI当前锁定的所有目标
        PlayerMissileWeaponTargetSelectionInfo targetInfoNotify = MessageSingleton.Get <PlayerMissileWeaponTargetSelectionInfo>();

        targetInfoNotify.TargeList = m_LockTargeMap;
        GameFacade.Instance.SendNotification(NotificationName.PlayerMissileWeaponTargetSelection, targetInfoNotify);
    }
    /// <summary>
    /// 当目标列表改变时
    /// </summary>
    /// <param name="msg">PlayerMissileWeaponTargetSelectionInfo</param>
    private void OnTargetListChanged(PlayerMissileWeaponTargetSelectionInfo msg)
    {
        if (msg.TargeList == null || msg.TargeList.Count == 0)
        {
            if (m_CurrentTargetListClearTime <= 0 && m_CurrentTargetList.Count > 0)
            {
                int selectedCount = 0;
                foreach (var info in m_CurrentTargetList.Values)
                {
                    if (info.LockTimes > 0)
                        selectedCount++;
                }

                if (selectedCount > 0)
                {
                    m_CurrentTargetListClearTime = Time.time + 3.0f;
                    foreach (var info in m_CurrentTargetList.Values)
                    {
                        info.LockState = WeaponAndCrossSight_Missile.TargetLockState.Locked;
                    }
                }
                else
                    m_CurrentTargetList.Clear();
            }
        }
        else
        {
            m_CurrentTargetList.Clear();
            foreach (ulong entityId in msg.TargeList.Keys)
            {
                m_CurrentTargetList.Add(entityId, msg.TargeList[entityId]);
            }
        }
    }
Example #3
0
    /// <summary>
    /// 武器技能释放结束
    /// </summary>
    public override void WeaponSkillFinish()
    {
        base.WeaponSkillFinish();
        m_LockTargeMap.Clear();

        // 通知UI当前锁定的所有目标
        PlayerMissileWeaponTargetSelectionInfo targetInfoNotify = MessageSingleton.Get <PlayerMissileWeaponTargetSelectionInfo>();

        targetInfoNotify.TargeList = m_LockTargeMap;
        GameFacade.Instance.SendNotification(NotificationName.PlayerMissileWeaponTargetSelection, targetInfoNotify);
    }
Example #4
0
    /// <summary>
    /// 检测是否已经选中了新的目标
    /// 更新已经锁定了的目标的锁定状态
    /// </summary>
    /// <param name="deltaTime"></param>
    public override void OnUpdate(float deltaTime)
    {
        base.OnUpdate(deltaTime);

        //  调试代码
        if (Input.GetKeyDown(KeyCode.Keypad0))
        {
            ResetWeaponRuntimeData();
            Debug.LogError("清理武器导弹状态");
        }

        TranslateUniformParamToWeaponParam();
        // 调试代码

        List <SpacecraftEntity> targetList = new List <SpacecraftEntity>();

        // 锁定多目标, 同时让他们描红的逻辑, 还需要仔细考虑. 这里暂时先注释. 选择目标把它描红的逻辑让HUD执行
        //bool targetSelected = GetAllEntitySelectedByVirtualCamera(ref targetList);
        //NotifyHUDTargetSelected(targetSelected ? targetList[0] : null);

        // 尝试锁定新的目标
        if (m_State == State.Lock && IsThereSurplusMissile())
        {
            for (int iTarget = 0; iTarget < targetList.Count; iTarget++)
            {
                TryToLockThisTarget(targetList[iTarget]);
            }
        }

        PlayerMissileWeaponTargetSelectionInfo targetInfoNotify = MessageSingleton.Get <PlayerMissileWeaponTargetSelectionInfo>();

        // FIXME. 动态内存分配
        //targetInfoNotify.TargeList = m_LockTargeMap;
        GameFacade.Instance.SendNotification(NotificationName.PlayerMissileWeaponTargetSelection, targetInfoNotify);

        // 更新已有的目标
        // iterate all locking and locked target
        // locking:
        //		once countdown finished, set target state to Locked
        // locking and locked:
        //		if target is out of range / dead, unlock target
        List <SpacecraftEntity> cancelLockList = new List <SpacecraftEntity>();

        foreach (var pair in m_LockTargeMap)
        {
            SpacecraftEntity targetEntity   = pair.Key;
            TargetLockInfo   targetLockInfo = pair.Value;
            if (targetLockInfo.LockState == TargetLockState.Locking)
            {
                if (targetLockInfo.LockTimeRemaining <= 0f)
                {
                    targetLockInfo.LockState         = TargetLockState.Locked;
                    targetLockInfo.LockTimeRemaining = 0f;
                    targetLockInfo.LockTimes++;

                    SLog("目标锁定完成. {0}", targetEntity.name);
                }
                else
                {
                    targetLockInfo.LockTimeRemaining -= deltaTime;
                }
            }

            // UNDONE, 检查所有目标是不是已经超出了射程或者已经死了. 如果是的话, 就接触锁定
            if (targetEntity == null || targetEntity.IsDead())
            {
                cancelLockList.Add(targetEntity);
            }
        }

        // 接触已经不可用的目标的锁定
        for (int iEntity = 0; iEntity < cancelLockList.Count; iEntity++)
        {
            m_LockTargeMap.Remove(cancelLockList[iEntity]);
            SLog("目标因为死亡或者超出视野而失去锁定. {0}", iEntity);
        }
    }
    /// <summary>
    /// 检测是否已经选中了新的目标
    /// 更新已经锁定了的目标的锁定状态
    /// </summary>
    /// <param name="deltaTime"></param>
    public override void OnUpdate(float deltaTime)
    {
        base.OnUpdate(deltaTime);

        //  调试代码
        if (Input.GetKeyDown(KeyCode.Keypad0))
        {
            ResetWeaponRuntimeData();
            Debug.LogError("清理武器导弹状态");
        }
        TranslateUniformParamToWeaponParam();
        //  调试代码

        if (m_State == State.Lock)
        {
            SpacecraftEntity newTarget = GetTargetSelectedByCenterRay();

            //NotifyHUDTargetSelected(newTarget);

            // 尝试锁定新的目标
            if (IsThereSurplusMissile())
            {
                TryToLockThisTarget(newTarget);
            }

            // 清理已经出框的目标
            ClearLockingTargetWhichIsNotInLockingRect();

            // 更新已有的目标
            // iterate all locking and locked target
            // locking:
            //		once countdown finished, set target state to Locked
            // locking and locked:
            //		if target is out of range / dead, unlock target
            List <SpacecraftEntity> cancelLockList = new List <SpacecraftEntity>();
            foreach (var pair in m_LockTargeMap)
            {
                SpacecraftEntity targetEntity = pair.Key;

                // UNDONE, 检查所有目标是不是已经超出了射程或者已经死了. 如果是的话, 就接触锁定
                if (targetEntity == null || targetEntity.IsDead())
                {
                    cancelLockList.Add(targetEntity);
                    continue;
                }

                TargetLockInfo targetLockInfo = pair.Value;
                if (targetLockInfo.LockState == TargetLockState.Locking && IsThereSurplusMissile())
                {
                    if (IsThereSurplusMissile()) //还不够
                    {
                        if (targetLockInfo.LockTimeRemaining <= 0f)
                        {
                            targetLockInfo.LockState         = TargetLockState.Locked;
                            targetLockInfo.LockTimeRemaining = 0f;
                            targetLockInfo.LockTimes++;

                            SLog("目标锁定完成. {0}", targetEntity.name);
                        }
                        else
                        {
                            targetLockInfo.LockTimeRemaining -= deltaTime;
                        }
                    }
                    else //够了,将未完成转圈的
                    {
                        if (targetLockInfo.LockTimes == 0)
                        {
                            cancelLockList.Add(targetEntity);
                        }
                        else
                        {
                            targetLockInfo.LockState         = BattleWeapon_Missile.TargetLockState.Locked;
                            targetLockInfo.LockTimeRemaining = 0;
                        }
                    }
                }
            }

            // 对于那些已经不可用的目标解除锁定
            for (int iEntity = 0; iEntity < cancelLockList.Count; iEntity++)
            {
                m_LockTargeMap.Remove(cancelLockList[iEntity]);
                SLog("目标因为死亡或者超出视野而失去锁定. {0}", iEntity);
            }
        }

        // 通知UI当前锁定的所有目标
        PlayerMissileWeaponTargetSelectionInfo targetInfoNotify = MessageSingleton.Get <PlayerMissileWeaponTargetSelectionInfo>();

        //targetInfoNotify.TargeList = m_LockTargeMap;
        GameFacade.Instance.SendNotification(NotificationName.PlayerMissileWeaponTargetSelection, targetInfoNotify);
    }