1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374 |
- using UnityEngine;
- /// <summary>
- /// Tween the camera's orthographic size.
- /// </summary>
- [RequireComponent(typeof(Camera))]
- public class TweenOrthoSize : Tweener
- {
- public float from = 1f;
- public float to = 1f;
- Camera mCam;
- /// <summary>
- /// Camera that's being tweened.
- /// </summary>
- public Camera cachedCamera {
- get {
- if (mCam == null)
- mCam = GetComponent<Camera>();
- return mCam;
- }
- }
- /// <summary>
- /// Tween's current value.
- /// </summary>
- public float value {
- get {
- return cachedCamera.orthographicSize;
- }
- set {
- cachedCamera.orthographicSize = 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 TweenOrthoSize Begin(GameObject go, float duration, float to)
- {
- TweenOrthoSize comp = Tweener.Begin<TweenOrthoSize>(go, duration);
- comp.from = comp.value;
- comp.to = to;
- if (duration <= 0f)
- {
- comp.Sample(1f, true);
- comp.enabled = false;
- }
- return comp;
- }
- public override void SetStartToCurrentValue()
- {
- from = value;
- }
- public override void SetEndToCurrentValue()
- {
- to = value;
- }
- }
|