예제 #1
0
    /// <summary>
    /// 显示开宝箱
    /// </summary>
    public void ShowOpenChest()
    {
        if (!IsDead() && !IsBattling() && !IsLeaping() && !IsWatchOrUIInputMode())
        {
            SpacecraftEntity entity = m_RaycastProxy.Raycast();
            if (entity && (entity.GetCurrentState().GetMainState() != EnumMainState.Dead) && entity.GetHeroType() == KHeroType.htLockChest)
            {
                Vector3 titleOffset = Vector3.zero;
                m_TargetNpcUID = entity.GetUId();
                //头顶偏移

                Npc entityVO = m_CfgEternityProxy.GetNpcByKey(entity.GetTemplateID());
                if (Vector3.Distance(entity.transform.position, m_MainEntity.transform.position) > entityVO.TriggerRange)
                {
                    return;
                }
                if (entityVO.HeroHeaderLength >= 3)
                {
                    titleOffset = new Vector3(entityVO.HeroHeader(0), entityVO.HeroHeader(1), entityVO.HeroHeader(2));
                }

                //忽略屏幕外的
                Vector3 screenPosition = m_MainCamera.WorldToScreenPoint(entity.transform.TransformPoint(titleOffset));
                if (screenPosition.z > m_MainCamera.nearClipPlane && screenPosition.x >= 0 && screenPosition.x <= m_MainCamera.pixelWidth && screenPosition.y > 0 && screenPosition.y <= Camera.main.pixelHeight)
                {
                    Vector2 anchoredPosition;
                    if (RectTransformUtility.ScreenPointToLocalPointInRectangle(m_Root, screenPosition, m_Camera, out anchoredPosition))
                    {
                        m_Content.anchorMin        = m_Content.anchorMax = Vector2.one * 0.5f;
                        m_Content.anchoredPosition = anchoredPosition;
                    }

                    if (!m_Content.gameObject.activeSelf && entity.GetIsActive())
                    {
                        m_Content.gameObject.SetActive(true);
                        ResetAnimators(null, HotkeyPhase.Disabled, true);
                    }
                }
                else
                {
                    m_Content.gameObject.SetActive(false);
                }
                return;
            }
            else
            {
                m_Content.gameObject.SetActive(false);
            }
        }
        else
        {
            m_Content.gameObject.SetActive(false);
        }
    }
예제 #2
0
    /// <summary>
    /// 创建时
    /// </summary>
    private void OnTargetCreate(SpacecraftEntity target, RectTransform view)
    {
        KHeroType entityType = target.GetHeroType();

        if (entityType == KHeroType.htMine)
        {
            TMP_Text nameField = view.Find("Name/Name/Label_Name").GetComponent <TMP_Text>();
            nameField.text = entityType == KHeroType.htPlayer ? target.GetName() : TableUtil.GetNpcName(target.GetTemplateID());

            //血段
            m_LineGrid = FindComponent <Transform>(view, "Slider/Image_Bar/LineGrid");

            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);
                }
            }
        }
        else
        {
            //目标名称
            TMP_Text nameField = view.Find("Name/Name").GetComponent <TMP_Text>();
            nameField.text = entityType == KHeroType.htPlayer ? target.GetName() : TableUtil.GetNpcName(target.GetTemplateID());

            //目标图标
            Image image = view.Find("Name/Icon/ImageIcon").GetComponent <Image>();
            image.gameObject.SetActive(entityType != KHeroType.htPlayer);
            if (image.gameObject.activeSelf)
            {
                Npc entityVO = m_CfgEternityProxy.GetNpcByKey(target.GetTemplateID());
                if (entityVO.NameBoardIcon == 0)
                {
                    image.color = Color.clear;
                }
                else
                {
                    image.color = Color.white;
                    UIUtil.SetIconImage(image, entityVO.NameBoardIcon);
                }
            }
        }
    }
예제 #3
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);
            }
        }
    }
예제 #4
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;
    }
예제 #5
0
    /// <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);
            }
        }
    }
예제 #6
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;
    }