/// <summary>Bring the axis back to the centered state (only if enabled).</summary> public void DoRecentering(ref AxisState axis, float deltaTime, float recenterTarget) { if (!m_enabled && deltaTime >= 0) { return; } recenterTarget = axis.ClampValue(recenterTarget); if (deltaTime < 0) { CancelRecentering(); axis.Value = recenterTarget; return; } float v = axis.ClampValue(axis.Value); float delta = recenterTarget - v; if (delta == 0) { return; } if (Time.time < (mLastAxisInputTime + m_WaitTime)) { return; } // Determine the direction float r = axis.m_MaxValue - axis.m_MinValue; if (axis.m_Wrap && Mathf.Abs(delta) > r * 0.5f) { v += Mathf.Sign(recenterTarget - v) * r; } // Damp our way there if (m_RecenteringTime < 0.001f) { v = recenterTarget; } else { v = Mathf.SmoothDamp( v, recenterTarget, ref mRecenteringVelocity, m_RecenteringTime, 9999, deltaTime); } axis.Value = axis.ClampValue(v); }
/// <summary>Bring the axis back to the centered state (only if enabled).</summary> public void DoRecentering(ref AxisState axis, float deltaTime, float recenterTarget) { if (!m_enabled && deltaTime >= 0) { return; } recenterTarget = axis.ClampValue(recenterTarget); if (deltaTime < 0) { CancelRecentering(); if (m_enabled) { axis.Value = recenterTarget; } return; } float v = axis.ClampValue(axis.Value); float delta = recenterTarget - v; if (delta == 0) { return; } float input = 0; if (m_NeedReTimingInputAxisName != "") { string[] names = m_NeedReTimingInputAxisName.Split(';'); for (int i = 0; i < names.Length; i++) { if (CinemachineCore.GetInputAxis(names[i]) != 0) { input = 1; break; } } } if (input != 0) { CancelRecentering(); } input = 0; if (m_NeedRecenterInputAxisName != "") { string[] names = m_NeedRecenterInputAxisName.Split(';'); for (int i = 0; i < names.Length; i++) { if (CinemachineCore.GetInputAxis(names[i]) != 0) { input = 1; break; } } } if (Time.time < (mLastAxisInputTime + m_WaitTime) && input == 0) { return; } // Determine the direction float r = axis.m_MaxValue - axis.m_MinValue; if (axis.m_Wrap && Mathf.Abs(delta) > r * 0.5f) { v += Mathf.Sign(recenterTarget - v) * r; } // Damp our way there float recenteringTime = input == 0? m_RecenteringTime : m_RecenterInputAxisTime; if (recenteringTime < 0.001f) { v = recenterTarget; } else { v = Mathf.SmoothDamp( v, recenterTarget, ref mRecenteringVelocity, recenteringTime, 9999, deltaTime); } axis.Value = axis.ClampValue(v); }