TweenOrthoSize.cs 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. using System;
  2. using UnityEngine;
  3. [RequireComponent(typeof(Camera))]
  4. [AddComponentMenu("NGUI/Tween/Tween Orthographic Size")]
  5. public class TweenOrthoSize : UITweener
  6. {
  7. public Camera cachedCamera
  8. {
  9. get
  10. {
  11. if (this.mCam == null)
  12. {
  13. this.mCam = base.GetComponent<Camera>();
  14. }
  15. return this.mCam;
  16. }
  17. }
  18. [Obsolete("Use 'value' instead")]
  19. public float orthoSize
  20. {
  21. get
  22. {
  23. return this.value;
  24. }
  25. set
  26. {
  27. this.value = value;
  28. }
  29. }
  30. public float value
  31. {
  32. get
  33. {
  34. return this.cachedCamera.orthographicSize;
  35. }
  36. set
  37. {
  38. this.cachedCamera.orthographicSize = value;
  39. }
  40. }
  41. protected override void OnUpdate(float factor, bool isFinished)
  42. {
  43. this.value = this.from * (1f - factor) + this.to * factor;
  44. }
  45. public static TweenOrthoSize Begin(GameObject go, float duration, float to)
  46. {
  47. TweenOrthoSize tweenOrthoSize = UITweener.Begin<TweenOrthoSize>(go, duration);
  48. tweenOrthoSize.from = tweenOrthoSize.value;
  49. tweenOrthoSize.to = to;
  50. if (duration <= 0f)
  51. {
  52. tweenOrthoSize.Sample(1f, true);
  53. tweenOrthoSize.enabled = false;
  54. }
  55. return tweenOrthoSize;
  56. }
  57. public override void SetStartToCurrentValue()
  58. {
  59. this.from = this.value;
  60. }
  61. public override void SetEndToCurrentValue()
  62. {
  63. this.to = this.value;
  64. }
  65. public float from = 1f;
  66. public float to = 1f;
  67. private Camera mCam;
  68. }