TweenOrthoSize.cs 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. using UnityEngine;
  2. /// <summary>
  3. /// Tween the camera's orthographic size.
  4. /// </summary>
  5. [RequireComponent(typeof(Camera))]
  6. public class TweenOrthoSize : Tweener
  7. {
  8. public float from = 1f;
  9. public float to = 1f;
  10. Camera mCam;
  11. /// <summary>
  12. /// Camera that's being tweened.
  13. /// </summary>
  14. public Camera cachedCamera {
  15. get {
  16. if (mCam == null)
  17. mCam = GetComponent<Camera>();
  18. return mCam;
  19. }
  20. }
  21. /// <summary>
  22. /// Tween's current value.
  23. /// </summary>
  24. public float value {
  25. get {
  26. return cachedCamera.orthographicSize;
  27. }
  28. set {
  29. cachedCamera.orthographicSize = value;
  30. }
  31. }
  32. /// <summary>
  33. /// Tween the value.
  34. /// </summary>
  35. protected override void OnUpdate(float factor, bool isFinished)
  36. {
  37. value = from * (1f - factor) + to * factor;
  38. }
  39. /// <summary>
  40. /// Start the tweening operation.
  41. /// </summary>
  42. static public TweenOrthoSize Begin(GameObject go, float duration, float to)
  43. {
  44. TweenOrthoSize comp = Tweener.Begin<TweenOrthoSize>(go, duration);
  45. comp.from = comp.value;
  46. comp.to = to;
  47. if (duration <= 0f)
  48. {
  49. comp.Sample(1f, true);
  50. comp.enabled = false;
  51. }
  52. return comp;
  53. }
  54. public override void SetStartToCurrentValue()
  55. {
  56. from = value;
  57. }
  58. public override void SetEndToCurrentValue()
  59. {
  60. to = value;
  61. }
  62. }