/// <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); } } } }
/// <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); } } }