TweenFOV.cs 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. using System;
  2. using UnityEngine;
  3. [RequireComponent(typeof(Camera))]
  4. [AddComponentMenu("NGUI/Tween/Tween Field of View")]
  5. public class TweenFOV : 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 fov
  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.fieldOfView;
  35. }
  36. set
  37. {
  38. this.cachedCamera.fieldOfView = 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 TweenFOV Begin(GameObject go, float duration, float to)
  46. {
  47. TweenFOV tweenFOV = UITweener.Begin<TweenFOV>(go, duration);
  48. tweenFOV.from = tweenFOV.value;
  49. tweenFOV.to = to;
  50. if (duration <= 0f)
  51. {
  52. tweenFOV.Sample(1f, true);
  53. tweenFOV.enabled = false;
  54. }
  55. return tweenFOV;
  56. }
  57. [ContextMenu("Set 'From' to current value")]
  58. public override void SetStartToCurrentValue()
  59. {
  60. this.from = this.value;
  61. }
  62. [ContextMenu("Set 'To' to current value")]
  63. public override void SetEndToCurrentValue()
  64. {
  65. this.to = this.value;
  66. }
  67. [ContextMenu("Assume value of 'From'")]
  68. private void SetCurrentValueToStart()
  69. {
  70. this.value = this.from;
  71. }
  72. [ContextMenu("Assume value of 'To'")]
  73. private void SetCurrentValueToEnd()
  74. {
  75. this.value = this.to;
  76. }
  77. public float from = 45f;
  78. public float to = 45f;
  79. private Camera mCam;
  80. }