private void ShowRelivePanel(DeadEvent deadEvent) { //if (m_SpacecraftDeadProperty.IsMain()) //{ // string killerName = "error_name"; // if (deadEvent.KillerNpctemplateID > 0) // { // killerName = TableUtil.GetNpcName(deadEvent.KillerNpctemplateID); // } // else // { // killerName = deadEvent.KillerPlayerName; // } // bool isShowHallRelive = false; // foreach (var item in deadEvent.ReliveOptions) // { // if (item == (short)PlayerReliveType.relive_hall) // { // isShowHallRelive = true; // break; // } // } // GameFacade.Instance.SendNotification(NotificationName.MainHeroDeath, new ShowRelviePanelNotify() // { // IsShowHallRelive = isShowHallRelive, // Countdown = deadEvent.CD, // KillerName = killerName, // }); //} SpacecraftEntity mainPlayer = m_GameplayProxy.GetMainPlayer(); if (mainPlayer.GetTarget() == m_GameplayProxy.GetEntityById <SpacecraftEntity>(m_SpacecraftDeadProperty.GetUId())) { mainPlayer.SetTarget(null, null); } }
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; } } }
/// <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> private void RaycastTarget_OLD() { //检测目标 m_CurrentTarget = m_RaycastProxy.RaycastTarget(m_AutoLockDistance); m_CurrentTargetIsFar = m_RaycastProxy.GetCurrentTargetIsFar(); //准星点追踪 GameplayProxy sceneProxy = Facade.RetrieveProxy(ProxyName.GameplayProxy) as GameplayProxy; SpacecraftEntity main = sceneProxy.GetEntityById<SpacecraftEntity>(sceneProxy.GetMainPlayerUID()); if (main != null && m_Point && m_Frame) { SpacecraftEntity target = main.GetTarget(); m_Point.gameObject.SetActive(true); m_Frame.gameObject.SetActive(true); //通过阵营或者类型判断 bool targetIsEnemy = false; if (target != null) { //是否可攻击 targetIsEnemy = sceneProxy.CanAttackToTarget(main, target); } if (target != null && !m_CurrentTargetIsFar) { m_Point.anchoredPosition = Vector2.zero; ChangeCrosshairColor(target); } else { bool locked = false; Vector2 iconPosition = Vector2.zero; if (target != null) { Vector3 targetPosition = target.transform.position; Vector3 viewportPoint = Camera.main.WorldToViewportPoint(targetPosition); if (viewportPoint.x >= 0 && viewportPoint.y >= 0 && viewportPoint.x <= 1 && viewportPoint.y <= 1 && viewportPoint.z >= Camera.main.nearClipPlane) { Vector2 position2D = Vector2.zero; if (RectTransformUtility.ScreenPointToLocalPointInRectangle(m_Root, Camera.main.WorldToScreenPoint(targetPosition), m_Camera, out position2D)) { iconPosition = position2D; locked = true; } } } m_Point.anchoredPosition = m_AutoLockDistance > 0 ? Vector2.Lerp(m_Point.anchoredPosition, iconPosition, m_LerpValue) : Vector2.zero; ChangeCrosshairColor(target); } float radius = Mathf.Max(m_Frame.sizeDelta.x, m_Frame.sizeDelta.y) / 2.0f; Vector2 centerPoint = RectTransformUtility.WorldToScreenPoint(m_Camera, m_Frame.transform.position); Vector2 rightPoint = RectTransformUtility.WorldToScreenPoint(m_Camera, m_Frame.transform.TransformPoint(Vector3.right * radius)); m_AutoLockDistance = m_AutoLockEnabled ? Mathf.Abs(centerPoint.x - rightPoint.x) : 0; } }