TweenFOV.cs 1.6 KB

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