TweenOrthoSize.cs 1.4 KB

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