| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- //----------------------------------------------
- // NGUI: Next-Gen UI kit
- // Copyright © 2011-2014 Tasharen Entertainment
- //----------------------------------------------
- using UnityEngine;
- using UnityEngine.UI;
- /// <summary>
- /// Tween the camera's field of view.
- /// </summary>
- [RequireComponent(typeof(Camera))]
- public class TweenFOV : Tweener
- {
- public float from = 45f;
- public float to = 45f;
- Camera mCam;
- public Camera cachedCamera { get { if (mCam == null) mCam = GetComponent<Camera>(); return mCam; } }
- /// <summary>
- /// Tween's current value.
- /// </summary>
- public float value { get { return cachedCamera.fieldOfView; } set { cachedCamera.fieldOfView = value; } }
- /// <summary>
- /// Tween the value.
- /// </summary>
- protected override void OnUpdate (float factor, bool isFinished) { value = from * (1f - factor) + to * factor; }
- /// <summary>
- /// Start the tweening operation.
- /// </summary>
- static public TweenFOV Begin (GameObject go, float duration, float to)
- {
- TweenFOV comp = Tweener.Begin<TweenFOV>(go, duration);
- comp.from = comp.value;
- comp.to = to;
- if (duration <= 0f)
- {
- comp.Sample(1f, true);
- comp.enabled = false;
- }
- return comp;
- }
- [ContextMenu("Set 'From' to current value")]
- public override void SetStartToCurrentValue () { from = value; }
- [ContextMenu("Set 'To' to current value")]
- public override void SetEndToCurrentValue () { to = value; }
- [ContextMenu("Assume value of 'From'")]
- void SetCurrentValueToStart () { value = from; }
- [ContextMenu("Assume value of 'To'")]
- void SetCurrentValueToEnd () { value = to; }
- }
|