Esempio n. 1
0
    /// <summary>
    /// 同步HP、MP
    /// </summary>
    /// <param name="buf"></param>
    private void OnHeroHpMpAnger(KProtoBuf buf)
    {
        S2C_SYNC_HERO_HPMP_ANGER msg    = buf as S2C_SYNC_HERO_HPMP_ANGER;
        SpacecraftEntity         entity = m_GameplayProxy.GetEntityById <SpacecraftEntity>(msg.heroID);

        if (entity != null)
        {
            entity.SetAttribute(AttributeName.kHP, msg.hp);
            entity.SetAttribute(AttributeName.kShieldValue, msg.shield_value);
            entity.SetAttribute(AttributeName.kPowerValue, msg.energyPower);
            //新屬性目前沒有
            //entity.SetAttribute(AttributeName.DefenseShield, msg.defense_shield_value);
            //entity.SetAttribute(AttributeName.ManaShield, msg.mana_shield_value);
            //entity.SetAttribute(AttributeName.SuperMagnetic, msg.superMagnetic);

            double oldPeerless = entity.GetAttribute(AttributeName.kConverterValue);             /// entity.GetPeerless();
            /// entity.SetPeerless((uint)msg.current_peerless);
            entity.SetAttribute(AttributeName.kConverterValue, msg.current_peerless);

            if (entity.IsMain() && oldPeerless != entity.GetAttribute(AttributeName.kConverterMax) &&
                entity.GetAttribute(AttributeName.kConverterValue) == entity.GetAttribute(AttributeName.kConverterMax))
            {
                entity.SendEvent(ComponentEventName.MaxPeerlessReached, null);
            }
        }
    }
    /// <summary>
    /// 加载模型
    /// </summary>
    /// <param name="target"></param>
    private void LoadViewerModel(SpacecraftEntity target)
    {
        if (m_NearestTarget != target)
        {
            m_NearestTarget = target;
            if (m_NearestTarget)
            {
                m_TargetList.Clear();
                if (m_NearestTarget.m_EntityFatherOwnerID == 0 && m_NearestTarget.HeroGroupId == 0)
                {
                    m_TargetViewer.LoadModel(ASSET_UI3DShip, FindSingleMine(), ASSET_UI3DEffect);
                }
                else
                {
                    m_TargetViewer.LoadModel(ASSET_UI3DShip, FindSubsidiaryMine(), ASSET_UI3DEffect);
                }

                if (!m_NearestTargetLast)
                {
                    PlaySound(WwiseMusicSpecialType.SpecialType_Voice_minera_event1);
                }
            }
            else
            {
                m_TargetViewer.ClearModel();
            }

            if (m_NearestTargetLast && m_NearestTargetLast.GetAttribute(AttributeName.kHP) <= 0)
            {
                PlaySound(WwiseMusicSpecialType.SpecialType_Voice_minera_event2);
            }
            m_NearestTargetLast = m_NearestTarget;
        }
    }
    private void UpdateCurrentTarget()
    {
        m_CurrentTarget = null;
        if (IsBattling())
        {
            if (m_MainSpacecraftEntity)
            {
                m_CurrentTarget = m_MainSpacecraftEntity.GetTarget();
            }
        }
        else
        {
            m_CurrentTarget = m_RaycastProxy.Raycast();
        }

        if (m_CurrentTarget != null)
        {
            if ((m_CurrentTarget.GetHeroType() != KHeroType.htMine || m_CurrentTarget.GetAttribute(AttributeName.kHP) <= 0))
            {
                m_CurrentTarget = null;
            }
        }
    }
Esempio n. 4
0
    /// <summary>
    /// 更新
    /// </summary>
    protected override void Update()
    {
        SpacecraftEntity main = GetMainEntity();

        if (main == null)
        {
            return;
        }

        //当前状态
        bool isBattle         = IsBattling();
        bool isBurstReady     = main.GetBurstReady();
        bool isBurstActivated = IsPeerless();

        //能量属性
        float peerless    = (float)main.GetAttribute(AttributeName.kConverterValue);
        float peerlessMax = (float)main.GetAttribute(AttributeName.kConverterMax);

        //能量条
        m_PowerSlider.gameObject.SetActive(true);
        if (peerlessMax > 0 && peerless > 0)
        {
            m_PowerSlider.fillAmount = Mathf.Lerp(m_PowerSlider.fillAmount, peerless / peerlessMax, Time.deltaTime * 2);
        }
        else
        {
            m_PowerSlider.fillAmount = Mathf.Lerp(m_PowerSlider.fillAmount, 0, Time.deltaTime * 2);
        }

        //倒计时
        //m_CountdownBox.gameObject.SetActive(isBurstActivated);
        //if(isBurstActivated)
        //{
        //peerless
        //double consume = main.GetAttribute(AttributeName.kConverterCostEfficiency);
        //Debug.LogError(consume);
        //}

        //热键显示
        //m_HotkeyBox.gameObject.SetActive(isBattle);
        m_Hotkey2.gameObject.SetActive(isBurstReady && !isBurstActivated);
        m_Hotkey1.gameObject.SetActive(Mathf.Approximately(peerless, peerlessMax) && !isBurstReady && !isBurstActivated);

        //状态动画
        if (isBattle != m_BattleState)
        {
            m_BattleState = isBattle;

            m_StateAnimator.ResetTrigger("Cruise");
            m_StateAnimator.ResetTrigger("Battle");
            m_StateAnimator.SetTrigger(isBattle ? "Battle" : "Cruise");
        }

        //特效动画
        string newState = "Normal";

        if (isBattle)
        {
            if (peerless >= peerlessMax && peerlessMax > 0)
            {
                newState = isBurstReady ? "Hold" : "Already";
            }
            if (isBurstActivated)
            {
                newState = "Release";
            }
        }
        if (!newState.Equals(m_EffectState))
        {
            m_EffectState = newState;

            m_EffectAnimator.ResetTrigger("Normal");
            m_EffectAnimator.ResetTrigger("Already");
            m_EffectAnimator.ResetTrigger("Hold");
            m_EffectAnimator.ResetTrigger("Release");
            m_EffectAnimator.SetTrigger(newState);
        }
    }
Esempio n. 5
0
    /// <summary>
    /// 更新目标
    /// </summary>
    /// <param name="main">主角</param>
    /// <param name="target">目标</param>
    /// <param name="view">UI</param>
    /// <param name="anchoredPosition">坐标</param>
    /// <param name="distance">距离</param>
    private void OnTargetUpdate(SpacecraftEntity main, SpacecraftEntity target, RectTransform view, Vector3 anchoredPosition, float distance, float visibleDistance, bool mouseMoved, bool IsNew)
    {
        TaskTrackingProxy taskTrackingProxy = Facade.RetrieveProxy(ProxyName.TaskTrackingProxy) as TaskTrackingProxy;

        float hp    = (float)target.GetAttribute(AttributeName.kHP);
        float hpMax = (float)target.GetAttribute(AttributeName.kHPMax);
        float mp    = (float)target.GetAttribute(AttributeName.kShieldValue);
        float mpMax = (float)target.GetAttribute(AttributeName.kShieldMax);

        float hpProgress = hpMax <= 0 ? 0.0f : hp / hpMax;
        float mpProgress = mpMax <= 0 ? 0.0f : mp / mpMax;

        //坐标
        view.anchoredPosition = anchoredPosition;

        if (target.GetHeroType() == KHeroType.htMine)
        {
            m_BloodImage            = FindComponent <Image>(view, "Slider/Image_Bar");
            m_BloodImage.fillAmount = hpProgress;
            TMP_Text hpText = FindComponent <TMP_Text>(view, "Name/Name/Label_Value");//血值比率
            if (hpText)
            {
                int textID = 1025;
                if (hpProgress <= 0.0f)
                {
                    textID = 1021;
                }
                else if (hpProgress <= 0.2f)
                {
                    textID = 1022;
                }
                else if (hpProgress <= 0.4f)
                {
                    textID = 1023;
                }
                else if (hpProgress <= 0.6f)
                {
                    textID = 1024;
                }

                hpText.text = GetLocalization("hud_text_id_" + textID);
            }

            //动画
            Animator animator = view.GetComponent <Animator>();
            if (animator)
            {
                SpacecraftEntity currentTarget = m_RaycastProxy.Raycast();

                animator.SetBool("isBattle", IsBattling());
                animator.SetBool("isTarget", currentTarget == target);
                if (mouseMoved)
                {
                    animator.SetTrigger("mouseMoved");
                }
            }
        }
        else
        {
            //血值
            Slider mpSlider = FindComponent <Slider>(view, "Slider/Slider_MP");
            if (mpSlider)
            {
                mpSlider.value = mpProgress;
            }

            //护甲
            Slider hpSlider = FindComponent <Slider>(view, "Slider/Slider_Hp");
            if (hpSlider)
            {
                hpSlider.value = hpProgress;
            }

            //距离
            TMP_Text distanceField = FindComponent <TMP_Text>(view, "Name/Distance");
            if (distanceField)
            {
                distanceField.text = FormatMetre(distance);
            }

            //任务
            RectTransform missionBox = FindComponent <RectTransform>(view, "MissionIconBox");
            if (missionBox)
            {
                bool needShowMissionFlag = distance < visibleDistance;
                if (needShowMissionFlag && !taskTrackingProxy.GetAreadyAddMissionInfo(target.GetUId(), target.GetTemplateID()))
                {
                    TaskTrackingProxy.TrackingInfo tracking = taskTrackingProxy.GetNpcMission(target.GetUId(), target.GetTemplateID());
                    MissionType missionType = tracking != null ? tracking.MissionType : MissionType.None;

                    missionBox.gameObject.SetActive(missionType != MissionType.None);
                    if (missionBox.gameObject.activeSelf)
                    {
                        Animator missionAniamtor = FindComponent <Animator>(missionBox, "IconMissionElement");
                        Image    missionIcon     = FindComponent <Image>(missionAniamtor, "Icon");

                        UIUtil.SetIconImage(missionIcon, GameConstant.FUNCTION_ICON_ATLAS_ASSETADDRESS, GetMissionIcon(missionType));

                        missionAniamtor.SetBool("Finished", tracking != null && tracking.MissionState == MissionState.Finished);
                    }
                }
                else
                {
                    missionBox.gameObject.SetActive(false);
                }
            }

            //逃跑
            Transform escapeTransform = FindComponent <Transform>(view, "RunIconBox ");
            if (escapeTransform != null && escapeTransform.gameObject.activeSelf != m_RunIconBoxActive)
            {
                escapeTransform.gameObject.SetActive(m_RunIconBoxActive);
            }

            //动画
            Animator      animator        = view.GetComponent <Animator>();
            Transform     buffIconBoxTras = view.Find("BuffIconBox");
            RectTransform bufferIconBox   = null;
            if (buffIconBoxTras)
            {
                bufferIconBox = buffIconBoxTras.GetComponent <RectTransform>();
            }
            if (animator)
            {
                if (distance < GameConstant.DEFAULT_VISIBILITY_METRE_FOR_SHIP / 2)
                {
                    if (main.GetTarget() == target)
                    {
                        if (bufferIconBox)
                        {
                            bufferIconBox.localPosition = m_NormalBufferPos;
                        }
                        animator.SetInteger("State", 2);
                    }
                    else
                    {
                        if (bufferIconBox)
                        {
                            bufferIconBox.localPosition = m_NormalBufferPos;
                        }
                        animator.SetInteger("State", 1);
                    }
                }
                else
                {
                    if (bufferIconBox)
                    {
                        bufferIconBox.localPosition = m_AwayFromBufferPos;
                    }
                    animator.SetInteger("State", 0);
                }

                if (target == main)
                {
                    if (bufferIconBox)
                    {
                        bufferIconBox.localPosition = m_SelfBufferPos;
                    }
                    animator.SetInteger("State", 0);
                    view.Find("Icon").gameObject.SetActive(false);
                }
            }

            if (IsNew)
            {
                OnAddBufferIcon(target);
            }
        }
    }
Esempio n. 6
0
    /// <summary>
    /// 更新视图
    /// </summary>
    protected override void Update()
    {
        if (!IsDead() && !IsWatchOrUIInputMode() && !IsLeaping())
        {
            //GameplayProxy sceneProxy = Facade.RetrieveProxy(ProxyName.GameplayProxy) as GameplayProxy;
            //SpacecraftEntity main = sceneProxy.GetEntityById<SpacecraftEntity>(sceneProxy.GetMainPlayerUID());
            if (m_MainEntity == null)
            {
                m_MainEntity = m_GameplayProxy.GetEntityById <SpacecraftEntity>(m_GameplayProxy.GetMainPlayerUID());
            }
            if (!m_MainEntity)
            {
                return;
            }
            List <SpacecraftEntity> entitys = m_GameplayProxy.GetEntities <SpacecraftEntity>();

            //按距离排序
            entitys.Sort((a, b) =>
            {
                Vector3 distanceA = a.transform.position - m_MainEntity.transform.position;
                Vector3 distanceB = b.transform.position - m_MainEntity.transform.position;
                return((int)(distanceB.sqrMagnitude - distanceA.sqrMagnitude));
            });

            bool isInSpace = IsInSpace();
            for (int i = 0; i < entitys.Count; i++)
            {
                SpacecraftEntity entity             = entitys[i];
                KHeroType        heroType           = entity.GetHeroType();
                Vector3          titleOffset        = Vector3.zero;
                float            visibilityDistance = GameConstant.DEFAULT_VISIBILITY_METRE_FOR_SHIP;

                //忽略自已
                // if (entity == main)
                //    continue;

                //忽略不需要显示的NPC
                if (heroType != KHeroType.htPlayer)
                {
                    Npc entityVO = m_CfgEternityProxy.GetNpcByKey(entity.GetTemplateID());
                    if (entityVO.Display == 0)
                    {
                        continue;
                    }

                    if (entityVO.HeroHeaderLength >= 3)
                    {
                        titleOffset = new Vector3(entityVO.HeroHeader(0), entityVO.HeroHeader(1), entityVO.HeroHeader(2));
                    }

                    visibilityDistance = entityVO.MissionTargetHiddenDistance * (isInSpace ? GameConstant.METRE_PER_UNIT : 1);
                }

                //忽略死亡的( 除了矿石 )
                if (heroType != KHeroType.htMine && heroType != KHeroType.htPreicous && (entity.GetAttribute(AttributeName.kHP) <= 0 || entity.GetCurrentState().GetMainState() == EnumMainState.Dead))
                {
                    continue;
                }
                if (entity.m_EntityFatherOwnerID > 0 && heroType == KHeroType.htMine)
                {
                    continue;
                }
                //忽略不支持的
                RectTransform template = GetTemplate(m_MainEntity, entity);
                if (!template)
                {
                    continue;
                }

                //忽略过远的
                float distance = (entity.transform.position - m_MainEntity.transform.position).magnitude;
                if (entity.GetHeroType() == KHeroType.htMine && distance > entity.GetNPCTemplateVO().TriggerRange)
                {
                    continue;
                }
                distance = distance * GameConstant.METRE_PER_UNIT;
                if (distance >= visibilityDistance)
                {
                    continue;
                }

                //忽略屏幕外的
                Vector3 screenPosition = Camera.main.WorldToScreenPoint(entity.transform.TransformPoint(titleOffset));
                if (!(screenPosition.z > Camera.main.nearClipPlane && screenPosition.x >= 0 && screenPosition.x <= Camera.main.pixelWidth && screenPosition.y > 0 && screenPosition.y <= Camera.main.pixelHeight))
                {
                    continue;
                }

                Vector2 anchoredPosition;
                if (RectTransformUtility.ScreenPointToLocalPointInRectangle(m_Root, screenPosition, m_Camera, out anchoredPosition))
                {
                    Transform templatePool = m_TemplateToPool[template];

                    uint uid   = entity.GetUId();
                    bool isNew = false;

                    EntityView info;
                    if (m_UIDToRectTranform1.ContainsKey(uid))
                    {
                        info = m_UIDToRectTranform1[uid];
                        m_UIDToRectTranform1.Remove(uid);
                        m_UIDToRectTranform2[uid] = info;
                    }
                    else
                    {
                        RectTransform view = templatePool.childCount > 0 ? templatePool.GetChild(0).GetComponent <RectTransform>() : Object.Instantiate(template, m_Root);
                        view.SetParent(m_Root);
                        view.transform.SetAsLastSibling();
                        view.gameObject.SetActive(true);

                        info = new EntityView()
                        {
                            uid = uid, view = view, viewPool = templatePool
                        };
                        m_UIDToRectTranform2[uid] = info;
                        isNew = true;


                        OnTargetCreate(entity, view);
                    }

                    OnTargetUpdate(m_MainEntity, entity, info.view, anchoredPosition, distance, visibilityDistance, m_MouseMoved, isNew);
                }
            }
        }

        m_MouseMoved = false;

        //回收无效的
        foreach (EntityView info in m_UIDToRectTranform1.Values)
        {
            info.view.SetParent(info.viewPool);
        }
        m_UIDToRectTranform1.Clear();

        Dictionary <uint, EntityView> tmp = m_UIDToRectTranform1;

        m_UIDToRectTranform1 = m_UIDToRectTranform2;
        m_UIDToRectTranform2 = tmp;
    }
    /// <summary>
    /// 更新UI
    /// </summary>
    private void UpdateUI()
    {
        if (m_NearestTarget)
        {
            m_NearestTarget.GetSkinRootTransform();

            float hp    = (float)m_NearestTarget.GetAttribute(AttributeName.kHP);
            float hpMax = (float)m_NearestTarget.GetAttribute(AttributeName.kHPMax);

            float hpProgress = hpMax <= 0 ? 0 : hp / hpMax;
            //int phase = Mathf.Min(4, Mathf.FloorToInt(hpProgress / (1.0f / 5)));

            m_HpBar.fillAmount = hpProgress;
            m_HpBarLabel.text  = Mathf.FloorToInt(hpProgress * 100) + "%";
            m_HpBarState.text  = "";           // GetLocalization("hud_text_id_" + (1021 + phase));

            if (m_TargetViewer && m_TargetViewer.Camera && m_TargetViewer.ModelArray != null)
            {
                if (m_TargetList.Count > 0)
                {
                    for (int i = 0; i < m_TargetViewer.ModelArray.Length; i++)
                    {
                        SpacecraftEntity entity = m_GameplayProxy.GetEntityById <SpacecraftEntity>(m_TargetList[i]);
                        if (entity != null)
                        {
                            Transform skinTransform = entity.GetSkinTransform();
                            if (skinTransform != null)
                            {
                                for (int k = 0; k < m_TargetViewer.ModelArray[i].transform.childCount; k++)
                                {
                                    Transform child = m_TargetViewer.ModelArray[i].transform;
                                    if (child.GetChild(k).GetComponent <EffectController>() != null)
                                    {
                                        continue;
                                    }
                                    string name = child.GetChild(k).name;
                                    if (skinTransform.Find(name) == null)
                                    {
                                        child.GetChild(k).gameObject.SetActive(false);
                                    }
                                    else
                                    {
                                        child.GetChild(k).gameObject.SetActive(true);
                                    }
                                }
                            }
                        }
                        else
                        {
                            GameObject currentModel = m_TargetViewer.ModelArray[i];
                            for (int j = 0; j < currentModel.transform.childCount; j++)
                            {
                                if (currentModel.transform.GetChild(j).GetComponent <EffectController>() != null)
                                {
                                    continue;
                                }
                                currentModel.transform.GetChild(j).gameObject.SetActive(false);
                            }
                        }
                    }
                }
                Transform skin = m_NearestTarget.GetSkinTransform();
                if (skin)
                {
                    Camera           mainCamera = CameraManager.GetInstance().GetMainCamereComponent().GetCamera();
                    GameplayProxy    sceneProxy = Facade.RetrieveProxy(ProxyName.GameplayProxy) as GameplayProxy;
                    SpacecraftEntity mainHero   = sceneProxy.GetEntityById <SpacecraftEntity>(sceneProxy.GetMainPlayerUID());

                    float   bestDistance  = m_TargetViewer.ModelBoundsDiagonalLength / 2.0f / Mathf.Tan(mainCamera.fieldOfView * Mathf.Deg2Rad / 2.0f);
                    Vector3 bestDirection = mainCamera.transform.position - mainHero.transform.position;

                    m_TargetViewer.ModelBox.rotation         = skin.rotation;
                    m_TargetViewer.Camera.transform.position = m_TargetViewer.ModelBox.position + bestDirection.normalized * bestDistance;
                    m_TargetViewer.Camera.transform.LookAt(m_TargetViewer.ModelBox);
                }
            }

            if (m_TargetViewer.EffectArray != null)
            {
                foreach (EffectController effect in m_TargetViewer.EffectArray)
                {
                    VFXController effectObject = effect.GetEffectObject();
                    if (effectObject)
                    {
                        Animator animator = effectObject.GetComponent <Animator>();
                        if (animator)
                        {
                            animator.SetFloat("Color", 1 - hpProgress);
                        }
                    }
                }
            }
        }
        else
        {
            m_HpBarState.text = GetLocalization("hud_text_id_" + 1021);
        }
    }
    /// <summary>
    /// 每帧更新
    /// </summary>
    protected override void Update()
    {
        if (!m_TargetViewer)
        {
            return;
        }

        bool needShow  = !IsWatchOrUIInputMode() && !IsDead() && !IsLeaping();
        bool hasTarget = false;

        if (m_MainSpacecraftEntity == null)
        {
            m_MainSpacecraftEntity = m_GameplayProxy.GetEntityById <SpacecraftEntity>(m_GameplayProxy.GetMainPlayerUID());
        }
        SpacecraftEntity target = m_NearestTarget;

        //每隔5帧重新查找一下最近矿物
        if (m_NearestTargetCounter % 5 == 0)
        {
            target = FindNearestTarget();
        }
        m_NearestTargetCounter++;

        if (target && target.GetAttribute(AttributeName.kHP) <= 0)
        {
            target = null;
        }

        //加载模型
        LoadViewerModel(target);
        if (target)
        {
            int bloodVolumeLength = m_CfgEternityProxy.GetDoppingBloodVolumeLengthByKey((uint)target.GetTemplateID()) - 1;
            if (m_OldPrivew != bloodVolumeLength)
            {
                m_OldPrivew = bloodVolumeLength;
                while (m_LineGrid.childCount - 2 < bloodVolumeLength)
                {
                    Transform lineItem = Object.Instantiate(m_LineGrid.GetChild(1), m_LineGrid);
                    lineItem.gameObject.SetActive(true);
                }
                for (int i = bloodVolumeLength + 2; i < m_LineGrid.childCount; i++)
                {
                    m_LineGrid.GetChild(i).gameObject.SetActive(false);
                }
            }
        }
        //更新UI
        m_Root.SetBool("Show", needShow && target != null);
        UpdateUI();

        if (needShow && target != null && m_IsPlayShowMusic == 0)
        {
            m_IsPlayShowMusic = 1;
            m_IsPlayHideMusic = 0;
            WwiseUtil.PlaySound((int)WwiseMusic.Music_Hud_Resource_Open, false, null);
        }
        if (m_IsPlayShowMusic == 1 && !(needShow && target != null) && m_IsPlayHideMusic == 0)
        {
            m_IsPlayHideMusic = 1;
            m_IsPlayShowMusic = 0;
            WwiseUtil.PlaySound((int)WwiseMusic.Music_Hud_Resource_Close, false, null);
        }

        //更新全息效果的透明度
        if (needShow)
        {
            UpdateCurrentTarget();
            hasTarget = m_CurrentTarget != null;
        }
        m_TargetImage.alpha = needShow && hasTarget ? 1.0f : 0.1f;

        //提示玩家切换到战斗模式
        if (needShow && !IsBattling() && m_CurrentTarget != null)
        {
            if (!m_IsShow)
            {
                m_IsShow = true;
                m_IsHide = false;
                Facade.SendNotification(NotificationName.MSG_INTERACTIVE_SHOWTIP, HudNpcInteractiveFlagPanel.InteractiveTipType.Collector);
            }
        }
        else
        {
            if (!m_IsHide)
            {
                m_IsHide = true;
                m_IsShow = false;
                Facade.SendNotification(NotificationName.MSG_INTERACTIVE_HIDETIP, HudNpcInteractiveFlagPanel.InteractiveTipType.Collector);
            }
        }
    }
Esempio n. 9
0
    private void Update()
    {
        int count = m_NearbyMonsterList.Count;

        if (count == 0)
        {
            PlayForeWarnVoice(false);
            return;
        }
        ulong cureenttime = ServerTimeUtil.Instance.GetNowTimeMSEL();

        if (cureenttime - m_CurentTime < 1000)
        {
            return;
        }

        m_CurentTime = cureenttime;
        if (IsDead() || IsLeaping() || !IsInSpace())
        {
            OpenCountDownTimePanel(false);
            return;
        }
        SpeekWarnVoiceNearbyAI(cureenttime);

        BaseEntity main           = m_GameplayProxy.GetEntityById <BaseEntity>(m_GameplayProxy.GetMainPlayerUID());
        bool       isInSpace      = IsInSpace();
        bool       isEscapeFromAI = false;
        bool       isEscapeFromM  = true;

        for (int i = 0; i < count; ++i)
        {
            uint             uid  = m_NearbyMonsterList[i];
            SpacecraftEntity ship = m_GameplayProxy.GetEntityById <SpacecraftEntity>(uid);
            if (ship != null && (ship.GetAttribute(AttributeName.kHP) > 0))
            {
                Vector3 targetPosition = ship.transform.position;
                float   targetDistance = Vector3.Distance(targetPosition, main.transform.position) * (isInSpace ? GameConstant.METRE_PER_UNIT : 1);
                if (!m_PreFrameMonsterDis.ContainsKey(uid))
                {
                    if (m_CurrentAIUid == uid)
                    {
                        isEscapeFromAI = false;
                        isEscapeFromM  = false;
                    }

                    m_PreFrameMonsterDis.Add(uid, targetDistance);
                }
                else
                {
                    if (uid == m_CurrentAIUid && m_PreFrameMonsterDis[uid] < targetDistance)
                    {
                        isEscapeFromAI = true;
                    }
                    if (m_PreFrameMonsterDis[uid] > targetDistance)
                    {
                        isEscapeFromM = false;
                    }
                    m_PreFrameMonsterDis[uid] = targetDistance;
                }
            }
            else if (ship == null && m_MonsterPos.ContainsKey(uid))
            {
                Vector3 targetPosition = m_GameplayProxy.ServerAreaOffsetToClientPosition(m_MonsterPos[uid]);
                float   targetDistance = Vector3.Distance(targetPosition, main.transform.position) * (isInSpace ? GameConstant.METRE_PER_UNIT : 1);
                if (m_PreFrameMonsterDis.ContainsKey(uid))
                {
                    if (m_CurrentAIUid == uid)
                    {
                        isEscapeFromAI = false;
                        isEscapeFromM  = false;
                    }

                    m_PreFrameMonsterDis[uid] = targetDistance;
                }
                else
                {
                    if (uid == m_CurrentAIUid && m_PreFrameMonsterDis[uid] < targetDistance)
                    {
                        isEscapeFromAI = true;
                    }
                    if (m_PreFrameMonsterDis[uid] > targetDistance)
                    {
                        isEscapeFromM = false;
                    }
                    m_PreFrameMonsterDis.Add(uid, targetDistance);
                }
            }
        }

        bool forewarn = false;

        foreach (var item in m_PreFrameMonsterDis)
        {
            if (item.Value <= FORE_WARN_MAXRADIUS)
            {
                forewarn = true;
                break;
            }
        }
        PlayForeWarnVoice(forewarn);
        if (m_PlayerInBattle && isEscapeFromAI && isEscapeFromM)
        {
            SetPlayerState(PlayerAIState.EscapeFromAI);
        }
    }
Esempio n. 10
0
    /// <summary>
    /// 更新所有任务标记
    /// </summary>
    protected override void Update()
    {
        if (!IsDead() && !IsWatchOrUIInputMode() && !IsLeaping())
        {
            float w = m_Flags.rect.width;
            float h = m_Flags.rect.height;

            m_ScaleBox.localScale = w > h ? new Vector3(1, h / w, 1) : new Vector3(w / h, 1, 1);

            GameplayProxy    sceneProxy = Facade.RetrieveProxy(ProxyName.GameplayProxy) as GameplayProxy;
            SpacecraftEntity main       = sceneProxy.GetEntityById <SpacecraftEntity>(sceneProxy.GetMainPlayerUID());

            if (!main)
            {
                return;
            }

            List <SpacecraftEntity> entitys = sceneProxy.GetEntities <SpacecraftEntity>();
            for (int i = 0; i < entitys.Count; i++)
            {
                SpacecraftEntity entity      = entitys[i];
                KHeroType        heroType    = entity.GetHeroType();
                Vector3          titleOffset = Vector3.zero;

                //忽略自已
                if (entity == main)
                {
                    continue;
                }

                //忽略不需要显示的NPC
                if (heroType != KHeroType.htPlayer)
                {
                    Npc entityVO = m_CfgEternityProxy.GetNpcByKey(entity.GetTemplateID());
                    //if (entityVO.Display == 0)
                    //continue;

                    if (entityVO.HeroHeaderLength >= 3)
                    {
                        titleOffset = new Vector3(entityVO.HeroHeader(0), entityVO.HeroHeader(1), entityVO.HeroHeader(2));
                    }
                }

                //忽略死亡的( 除了矿石 )
                if (heroType != KHeroType.htMine && heroType != KHeroType.htPreicous && (entity.GetAttribute(AttributeName.kHP) <= 0 || entity.GetCurrentState().GetMainState() == EnumMainState.Dead))
                {
                    continue;
                }

                //忽略不支持的
                RectTransform template = GetTemplate(main, entity);
                if (!template)
                {
                    continue;
                }

                //忽略过远的
                float distance = (entity.transform.position - main.transform.position).magnitude;
                if (entity.GetHeroType() == KHeroType.htMine && distance > entity.GetNPCTemplateVO().TriggerRange)
                {
                    continue;
                }
                distance = distance * GameConstant.METRE_PER_UNIT;
                if (distance >= GameConstant.DEFAULT_VISIBILITY_METRE_FOR_SHIP)
                {
                    continue;
                }

                //忽略屏幕内的
                Vector3 screenPosition = Camera.main.WorldToScreenPoint(entity.transform.TransformPoint(titleOffset));
                if (screenPosition.z > Camera.main.nearClipPlane && screenPosition.x >= 0 && screenPosition.x <= Camera.main.pixelWidth && screenPosition.y > 0 && screenPosition.y <= Camera.main.pixelHeight)
                {
                    // is in screen
                }
                else
                {
                    //忽略屏幕外的
                    Transform templatePool = m_TemplateToPool[template];

                    uint uid = entity.GetUId();

                    EntityView info;
                    if (m_UIDToRectTranform1.ContainsKey(uid))
                    {
                        info = m_UIDToRectTranform1[uid];
                        m_UIDToRectTranform1.Remove(uid);
                        m_UIDToRectTranform2[uid] = info;
                    }
                    else
                    {
                        RectTransform view = templatePool.childCount > 0 ? templatePool.GetChild(0).GetComponent <RectTransform>() : Object.Instantiate(template, m_Flags);
                        view.SetParent(m_Flags);
                        view.transform.SetAsLastSibling();
                        view.gameObject.SetActive(true);

                        info = new EntityView()
                        {
                            uid = uid, view = view, viewPool = templatePool
                        };
                        m_UIDToRectTranform2[uid] = info;

                        OnTargetCreate(view, entity);
                    }

                    OnTargetUpdate(info.view, entity.transform.position, distance);
                }
            }
        }


        //回收无效的
        foreach (EntityView info in m_UIDToRectTranform1.Values)
        {
            info.view.SetParent(info.viewPool);
        }
        m_UIDToRectTranform1.Clear();

        Dictionary <uint, EntityView> tmp = m_UIDToRectTranform1;

        m_UIDToRectTranform1 = m_UIDToRectTranform2;
        m_UIDToRectTranform2 = tmp;
    }
Esempio n. 11
0
    /// <summary>
    /// 更新UI
    /// </summary>
    protected override void Update()
    {
        GameplayProxy    gameplayProxy = Facade.RetrieveProxy(ProxyName.GameplayProxy) as GameplayProxy;
        SpacecraftEntity main          = gameplayProxy.GetEntityById <SpacecraftEntity>(gameplayProxy.GetMainPlayerUID());

        if (main == null)
        {
            return;
        }

        bool needCrosshair = !IsWatchOrUIInputMode() && !IsDead() && !IsLeaping() && !IsBattling();
        bool hasMineral    = false;

        if (needCrosshair)
        {
            SpacecraftEntity target = m_RaycastProxy.Raycast();
            hasMineral = target != null && target.GetHeroType() == Assets.Scripts.Define.KHeroType.htMine && target.GetAttribute(AttributeName.kHP) > 0;
        }
        m_Crosshair.gameObject.SetActive(needCrosshair);
        m_JumpCrosshair.gameObject.SetActive(!hasMineral);
        m_MineralCrosshair.gameObject.SetActive(hasMineral);

        float w = m_Root.rect.width;
        float h = m_Root.rect.height;

        m_ScaleBox.localScale = w > h ? new Vector3(1, h / w, 1) : new Vector3(w / h, 1, 1);

        m_HaveMissionFlagPoints.Clear();
        List <TaskTrackingProxy.TrackingInfo> trackingList = m_TaskTracking.GetAllTrackings();

        for (int i = 0; i < trackingList.Count; i++)
        {
            if (trackingList[i].Mode == TaskTrackingProxy.TrackingMode.LeapPoint)
            {
                m_HaveMissionFlagPoints.Add((uint)trackingList[i].LeapPointID);
            }
        }

        ulong currentAreaID = MapManager.GetInstance().GetCurrentAreaUid();

        uint[] visibleLeapIDs = null;
        for (int i = 0; i < m_LeapCfgs.Count; i++)
        {
            if (m_LeapCfgs[i].LeapId == currentAreaID)
            {
                visibleLeapIDs = m_LeapCfgs[i].GetVisibleLeapListArray();
                break;
            }
        }

        int     hitedPointIndex = -1;
        bool    allowVisible    = !IsDead() && !IsWatchOrUIInputMode();// && !IsBattling();
        Vector2 screenCenter    = new Vector2(Screen.width / 2, Screen.height / 2);

        for (int i = 0; i < m_LeapCfgs.Count; i++)
        {
            RectTransform point = m_PointBox.GetChild(i).GetComponent <RectTransform>();
            RectTransform arrow = m_ArrowBox.GetChild(i).GetComponent <RectTransform>();

            if (!allowVisible)
            {
                arrow.gameObject.SetActive(false);
                point.gameObject.SetActive(false);
                continue;
            }

            LeapItem leapVO = m_LeapCfgs[i];
            uint     leapID = (uint)leapVO.LeapId;

            if (visibleLeapIDs != null && System.Array.IndexOf(visibleLeapIDs, leapID) == -1)
            {
                arrow.gameObject.SetActive(false);
                point.gameObject.SetActive(false);
                continue;
            }

            Vector3 targetWorldPosition = gameplayProxy.WorldPositionToServerAreaOffsetPosition(new Vector3((float)leapVO.Position.Value.X, (float)leapVO.Position.Value.Y, (float)leapVO.Position.Value.Z));

            //目标过远,忽略
            float distance = Vector3.Distance(targetWorldPosition, main.transform.position);
            if (distance <= leapVO.Range * GameConstant.METRE_PER_UNIT)
            {
                arrow.gameObject.SetActive(false);
                point.gameObject.SetActive(false);
                continue;
            }

            Vector3 viewportPoint = Camera.main.WorldToViewportPoint(targetWorldPosition);
            if (viewportPoint.x >= 0 && viewportPoint.y >= 0 && viewportPoint.x <= 1 && viewportPoint.y <= 1 && viewportPoint.z >= Camera.main.nearClipPlane)
            {
                //屏幕内
                Vector3 screenPoint = Camera.main.WorldToScreenPoint(targetWorldPosition);

                Vector2 iconPosition;
                if (RectTransformUtility.ScreenPointToLocalPointInRectangle(m_PointBox, screenPoint, m_Camera, out iconPosition))
                {
                    arrow.gameObject.SetActive(false);
                    point.gameObject.SetActive(true);

                    point.anchoredPosition = iconPosition;
                    point.localScale       = Vector3.one * LEAP_POINT_SCALE;
                    point.Find("JumpTips/TextBox/Distance").GetComponent <TMP_Text>().text = FormatMetre(distance * GameConstant.METRE_PER_UNIT);

                    if (hitedPointIndex == -1)
                    {
                        Vector2 crosshairPosition;
                        if (RectTransformUtility.ScreenPointToLocalPointInRectangle(m_Crosshair, screenPoint, m_Camera, out crosshairPosition))
                        {
                            //确定选中项
                            if (crosshairPosition.magnitude <= m_Crosshair.rect.width * 0.5f)
                            {
                                hitedPointIndex = i;
                            }
                        }
                    }
                }
            }
            else
            {
                if (m_HaveMissionFlagPoints.Contains(leapID))
                {
                    arrow.gameObject.SetActive(false);
                    point.gameObject.SetActive(false);
                    continue;
                }

                //屏幕外
                point.gameObject.SetActive(false);
                arrow.gameObject.SetActive(true);

                Vector3 inCameraPosition = Camera.main.transform.InverseTransformPoint(targetWorldPosition);

                Vector2 arrowPosition = m_ScaleBox.InverseTransformPoint(m_Root.TransformPoint(((Vector2)inCameraPosition)));
                arrowPosition = arrowPosition.normalized * (Mathf.Max(m_Root.rect.width, m_Root.rect.height) / 2);
                arrowPosition = m_Root.InverseTransformPoint(m_ScaleBox.TransformPoint(arrowPosition));


                arrow.anchoredPosition = arrowPosition;
                arrow.localScale       = Vector3.one * ARROW_SCALE;

                RectTransform arrowArrow = FindComponent <RectTransform>(arrow, "Arrow");
                arrowArrow.localRotation = Quaternion.Euler(0, 0, Mathf.Atan2(inCameraPosition.y, inCameraPosition.x) * Mathf.Rad2Deg - 90);
            }
        }

        //如果处理战斗状态,强制取消选中
        if (IsBattling())
        {
            hitedPointIndex = -1;
        }

        //只能在NORMAL状态下换目标
        if (m_LeapState == LEAP_PHASE.NORMAL && m_CurrentIndex != hitedPointIndex)
        {
            if (m_CurrentIndex != -1)
            {
                RectTransform point          = m_PointBox.GetChild(m_CurrentIndex).GetComponent <RectTransform>();
                Animator      tipAnimator    = point.Find("JumpTips").GetComponent <Animator>();
                Animator      iconBgAnimator = point.Find("IconBg").GetComponent <Animator>();
                Animator      iconAnimator   = point.Find("Icon").GetComponent <Animator>();
                Transform     missionBox     = point.Find("MissionBox");

                tipAnimator.ResetTrigger("Closed");
                tipAnimator.ResetTrigger("Open");
                tipAnimator.SetTrigger("Closed");

                iconBgAnimator.ResetTrigger("Closed");
                iconBgAnimator.ResetTrigger("Open");
                iconBgAnimator.SetTrigger("Closed");

                iconAnimator.SetBool("selected", false);

                missionBox.gameObject.SetActive(true);
            }
            //Debug.LogError(m_LeapState + "=>" + m_CurrentIndex + " -> " + hitedPointIndex);
            m_CurrentIndex = hitedPointIndex;

            if (m_CurrentIndex != -1)
            {
                RectTransform point          = m_PointBox.GetChild(m_CurrentIndex).GetComponent <RectTransform>();
                Animator      tipAnimator    = point.Find("JumpTips").GetComponent <Animator>();
                Animator      iconBgAnimator = point.Find("IconBg").GetComponent <Animator>();
                Animator      iconAnimator   = point.Find("Icon").GetComponent <Animator>();
                Transform     missionBox     = point.Find("MissionBox");

                tipAnimator.ResetTrigger("Closed");
                tipAnimator.ResetTrigger("Open");
                tipAnimator.SetTrigger("Open");

                iconBgAnimator.ResetTrigger("Closed");
                iconBgAnimator.ResetTrigger("Open");
                iconBgAnimator.SetTrigger("Open");

                iconAnimator.SetBool("selected", true);

                missionBox.gameObject.SetActive(false);

                m_HotKeyBox.SetParent(point.Find("JumpTips/TextBox/HotKeyBox"));
                m_HotKeyBox.gameObject.SetActive(true);
                SetHotKeyVisible("f_hold", true);
                SetHotKeyVisible("f_press", false);
            }
            else
            {
                m_HotKeyBox.SetParent(GetTransform());
                m_HotKeyBox.gameObject.SetActive(false);
                SetHotKeyVisible("f_hold", false);
                SetHotKeyVisible("f_press", false);
            }
        }

        UpdateMissionState();
    }
    /// <summary>
    /// 更新
    /// </summary>
    protected override void Update()
    {
        SpacecraftEntity main = GetMainEntity();

        if (main != null)
        {
            bool IsFighting = IsBattling();

            float fireCD = main.GetFireCountdown();
            //float fireCDMax = 10.0f;// main.GetAttribute(AircraftAttributeType.peerlessTopLimit);

            m_CooldownBox.gameObject.SetActive(IsFighting && fireCD > 0);
            if (m_CooldownBox.gameObject.activeSelf)
            {
                m_CooldownText.text = string.Format(TableUtil.GetLanguageString("hud_text_id_1014"), fireCD > 0 ? (int)fireCD : 0);
            }

            m_HpText.text = Mathf.FloorToInt((float)main.GetAttribute(AttributeName.kHP)).ToString();
            m_SpText.text = Mathf.FloorToInt((float)main.GetAttribute(AttributeName.kShieldValue)).ToString();

            State state = State.Normal;
            if (IsFighting)
            {
                state = fireCD > 0 ? State.BattleCD : State.Battle;
            }
            else
            {
                state = Time.time - m_HurtTime < 10.0f ? State.Hurt : State.Normal;
            }

            if (m_State != state)
            {
                m_Animator.ResetTrigger("Normal");
                m_Animator.ResetTrigger("Injured");
                m_Animator.ResetTrigger("Battle");
                m_Animator.ResetTrigger("Ready");

                m_State = state;
                switch (m_State)
                {
                case State.Normal:
                    m_StateText.text = TableUtil.GetLanguageString("hud_text_id_1009");
                    m_HotkeyBox.gameObject.SetActive(false);
                    m_Animator.SetTrigger("Normal");
                    break;

                case State.Hurt:
                    m_StateText.text = TableUtil.GetLanguageString("hud_text_id_1010");
                    m_HotkeyBox.gameObject.SetActive(true);
                    m_Animator.SetTrigger("Injured");
                    break;

                case State.BattleCD:
                    m_StateText.text = TableUtil.GetLanguageString("hud_text_id_1011");
                    m_HotkeyBox.gameObject.SetActive(false);
                    m_Animator.SetTrigger("Battle");
                    break;

                case State.Battle:
                    m_StateText.text = TableUtil.GetLanguageString("hud_text_id_1012");
                    m_HotkeyBox.gameObject.SetActive(true);
                    m_Animator.SetTrigger("Ready");
                    break;
                }
            }
        }
    }
Esempio n. 13
0
    /// <summary>
    /// 更新
    /// </summary>
    protected override void Update()
    {
        SpacecraftEntity main = GetMainEntity();

        if (main == null)
        {
            return;
        }

        Transform mainShadow = main.GetSyncTarget();

        if (mainShadow == null)
        {
            return;
        }

        Rigidbody rigidbody = mainShadow.GetComponent <Rigidbody>();

        if (rigidbody == null)
        {
            return;
        }

        SpacecraftMotionComponent motionComponent = main.GetEntityComponent <SpacecraftMotionComponent>();

        if (motionComponent == null)
        {
            return;
        }

        Vector3 shipVelocity = rigidbody.transform.InverseTransformDirection(rigidbody.velocity);
        SpacecraftMotionInfo shipMotionInfo = motionComponent.GetCruiseModeMotionInfo();

        bool isBattle   = IsBattling();
        bool isOverload = IsOverload();

        float hp        = (float)main.GetAttribute(AttributeName.kHP);
        float hpMax     = (float)main.GetAttribute(AttributeName.kHPMax);
        float hpPercent = Mathf.Clamp01(hpMax > 0 ? hp / hpMax : 0);

        float sp        = (float)main.GetAttribute(AttributeName.kShieldValue);
        float spMax     = (float)main.GetAttribute(AttributeName.kShieldMax);
        float spPercent = Mathf.Clamp01(spMax > 0 ? sp / spMax : 0);

        float electric        = (float)main.GetAttribute(AttributeName.kPowerValue);
        float electricMax     = (float)main.GetAttribute(AttributeName.kPowerMax);
        float electricPercent = Mathf.Clamp01(electricMax > 0 ? electric / electricMax : 0);

        float velocityForward        = shipVelocity.z;
        float velocityForwardMax     = shipMotionInfo.LineVelocityMax.z;
        float velocityForwardPercent = velocityForwardMax > 0 ? Mathf.Clamp01(Mathf.Abs(velocityForward) / Mathf.Abs(velocityForwardMax)) : 0;

        float velocityUp        = shipVelocity.y;
        float velocityUpMax     = shipMotionInfo.LineVelocityMax.y;
        float velocityUpPercent = velocityUpMax > 0 ? Mathf.Clamp01(Mathf.Abs(velocityUp) / Mathf.Abs(velocityUpMax)) : 0;

        m_HpImage.fillAmount          = Mathf.Lerp(0.171f, 0.329f, hpPercent);
        m_HpLabelBox.localEulerAngles = Vector3.forward * Mathf.Lerp(31.8f, -26.0f, hpPercent);
        m_HpLabel.text = string.Format("{0}%", Mathf.FloorToInt(hpPercent * 100));

        m_SpImage.fillAmount = Mathf.Lerp(0.181f, 0.319f, spPercent);
        m_SpLabel.gameObject.SetActive(Mathf.Approximately(spPercent, 1.0f));

        m_ElectricImage.fillAmount     = Mathf.Lerp(0.181f, 0.319f, electricPercent);
        m_ElectricText.text            = string.Format("{0}/{1}", Mathf.CeilToInt(electric), Mathf.FloorToInt(electricMax));
        m_OverloadBox.localEulerAngles = Vector3.forward * Mathf.Lerp(-21.86f, 26.0f, electricPercent);

        m_SpeedImage1.fillAmount = Mathf.Lerp(0.171f, 0.248f, Mathf.Clamp01(velocityForwardPercent / 0.5f));
        m_SpeedImage2.fillAmount = Mathf.Lerp(0.252f, 0.328f, Mathf.Clamp01((velocityForwardPercent - 0.5f) / 0.5f));

        velocityForward *= GameConstant.METRE_PER_UNIT;
        m_SpeedText.gameObject.SetActive(velocityForward > 0);
        if (m_SpeedText.gameObject.activeSelf)
        {
            if (velocityForward < 1000)
            {
                m_SpeedText.text = string.Format("{0}M", (int)velocityForward);
            }
            else
            {
                m_SpeedText.text = string.Format("{0:N2}KM", velocityForward / 1000.0f);
            }
        }

        float overloadProgress = main.GetOverloadProgress();

        m_OverloadBar.gameObject.SetActive(isBattle && overloadProgress > 0 && overloadProgress < 1.0f);
        if (m_OverloadBar.gameObject.activeSelf)
        {
            m_OverloadBar.fillAmount  = overloadProgress;
            m_OverloadArrow.anchorMin = new Vector2(m_OverloadArrow.anchorMin.x, 1 - overloadProgress);
            m_OverloadArrow.anchorMax = new Vector2(m_OverloadArrow.anchorMax.x, 1 - overloadProgress);
        }

        /*
         * float upSpeedPercent = Mathf.Clamp(velocityUp / velocityUpMax, -1, 1);
         * m_HeightRule.uvRect = new Rect(0, m_HeightRule.uvRect.y + upSpeedPercent * 0.01f, 1, 1);
         * if (Mathf.Abs(upSpeedPercent) > 0.01f)
         * {
         *  m_HeightBox.gameObject.SetActive(true);
         *  m_HeightArrow.anchorMax = m_HeightArrow.anchorMin = new Vector2(m_HeightArrow.anchorMin.x, 0.5f + upSpeedPercent * 0.5f);
         * }
         * else
         * {
         *  if (Mathf.Abs(m_HeightArrow.anchorMin.y - 0.5f) < 0.01f)
         *  {
         *      m_HeightBox.gameObject.SetActive(false);
         *  }
         *  else
         *  {
         *      m_HeightBox.gameObject.SetActive(true);
         *      m_HeightArrow.anchorMax = m_HeightArrow.anchorMin = new Vector2(m_HeightArrow.anchorMin.x, Mathf.Lerp(m_HeightArrow.anchorMin.y, 0.5f, Time.deltaTime * 3.0f));
         *  }
         * }
         */
    }