/// <summary> /// 如果此特效是一个射线特效, 设置射线的目标 /// 如果特效不是射线, 则不会有任何效果 /// </summary> /// <param name="targetTransform">目标Transform, 射线以此为结束点</param> /// <param name="offset">射线结束点相对于targetTransform的偏移</param> /// <param name="updateHitPoint">是否根据目标Collider的形状每帧更新射线弹着点</param> /// <param name="targetColliderList">只有需要每帧更新弹着点的时候才需要设置这个参数。 目标拥有的所有Collider</param> public void SetBeamTarget(Transform startTransform, Transform targetTransform, Vector3 offset, bool updateHitPoint = false, List <Collider> targetColliderList = null) { if (m_VFXController == null) { m_OpCache_SetBeamTarget = true; m_OpCache_BeamStartTransform = startTransform; m_OpCache_BeamTargetTransform = targetTransform; m_OpCache_BeamTargetOffset = offset; m_OpCache_UpdateHitPoint = updateHitPoint; m_OpCache_TargetColliderList = targetColliderList; m_OpCache_TargetPoint = targetTransform.position + offset; } else { m_OpCache_SetBeamTarget = false; VFXBeam beam = m_VFXController.GetComponent <VFXBeam>(); if (beam != null) { beam.SetBeamTarget(transform, targetTransform , offset, updateHitPoint, m_OpCache_TargetColliderList); } } }
/// <summary> /// 收到任何伤害消息时 /// </summary> /// <param name="targetID">目标ID</param> private void OnAnyHurt(uint targetID) { if (m_TargetViewer.EffectArray != null) { foreach (EffectController effect in m_TargetViewer.EffectArray) { VFXController effectObject = effect.GetEffectObject(); if (effectObject) { Animator animator = effectObject.GetComponent <Animator>(); if (animator) { animator.SetTrigger("hurting"); } } } } }
/// <summary> /// 调整描边特效颜色 /// </summary> private void AdjustOutlineEffectColor() { if (m_Property != null && m_Property.GetHeroType() == KHeroType.htMine) { if (m_OutlineVFX != null) { VFXController effectObject = m_OutlineVFX.GetEffectObject(); if (effectObject) { Animator animator = effectObject.GetComponent <Animator>(); if (animator) { float hp = (float)m_Property.GetOwner().GetAttribute(AttributeName.kHP); float hpMax = (float)m_Property.GetOwner().GetAttribute(AttributeName.kHPMax); float hpProgress = hpMax <= 0 ? 0 : hp / hpMax; animator.SetFloat("Color", 0); } } } } }
/// <summary> /// 更新UI /// </summary> private void UpdateUI() { if (m_NearestTarget) { m_NearestTarget.GetSkinRootTransform(); float hp = (float)m_NearestTarget.GetAttribute(AttributeName.kHP); float hpMax = (float)m_NearestTarget.GetAttribute(AttributeName.kHPMax); float hpProgress = hpMax <= 0 ? 0 : hp / hpMax; //int phase = Mathf.Min(4, Mathf.FloorToInt(hpProgress / (1.0f / 5))); m_HpBar.fillAmount = hpProgress; m_HpBarLabel.text = Mathf.FloorToInt(hpProgress * 100) + "%"; m_HpBarState.text = ""; // GetLocalization("hud_text_id_" + (1021 + phase)); if (m_TargetViewer && m_TargetViewer.Camera && m_TargetViewer.ModelArray != null) { if (m_TargetList.Count > 0) { for (int i = 0; i < m_TargetViewer.ModelArray.Length; i++) { SpacecraftEntity entity = m_GameplayProxy.GetEntityById <SpacecraftEntity>(m_TargetList[i]); if (entity != null) { Transform skinTransform = entity.GetSkinTransform(); if (skinTransform != null) { for (int k = 0; k < m_TargetViewer.ModelArray[i].transform.childCount; k++) { Transform child = m_TargetViewer.ModelArray[i].transform; if (child.GetChild(k).GetComponent <EffectController>() != null) { continue; } string name = child.GetChild(k).name; if (skinTransform.Find(name) == null) { child.GetChild(k).gameObject.SetActive(false); } else { child.GetChild(k).gameObject.SetActive(true); } } } } else { GameObject currentModel = m_TargetViewer.ModelArray[i]; for (int j = 0; j < currentModel.transform.childCount; j++) { if (currentModel.transform.GetChild(j).GetComponent <EffectController>() != null) { continue; } currentModel.transform.GetChild(j).gameObject.SetActive(false); } } } } Transform skin = m_NearestTarget.GetSkinTransform(); if (skin) { Camera mainCamera = CameraManager.GetInstance().GetMainCamereComponent().GetCamera(); GameplayProxy sceneProxy = Facade.RetrieveProxy(ProxyName.GameplayProxy) as GameplayProxy; SpacecraftEntity mainHero = sceneProxy.GetEntityById <SpacecraftEntity>(sceneProxy.GetMainPlayerUID()); float bestDistance = m_TargetViewer.ModelBoundsDiagonalLength / 2.0f / Mathf.Tan(mainCamera.fieldOfView * Mathf.Deg2Rad / 2.0f); Vector3 bestDirection = mainCamera.transform.position - mainHero.transform.position; m_TargetViewer.ModelBox.rotation = skin.rotation; m_TargetViewer.Camera.transform.position = m_TargetViewer.ModelBox.position + bestDirection.normalized * bestDistance; m_TargetViewer.Camera.transform.LookAt(m_TargetViewer.ModelBox); } } if (m_TargetViewer.EffectArray != null) { foreach (EffectController effect in m_TargetViewer.EffectArray) { VFXController effectObject = effect.GetEffectObject(); if (effectObject) { Animator animator = effectObject.GetComponent <Animator>(); if (animator) { animator.SetFloat("Color", 1 - hpProgress); } } } } } else { m_HpBarState.text = GetLocalization("hud_text_id_" + 1021); } }