Easer.cs 856 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. using UnityEngine;
  2. namespace HQFPSWeapons
  3. {
  4. public class Easer
  5. {
  6. public float InterpolatedValue { get; private set; }
  7. public Easings.Function Function { get { return m_Function; } set { m_Function = value; } }
  8. public float Duration { get { return m_Duration; } set { m_Duration = value; m_Speed = 1f / m_Duration; } }
  9. private float m_Time;
  10. private float m_Duration;
  11. private Easings.Function m_Function;
  12. private float m_Speed;
  13. public Easer(Easings.Function function, float duration)
  14. {
  15. m_Function = function;
  16. m_Speed = 1f / duration;
  17. }
  18. public void Reset()
  19. {
  20. InterpolatedValue = 0f;
  21. m_Time = 0f;
  22. }
  23. public float Update(float deltaTime)
  24. {
  25. m_Time = Mathf.Clamp01(m_Time + m_Speed * deltaTime);
  26. InterpolatedValue = Easings.Interpolate(m_Time, Function);
  27. return InterpolatedValue;
  28. }
  29. }
  30. }