/// <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); } }
/// <summary> /// 显示BuffIcon /// </summary> public void OnAddBufferIcon(SpacecraftEntity target) { RectTransform view = null; if (m_UIDToRectTranform1.ContainsKey(target.GetUId())) { view = m_UIDToRectTranform1[target.GetUId()].view; } else { if (m_UIDToRectTranform2.ContainsKey(target.GetUId())) { view = m_UIDToRectTranform2[target.GetUId()].view; } else { return; } } Transform bufferIconBox = view.Find("BuffIconBox"); if (bufferIconBox == null) { return; } bufferIconBox.gameObject.SetActive(true); Transform iconTemplate = bufferIconBox.GetChild(0); iconTemplate.gameObject.SetActive(false); int index = 0; if (target.GetAllBuffs().Count > 0) { foreach (KeyValuePair <uint, Buff> buffID2Value in target.GetAllBuffs()) { SkillBuff configVO = m_SkillProxy.GetBuff((int)buffID2Value.Key); Transform iconTras; if (configVO.ByteBuffer != null) { if ((BufferType)configVO.BuffHudShow == BufferType.None) { continue; } // Debug.LogError(target.GetName() + "==============" + configVO.Id + "========" //+ target.GetAllBuffs().Count + "=======" + (BufferType)configVO.BuffHudShow); index++; if (bufferIconBox.childCount >= index) { iconTras = bufferIconBox.GetChild(index - 1); } else { iconTras = Object.Instantiate(iconTemplate); iconTras.SetParent(bufferIconBox); iconTras.localScale = Vector3.one; iconTras.localPosition = Vector3.zero; iconTras.SetAsLastSibling(); } bufferIconBox.localScale = Vector3.one; if (m_MainEntity == target) { bufferIconBox.localScale = Vector3.one * 1.5f; } if ((uint)configVO.BuffHudIcon > 0) { UIUtil.SetIconImage(iconTras.GetComponent <Image>(), (uint)configVO.BuffHudIcon); } else { Debug.LogWarning("报错" + configVO.Id); } //Debug.Log(configVO.BuffHudIcon + "-=-=-=-=-=-" + configVO.BuffHudShow); switch ((BufferType)configVO.BuffHudShow) { case BufferType.All: // 1 全体 iconTras.gameObject.SetActive(true); break; case BufferType.Friend: // 2 友方 if (m_TeamProxy.GetMember(target.GetPlayerId()) != null) { iconTras.gameObject.SetActive(true); } break; case BufferType.Enemy: // 3 敌方 if (m_MainEntity != target && m_TeamProxy.GetMember(target.GetPlayerId()) == null) { iconTras.gameObject.SetActive(true); } break; case BufferType.Self: // 4 自己 if (m_MainEntity = target) { iconTras.gameObject.SetActive(true); } break; default: break; } } } // Debug.Log(index); for (int i = index; i < bufferIconBox.childCount; i++) { bufferIconBox.GetChild(i).gameObject.SetActive(false); } } else { for (int i = 0; i < bufferIconBox.childCount; i++) { bufferIconBox.GetChild(i).gameObject.SetActive(false); } } }
/// <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); } } }
/// <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> /// 更新所有任务标记 /// </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; }