/// <summary> /// 根据刚体速度更新惯性 /// </summary> /// <param name="rect">要微调的UI</param> /// <param name="inertia">惯性设置</param> private void UpdateInertanceByVelocity(RectTransform rect, InertiaWithHud inertia) { SpacecraftEntity main = GetMainEntity(); if (main == null) { return; } Transform mainShadow = main.GetSyncTarget(); if (mainShadow == null) { return; } Rigidbody rigidbody = mainShadow.GetComponent <Rigidbody>(); if (rigidbody == null) { return; } SpacecraftMotionComponent mainMotion = main.GetEntityComponent <SpacecraftMotionComponent>(); if (mainMotion == null) { return; } SpacecraftMotionInfo cruiseMotion = mainMotion.GetCruiseModeMotionInfo(); Vector3 velocity = rigidbody.transform.InverseTransformDirection(rigidbody.velocity); float forwardSpeed = velocity.z; float forwardSpeedMax = cruiseMotion.LineVelocityMax.z; float forwardSpeedPercent = Mathf.Clamp01(Mathf.Abs(forwardSpeed) / Mathf.Abs(forwardSpeedMax)); float upSpeed = velocity.y; float upSpeedMax = cruiseMotion.LineVelocityMax.y; float upSpeedPercent = Mathf.Clamp01(Mathf.Abs(upSpeed) / Mathf.Abs(upSpeedMax)); float rotationSpeed = rigidbody.angularVelocity.y * Mathf.Rad2Deg; float rotationSpeedMax = cruiseMotion.AngularVelocityMax.y; float rotationSpeedPercent = Mathf.Clamp01(Mathf.Abs(rotationSpeed) / Mathf.Abs(rotationSpeedMax)); float forwardDir = Vector3.Dot(rigidbody.velocity.normalized, Camera.main.transform.forward); float x = rotationSpeedPercent * inertia.OffsetX * (rotationSpeed > 0 ? 1 : -1); float y = upSpeedPercent * inertia.OffsetY * (upSpeed > 0 ? 1 : -1); float z = forwardSpeedPercent * inertia.OffsetZ * forwardDir; //Debug.LogError("----> " + // string.Format("{0:N2}", forwardSpeed) + "/" + forwardSpeedMax + " " + // string.Format("{0:N2}", upSpeed) + "/" + upSpeedMax + " " + // string.Format("{0:N2}", rotationSpeed) + "/" + rotationSpeedMax); rect.anchoredPosition3D = new Vector3(x, y, z); }
protected override void Update() { if (!m_Content) { return; } if (!m_Content.gameObject.activeSelf) { return; } GameplayProxy proxy = Facade.RetrieveProxy(ProxyName.GameplayProxy) as GameplayProxy; SpacecraftEntity main = proxy.GetEntityById <SpacecraftEntity>(proxy.GetMainPlayerUID()); if (main == null) { return; } Transform mainShadow = main.GetSyncTarget(); if (mainShadow == null) { return; } Rigidbody rigidbody = mainShadow.GetComponent <Rigidbody>(); if (rigidbody == null) { return; } SpacecraftMotionComponent mainMotion = main.GetEntityComponent <SpacecraftMotionComponent>(); if (mainMotion == null) { return; } SpacecraftMotionInfo cruiseMotion = mainMotion.GetCruiseModeMotionInfo(); Vector3 velocity = rigidbody.transform.InverseTransformDirection(rigidbody.velocity); float upSpeed = velocity.y; float upSpeedMax = cruiseMotion.LineVelocityMax.y; float upSpeedPercent = Mathf.Clamp01(Mathf.Abs(upSpeed) / Mathf.Abs(upSpeedMax)); float dir = upSpeedPercent * (upSpeed > 0 ? 1 : -1); m_Content.SetBool("Opened", upSpeed != 0); m_AltitudeRule.FillAmount = 0.5f - upSpeedPercent * dir * 0.5f; m_AltitudeArrow.FillAmount = 0.5f + upSpeedPercent * dir * 0.5f; //Debug.LogError(string.Format("{0:N2}/{1:N2} = {2:N3}", upSpeed, upSpeedMax, upSpeedPercent)); }
private void OnGUI() { if (GUI.Button(new Rect(0, 0, 100, 50), "获取玩家")) { m_GameplayProxy = GameFacade.Instance.RetrieveProxy(ProxyName.GameplayProxy) as GameplayProxy; m_Entity = m_GameplayProxy.GetMainPlayer(); m_BehaviorComponent = m_Entity.GetEntityComponent <SpacecraftBehaviorComponent>(); } if (GUI.Button(new Rect(0, 100, 100, 50), "战斗")) { if (m_BehaviorComponent == null) { m_GameplayProxy = GameFacade.Instance.RetrieveProxy(ProxyName.GameplayProxy) as GameplayProxy; m_Entity = m_GameplayProxy.GetMainPlayer(); m_BehaviorComponent = m_Entity.GetEntityComponent <SpacecraftBehaviorComponent>(); } else { m_BehaviorComponent.ChangeMainStateTest(EnumMainState.Fight); } } if (GUI.Button(new Rect(100, 0, 100, 50), "巡航")) { if (m_BehaviorComponent == null) { m_GameplayProxy = GameFacade.Instance.RetrieveProxy(ProxyName.GameplayProxy) as GameplayProxy; m_Entity = m_GameplayProxy.GetMainPlayer(); m_BehaviorComponent = m_Entity.GetEntityComponent <SpacecraftBehaviorComponent>(); } else { m_BehaviorComponent.ChangeMainStateTest(EnumMainState.Cruise); } } if (GUI.Button(new Rect(0, 50, 100, 50), "死亡")) { if (m_BehaviorComponent == null) { m_GameplayProxy = GameFacade.Instance.RetrieveProxy(ProxyName.GameplayProxy) as GameplayProxy; m_Entity = m_GameplayProxy.GetMainPlayer(); m_BehaviorComponent = m_Entity.GetEntityComponent <SpacecraftBehaviorComponent>(); } else { m_BehaviorComponent.ChangeMainStateTest(EnumMainState.Dead); } } }
public void SyncDeteCtorDistance(S2C_SYNC_DETECTOR_DISTANCE msg) { ///if (msg.is_active == 0) ///{ /// return; ///} SpacecraftEntity entity = m_GameplayProxy.GetEntityById <SpacecraftEntity>((uint)msg.hero_uid); if (entity) { ChangeMaterialComponent motionComponent = entity.GetEntityComponent <ChangeMaterialComponent>(); if (motionComponent == null) { return; } motionComponent.ChangeEffect(msg.distance, msg.treasure_signal_tid, msg.is_active != 0); } }
/// <summary> /// 更新 /// </summary> protected override void Update() { SpacecraftEntity main = GetMainEntity(); if (main == null) { return; } Transform mainShadow = main.GetSyncTarget(); if (mainShadow == null) { return; } Rigidbody rigidbody = mainShadow.GetComponent <Rigidbody>(); if (rigidbody == null) { return; } SpacecraftMotionComponent motionComponent = main.GetEntityComponent <SpacecraftMotionComponent>(); if (motionComponent == null) { return; } Vector3 shipVelocity = rigidbody.transform.InverseTransformDirection(rigidbody.velocity); SpacecraftMotionInfo shipMotionInfo = motionComponent.GetCruiseModeMotionInfo(); bool isBattle = IsBattling(); bool isOverload = IsOverload(); float hp = (float)main.GetAttribute(AttributeName.kHP); float hpMax = (float)main.GetAttribute(AttributeName.kHPMax); float hpPercent = Mathf.Clamp01(hpMax > 0 ? hp / hpMax : 0); float sp = (float)main.GetAttribute(AttributeName.kShieldValue); float spMax = (float)main.GetAttribute(AttributeName.kShieldMax); float spPercent = Mathf.Clamp01(spMax > 0 ? sp / spMax : 0); float electric = (float)main.GetAttribute(AttributeName.kPowerValue); float electricMax = (float)main.GetAttribute(AttributeName.kPowerMax); float electricPercent = Mathf.Clamp01(electricMax > 0 ? electric / electricMax : 0); float velocityForward = shipVelocity.z; float velocityForwardMax = shipMotionInfo.LineVelocityMax.z; float velocityForwardPercent = velocityForwardMax > 0 ? Mathf.Clamp01(Mathf.Abs(velocityForward) / Mathf.Abs(velocityForwardMax)) : 0; float velocityUp = shipVelocity.y; float velocityUpMax = shipMotionInfo.LineVelocityMax.y; float velocityUpPercent = velocityUpMax > 0 ? Mathf.Clamp01(Mathf.Abs(velocityUp) / Mathf.Abs(velocityUpMax)) : 0; m_HpImage.fillAmount = Mathf.Lerp(0.171f, 0.329f, hpPercent); m_HpLabelBox.localEulerAngles = Vector3.forward * Mathf.Lerp(31.8f, -26.0f, hpPercent); m_HpLabel.text = string.Format("{0}%", Mathf.FloorToInt(hpPercent * 100)); m_SpImage.fillAmount = Mathf.Lerp(0.181f, 0.319f, spPercent); m_SpLabel.gameObject.SetActive(Mathf.Approximately(spPercent, 1.0f)); m_ElectricImage.fillAmount = Mathf.Lerp(0.181f, 0.319f, electricPercent); m_ElectricText.text = string.Format("{0}/{1}", Mathf.CeilToInt(electric), Mathf.FloorToInt(electricMax)); m_OverloadBox.localEulerAngles = Vector3.forward * Mathf.Lerp(-21.86f, 26.0f, electricPercent); m_SpeedImage1.fillAmount = Mathf.Lerp(0.171f, 0.248f, Mathf.Clamp01(velocityForwardPercent / 0.5f)); m_SpeedImage2.fillAmount = Mathf.Lerp(0.252f, 0.328f, Mathf.Clamp01((velocityForwardPercent - 0.5f) / 0.5f)); velocityForward *= GameConstant.METRE_PER_UNIT; m_SpeedText.gameObject.SetActive(velocityForward > 0); if (m_SpeedText.gameObject.activeSelf) { if (velocityForward < 1000) { m_SpeedText.text = string.Format("{0}M", (int)velocityForward); } else { m_SpeedText.text = string.Format("{0:N2}KM", velocityForward / 1000.0f); } } float overloadProgress = main.GetOverloadProgress(); m_OverloadBar.gameObject.SetActive(isBattle && overloadProgress > 0 && overloadProgress < 1.0f); if (m_OverloadBar.gameObject.activeSelf) { m_OverloadBar.fillAmount = overloadProgress; m_OverloadArrow.anchorMin = new Vector2(m_OverloadArrow.anchorMin.x, 1 - overloadProgress); m_OverloadArrow.anchorMax = new Vector2(m_OverloadArrow.anchorMax.x, 1 - overloadProgress); } /* * float upSpeedPercent = Mathf.Clamp(velocityUp / velocityUpMax, -1, 1); * m_HeightRule.uvRect = new Rect(0, m_HeightRule.uvRect.y + upSpeedPercent * 0.01f, 1, 1); * if (Mathf.Abs(upSpeedPercent) > 0.01f) * { * m_HeightBox.gameObject.SetActive(true); * m_HeightArrow.anchorMax = m_HeightArrow.anchorMin = new Vector2(m_HeightArrow.anchorMin.x, 0.5f + upSpeedPercent * 0.5f); * } * else * { * if (Mathf.Abs(m_HeightArrow.anchorMin.y - 0.5f) < 0.01f) * { * m_HeightBox.gameObject.SetActive(false); * } * else * { * m_HeightBox.gameObject.SetActive(true); * m_HeightArrow.anchorMax = m_HeightArrow.anchorMin = new Vector2(m_HeightArrow.anchorMin.x, Mathf.Lerp(m_HeightArrow.anchorMin.y, 0.5f, Time.deltaTime * 3.0f)); * } * } */ }