using UnityEngine; /// /// Tween the object's rotation. /// public class TweenEulerAngles : Tweener { public Vector3 from; public Vector3 to; Transform mTrans; public Transform cachedTransform { get { if (mTrans == null) mTrans = transform; return mTrans; } } /// /// Tween's current value. /// public Vector3 value { get { return cachedTransform.localEulerAngles; } set { cachedTransform.localEulerAngles = value; } } /// /// Tween the value. /// protected override void OnUpdate(float factor, bool isFinished) { value = Vector3.Lerp(from, to, factor); } /// /// Start the tweening operation. /// static public TweenEulerAngles Begin(GameObject go, float duration, Vector3 to) { TweenEulerAngles comp = Tweener.Begin(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; } }