12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182 |
- using UnityEngine;
- /// <summary>
- /// Tween the object's rotation.
- /// </summary>
- public class TweenRotation : Tweener
- {
- public Vector3 from;
- public Vector3 to;
- Transform mTrans;
- public Transform cachedTransform {
- get {
- if (mTrans == null)
- mTrans = transform;
- return mTrans;
- }
- }
- /// <summary>
- /// Tween's current value.
- /// </summary>
- public Quaternion value {
- get {
- return cachedTransform.localRotation;
- }
- set {
- cachedTransform.localRotation = value;
- }
- }
- /// <summary>
- /// Tween the value.
- /// </summary>
- protected override void OnUpdate(float factor, bool isFinished)
- {
- value = Quaternion.Slerp(Quaternion.Euler(from), Quaternion.Euler(to), factor);
- }
- /// <summary>
- /// Start the tweening operation.
- /// </summary>
- static public TweenRotation Begin(GameObject go, float duration, Quaternion rot)
- {
- TweenRotation comp = Tweener.Begin<TweenRotation>(go, duration);
- comp.from = comp.value.eulerAngles;
- comp.to = rot.eulerAngles;
- if (duration <= 0f)
- {
- comp.Sample(1f, true);
- comp.enabled = false;
- }
- return comp;
- }
- [ContextMenu("Set 'From' to current value")]
- public override void SetStartToCurrentValue()
- {
- from = value.eulerAngles;
- }
- [ContextMenu("Set 'To' to current value")]
- public override void SetEndToCurrentValue()
- {
- to = value.eulerAngles;
- }
- [ContextMenu("Assume value of 'From'")]
- void SetCurrentValueToStart()
- {
- value = Quaternion.Euler(from);
- }
- [ContextMenu("Assume value of 'To'")]
- void SetCurrentValueToEnd()
- {
- value = Quaternion.Euler(to);
- }
- }
|