예제 #1
0
    /// <summary>
    /// 获取目标位置
    /// </summary>
    /// <param name="target">目标</param>
    /// <param name="targetPosition">目标位置</param>
    /// <param name="offsetPosition">偏移量</param>
    /// <param name="hiddenDistance">任务标记的隐藏距离</param>
    /// <returns>是否有效</returns>
    private bool GetTaskPositionInfo(TaskTrackingProxy.TrackingInfo target, out Vector3 targetPosition, out Vector3 offsetPosition, out float hiddenDistance)
    {
        offsetPosition = Vector3.zero;

        if (target.Mode == TaskTrackingProxy.TrackingMode.NpcAndPoint)
        {
            bool    isInSpace = IsInSpace();
            Npc     entityVO  = m_EternityProxy.GetNpcByKey((uint)target.NpcTID);
            Vector3 offset    = entityVO.HeroHeaderLength >= 3 ? new Vector3(entityVO.HeroHeader(0), entityVO.HeroHeader(1), entityVO.HeroHeader(2)) : Vector3.zero;

            BaseEntity entity = null;
            if (target.NpcUID != 0)
            {
                if (isInSpace)
                {
                    entity = m_GamePlayProxy.GetEntityById <SpacecraftEntity>(target.NpcUID);
                }
                else
                {
                    entity = m_GamePlayProxy.GetEntityById <HumanEntity>(target.NpcUID);
                }
            }

            if (entity != null)
            {
                hiddenDistance = entityVO.MissionTargetHiddenDistance;
                targetPosition = entity.transform.position;

                if (isInSpace && entity.GetHeroType() != KHeroType.htMonster)
                {
                    offsetPosition = entity.transform.TransformDirection(offset);
                }
                else if (!isInSpace)
                {
                    offsetPosition = entity.transform.TransformDirection(offset);
                }

                return(true);
            }
            else
            {
                hiddenDistance = entityVO.MissionTargetHiddenDistance;
                targetPosition = m_GamePlayProxy.WorldPositionToClientPosition(target.Position);
                return(true);
            }
        }
        else if (target.Mode == TaskTrackingProxy.TrackingMode.LeapPoint)
        {
            hiddenDistance = 0;
            targetPosition = m_GamePlayProxy.WorldPositionToClientPosition(target.Position);
            return(true);
        }

        hiddenDistance = 0;
        targetPosition = Vector3.zero;
        return(false);
    }
예제 #2
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);
            }
        }
    }
예제 #3
0
    /// <summary>
    /// 更新
    /// </summary>
    protected override void Update()
    {
        CfgEternityProxy  eternityProxy     = Facade.RetrieveProxy(ProxyName.CfgEternityProxy) as CfgEternityProxy;
        TaskTrackingProxy taskTrackingProxy = Facade.RetrieveProxy(ProxyName.TaskTrackingProxy) as TaskTrackingProxy;

        if (!IsWatchOrUIInputMode() && !IsDead() && !IsLeaping())
        {
            GameplayProxy gamePlayProxy = Facade.RetrieveProxy(ProxyName.GameplayProxy) as GameplayProxy;
            BaseEntity    main          = gamePlayProxy.GetEntityById <BaseEntity>(gamePlayProxy.GetMainPlayerUID());

            List <SpacecraftEntity> humanList = gamePlayProxy.GetEntities <SpacecraftEntity>(KHeroType.htNpc);
            foreach (SpacecraftEntity entity in humanList)
            {
                if (entity.GetHeroType() != KHeroType.htNpc)
                {
                    continue;
                }

                Npc entityVO = eternityProxy.GetNpcByKey(entity.GetTemplateID());
                if (entityVO.Display == 0)
                {
                    continue;
                }

                Vector3 titleOffset    = entityVO.HeroHeaderLength >= 3 ? new Vector3(entityVO.HeroHeader(0), entityVO.HeroHeader(1), entityVO.HeroHeader(2)) : Vector3.zero;
                Vector3 targetPosition = entity.transform.position + entity.transform.TransformDirection(titleOffset);

                //屏幕外忽略
                if (!IsInScreen(targetPosition, Camera.main))
                {
                    continue;
                }

                //太远忽略
                float targetDistance = Vector3.Distance(entity.transform.position, main.transform.position) * GameConstant.METRE_PER_UNIT;
                if (targetDistance >= entityVO.MissionTargetHiddenDistance * GameConstant.METRE_PER_UNIT)
                {
                    continue;
                }

                Vector2 iconPosition;
                Vector3 screenPosition = Camera.main.WorldToScreenPoint(targetPosition);
                if (RectTransformUtility.ScreenPointToLocalPointInRectangle(m_FlagBox, screenPosition, m_CanvasCamera, out iconPosition))
                {
                    bool isNew    = false;
                    uint entityID = entity.GetUId();

                    //创建标记
                    RectTransform flag = m_NpcID2FlagA.ContainsKey(entityID) ? m_NpcID2FlagA[entityID] : null;
                    if (flag == null)
                    {
                        if (m_IdleBox.childCount > 0)
                        {
                            flag = m_IdleBox.GetChild(0).GetComponent <RectTransform>();
                            flag.gameObject.SetActive(true);
                            flag.SetParent(m_FlagBox);
                        }
                        else
                        {
                            flag = Object.Instantiate(m_FlagTemplate, m_FlagBox);
                            flag.gameObject.SetActive(true);
                        }
                        isNew = true;
                    }
                    m_NpcID2FlagA.Remove(entityID);
                    m_NpcID2FlagB.Add(entityID, flag);

                    //标记坐标
                    flag.anchoredPosition = new Vector2(iconPosition.x, iconPosition.y);

                    //名称文本
                    if (isNew)
                    {
                        flag.Find("Name/Label_NPCName").GetComponent <TMP_Text>().text = TableUtil.GetNpcName(entity.GetTemplateID());

                        Image npcIcon = flag.Find("IconBox/IconScenceNameElement/Image_NpcIcon").GetComponent <Image>();
                        npcIcon.color = entityVO.NameBoardIcon == 0 ? Color.clear : Color.white;
                        if (entityVO.NameBoardIcon != 0)
                        {
                            UIUtil.SetIconImage(npcIcon, entityVO.NameBoardIcon);
                        }
                    }

                    //任务
                    TaskTrackingProxy.TrackingInfo tracking = taskTrackingProxy.GetNpcMission(entity.GetUId(), entity.GetTemplateID());
                    MissionType missionType = tracking != null ? tracking.MissionType : MissionType.None;

                    //任务状态
                    RectTransform flagIcon            = FindComponent <RectTransform>(flag, "IconBox");
                    RectTransform flagMission         = FindComponent <RectTransform>(flag, "MissionBox");
                    Animator      flagMissionAnimator = FindComponent <Animator>(flagMission, "IconMissionElement");
                    Image         flagMissionIcon     = FindComponent <Image>(flagMissionAnimator, "Icon").GetComponent <Image>();

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

                    flagMission.gameObject.SetActive(missionType != MissionType.None);
                    flagIcon.gameObject.SetActive(!flagMission.gameObject.activeSelf);
                    taskTrackingProxy.SetAreadyAddMissionInfo(entity.GetUId(), entity.GetTemplateID());

                    flagMissionAnimator.SetBool("Finished", tracking != null && tracking.MissionState == MissionState.Finished);

                    /*
                     * //图标动画
                     * Animator flagIconAnimator = flag.Find("IconBox").GetComponent<Animator>();
                     * if (flagIconAnimator != null && flagIconAnimator.runtimeAnimatorController != null && flagIconAnimator.isActiveAndEnabled)
                     * {
                     *  flagIconAnimator.ResetTrigger("Open");
                     *  flagIconAnimator.ResetTrigger("Close");
                     *  flagIconAnimator.SetTrigger(targetDistance <= GameConstant.DEFAULT_HUMAN_TITLE_SHOW_RANGE * 2 ? "Open" : "Close");
                     * }
                     *
                     * //名称动画
                     * Animator flagTextAnimator = flag.Find("Name").GetComponent<Animator>();
                     * if (flagTextAnimator != null && flagTextAnimator.runtimeAnimatorController != null && flagTextAnimator.isActiveAndEnabled)
                     * {
                     *  flagTextAnimator.ResetTrigger("Open");
                     *  flagTextAnimator.ResetTrigger("Close");
                     *  flagTextAnimator.SetTrigger(targetDistance <= GameConstant.DEFAULT_HUMAN_TITLE_SHOW_RANGE ? "Open" : "Close");
                     * }
                     */
                }
            }
        }

        //回收标记
        foreach (var flag in m_NpcID2FlagA)
        {
            taskTrackingProxy.SetAreadyAddMissionInfo(flag.Key, 0, true);
            flag.Value.gameObject.SetActive(false);
            flag.Value.SetParent(m_IdleBox);
        }
        m_NpcID2FlagA.Clear();

        //交换缓存
        Dictionary <uint, RectTransform> tmp = m_NpcID2FlagA;

        m_NpcID2FlagA = m_NpcID2FlagB;
        m_NpcID2FlagB = tmp;
    }
예제 #4
0
    /// <summary>
    /// 更新所有任务标记
    /// </summary>
    protected override void Update()
    {
        if (!IsWatchOrUIInputMode() && !IsLeaping() && !IsDead())
        {
            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_TargetUIDs.Clear();

            BaseEntity main = m_GamePlayProxy.GetEntityById <BaseEntity>(m_GamePlayProxy.GetMainPlayerUID());

            bool isInSpace = IsInSpace();

            m_EdgeEntitys.Clear();

            List <TaskTrackingProxy.TrackingInfo> trackingList = m_TrakingProxy.GetAllTrackings();
            for (int i = 0; i < trackingList.Count; i++)
            {
                TaskTrackingProxy.TrackingInfo target = trackingList[i];

                //忽略重复的引导
                if (target.NpcUID != 0 && m_TargetUIDs.Contains(target.NpcUID))
                {
                    continue;
                }

                //目标位置信息
                Vector3 originPosition  = Vector3.zero;
                Vector3 offsetPosition  = Vector3.zero;
                float   hiddentDistance = 0;
                if (!GetTaskPositionInfo(target, out originPosition, out offsetPosition, out hiddentDistance))
                {
                    continue;
                }

                hiddentDistance *= (isInSpace ? GameConstant.METRE_PER_UNIT : 1);

                //原点距离
                float originDistance = Vector3.Distance(originPosition, main.transform.position) * (isInSpace ? GameConstant.METRE_PER_UNIT : 1);

                //目标位置
                Vector3 targetPosition = originPosition + offsetPosition;

                //过远提示
                if (target.FarNotice)
                {
                    if (originDistance > target.FarNoticeDistance)
                    {
                        GameFacade.Instance.SendNotification(NotificationName.MSG_INTERACTIVE_MISSIONESCORT, true);
                    }
                    else
                    {
                        GameFacade.Instance.SendNotification(NotificationName.MSG_INTERACTIVE_MISSIONESCORT, false);
                    }
                }

                //是否在屏幕内
                bool isInScreen = IsInScreen(targetPosition, m_MainCamera);

                //屏幕内跃迁点的任务引导由跃迁点自已显示
                if (isInScreen && target.Mode == TaskTrackingProxy.TrackingMode.LeapPoint)
                {
                    continue;
                }

                if (target.Mode == TaskTrackingProxy.TrackingMode.NpcAndPoint && originDistance < hiddentDistance)
                {
                    Npc entityVO = m_EternityProxy.GetNpcByKey((uint)target.NpcTID);
                    if (entityVO.Display == 0)
                    {
                        continue;
                    }
                    else if (isInScreen)
                    {
                        continue;
                    }
                }

                //取出标记视图
                Entity flag = m_Task2Entity1.ContainsKey(target) ? m_Task2Entity1[target] : null;
                if (flag == null)
                {
                    flag = new Entity();
                    if (m_IdleBox.childCount > 0)
                    {
                        flag.View = m_IdleBox.GetChild(0).GetComponent <RectTransform>();
                        flag.View.SetParent(m_FlagBox);
                        flag.View.localScale = Vector3.one;
                        flag.View.gameObject.SetActive(true);
                    }
                    else
                    {
                        flag.View            = Object.Instantiate(m_FlagTemplate, m_FlagBox);
                        flag.View.localScale = Vector3.one;
                        flag.View.gameObject.SetActive(true);
                    }

                    flag.MissionNode = FindComponent <Animator>(flag.View, "IconMissionElement");
                    flag.Icon        = FindComponent <Image>(flag.MissionNode, "Icon");
                    flag.Arrow       = FindComponent <RectTransform>(flag.View, "Arrow");
                    flag.Label       = FindComponent <TMP_Text>(flag.View, "Label_DistanceText");

                    flag.MissionNode.SetBool("Finished", target.MissionState == MissionState.Finished);

                    //图标显示
                    MissionType missionType = target.MissionType;
                    if (target.Mode == TaskTrackingProxy.TrackingMode.NpcAndPoint)
                    {
                        missionType = m_TrakingProxy.GetNpcMissionType(target.NpcUID, (uint)target.NpcTID);
                    }

                    UIUtil.SetIconImage(flag.Icon, GameConstant.FUNCTION_ICON_ATLAS_ASSETADDRESS, GetMissionIcon(missionType));
                }

                m_Task2Entity1.Remove(target);
                m_Task2Entity2.Add(target, flag);

                //屏幕内
                if (isInScreen)
                {
                    Vector3 screenPoint = m_MainCamera.WorldToScreenPoint(targetPosition);
                    Vector2 localPoint  = Vector2.zero;
                    if (RectTransformUtility.ScreenPointToLocalPointInRectangle(m_FlagBox, screenPoint, m_UICamera, out localPoint))
                    {
                        flag.View.anchoredPosition = localPoint;
                    }
                }

                //方向箭头
                flag.Arrow.gameObject.SetActive(!isInScreen);
                if (!isInScreen)
                {
                    Vector3 inCameraPosition = m_MainCamera.transform.InverseTransformPoint(targetPosition);
                    flag.Arrow.transform.localRotation = Quaternion.Euler(0, 0, Mathf.Atan2(inCameraPosition.y, inCameraPosition.x) * Mathf.Rad2Deg - 90);
                }

                //距离显示
                flag.Label.gameObject.SetActive(true);
                if (flag.Label.gameObject.activeSelf)
                {
                    flag.Label.text = FormatMetre(originDistance);
                }

                //目标位置
                flag.TargetPosition = targetPosition;

                //放入边缘列表
                if (!isInScreen)
                {
                    m_EdgeEntitys.Add(flag);
                }


                if (target.NpcUID != 0)
                {
                    m_TargetUIDs.Add(target.NpcUID);
                }
            }
        }

        //回收标记
        foreach (Entity flag in m_Task2Entity1.Values)
        {
            flag.View.gameObject.SetActive(false);
            flag.View.SetParent(m_IdleBox);
        }
        m_Task2Entity1.Clear();

        //交换缓存
        Dictionary <TaskTrackingProxy.TrackingInfo, Entity> tmp = m_Task2Entity1;

        m_Task2Entity1 = m_Task2Entity2;
        m_Task2Entity2 = tmp;

        //布局边缘图标
        LayoutEntityList(m_EdgeEntitys);
        m_EdgeEntitys.Clear();
    }
예제 #5
0
    /// <summary>
    /// 更新任务状态
    /// </summary>
    private void UpdateMissionState()
    {
        TaskTrackingProxy trakingProxy = Facade.RetrieveProxy(ProxyName.TaskTrackingProxy) as TaskTrackingProxy;

        for (int i = 0; i < m_LeapCfgs.Count; i++)
        {
            LeapItem leapVO = m_LeapCfgs[i];
            uint     leapID = (uint)leapVO.LeapId;

            RectTransform point = m_PointBox.GetChild(i).GetComponent <RectTransform>();
            if (point.gameObject.activeSelf)
            {
                RectTransform box1 = point.Find("MissionBox").GetComponent <RectTransform>();
                RectTransform box2 = point.Find("JumpTips/MissionBox").GetComponent <RectTransform>();

                int index = 0;

                List <TaskTrackingProxy.TrackingInfo> trackingList = trakingProxy.GetLeapTrackings(leapID);
                if (trackingList != null)
                {
                    for (int j = 0; j < trackingList.Count; j++)
                    {
                        TaskTrackingProxy.TrackingInfo tracking = trackingList[j];
                        RectTransform icon1 = index < box1.childCount ? box1.GetChild(j).GetComponent <RectTransform>() : null;
                        if (icon1 == null)
                        {
                            if (m_MissionIdleBox.childCount > 0)
                            {
                                icon1 = m_MissionIdleBox.GetChild(0).GetComponent <RectTransform>();
                            }
                            else
                            {
                                icon1 = Object.Instantiate(m_MissionTemplate, box1);
                            }

                            icon1.SetParent(box1);
                            icon1.gameObject.SetActive(true);
                        }

                        RectTransform icon2 = index < box2.childCount ? box2.GetChild(j).GetComponent <RectTransform>() : null;
                        if (icon2 == null)
                        {
                            if (m_MissionIdleBox.childCount > 0)
                            {
                                icon2 = m_MissionIdleBox.GetChild(0).GetComponent <RectTransform>();
                            }
                            else
                            {
                                icon2 = Object.Instantiate(m_MissionTemplate, box2);
                            }

                            icon2.SetParent(box2);
                            icon2.gameObject.SetActive(true);
                        }

                        string missionIcon = GetMissionIcon(tracking.MissionType);
                        UIUtil.SetIconImage(icon1.Find("Icon").GetComponent <Image>(), GameConstant.FUNCTION_ICON_ATLAS_ASSETADDRESS, missionIcon);
                        UIUtil.SetIconImage(icon2.Find("Icon").GetComponent <Image>(), GameConstant.FUNCTION_ICON_ATLAS_ASSETADDRESS, missionIcon);

                        bool missionFinished = tracking.MissionState == MissionState.Finished;
                        icon1.GetComponent <Animator>().SetBool("Finished", missionFinished);
                        icon2.GetComponent <Animator>().SetBool("Finished", missionFinished);

                        index++;
                    }
                }

                while (index < box1.childCount)
                {
                    box1.GetChild(index).gameObject.SetActive(false);
                    box1.GetChild(index).SetParent(m_MissionIdleBox);
                }
                while (index < box2.childCount)
                {
                    box2.GetChild(index).gameObject.SetActive(false);
                    box2.GetChild(index).SetParent(m_MissionIdleBox);
                }
            }
        }
    }