using System; using UnityEngine; [AddComponentMenu("NGUI/Tween/Tween Rotation")] public class TweenRotation : UITweener { public Transform cachedTransform { get { if (this.mTrans == null) { this.mTrans = base.transform; } return this.mTrans; } } [Obsolete("Use 'value' instead")] public Quaternion rotation { get { return this.value; } set { this.value = value; } } public Quaternion value { get { return this.cachedTransform.localRotation; } set { this.cachedTransform.localRotation = value; } } protected override void OnUpdate(float factor, bool isFinished) { this.value = Quaternion.Euler(new Vector3(Mathf.Lerp(this.from.x, this.to.x, factor), Mathf.Lerp(this.from.y, this.to.y, factor), Mathf.Lerp(this.from.z, this.to.z, factor))); } public static TweenRotation Begin(GameObject go, float duration, Quaternion rot) { TweenRotation tweenRotation = UITweener.Begin(go, duration); tweenRotation.from = tweenRotation.value.eulerAngles; tweenRotation.to = rot.eulerAngles; if (duration <= 0f) { tweenRotation.Sample(1f, true); tweenRotation.enabled = false; } return tweenRotation; } [ContextMenu("Set 'From' to current value")] public override void SetStartToCurrentValue() { this.from = this.value.eulerAngles; } [ContextMenu("Set 'To' to current value")] public override void SetEndToCurrentValue() { this.to = this.value.eulerAngles; } [ContextMenu("Assume value of 'From'")] private void SetCurrentValueToStart() { this.value = Quaternion.Euler(this.from); } [ContextMenu("Assume value of 'To'")] private void SetCurrentValueToEnd() { this.value = Quaternion.Euler(this.to); } public Vector3 from; public Vector3 to; private Transform mTrans; }