TweenRotation.cs 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. using System;
  2. using UnityEngine;
  3. [AddComponentMenu("NGUI/Tween/Tween Rotation")]
  4. public class TweenRotation : UITweener
  5. {
  6. public Transform cachedTransform
  7. {
  8. get
  9. {
  10. if (this.mTrans == null)
  11. {
  12. this.mTrans = base.transform;
  13. }
  14. return this.mTrans;
  15. }
  16. }
  17. [Obsolete("Use 'value' instead")]
  18. public Quaternion rotation
  19. {
  20. get
  21. {
  22. return this.value;
  23. }
  24. set
  25. {
  26. this.value = value;
  27. }
  28. }
  29. public Quaternion value
  30. {
  31. get
  32. {
  33. return this.cachedTransform.localRotation;
  34. }
  35. set
  36. {
  37. this.cachedTransform.localRotation = value;
  38. }
  39. }
  40. protected override void OnUpdate(float factor, bool isFinished)
  41. {
  42. 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)));
  43. }
  44. public static TweenRotation Begin(GameObject go, float duration, Quaternion rot)
  45. {
  46. TweenRotation tweenRotation = UITweener.Begin<TweenRotation>(go, duration);
  47. tweenRotation.from = tweenRotation.value.eulerAngles;
  48. tweenRotation.to = rot.eulerAngles;
  49. if (duration <= 0f)
  50. {
  51. tweenRotation.Sample(1f, true);
  52. tweenRotation.enabled = false;
  53. }
  54. return tweenRotation;
  55. }
  56. [ContextMenu("Set 'From' to current value")]
  57. public override void SetStartToCurrentValue()
  58. {
  59. this.from = this.value.eulerAngles;
  60. }
  61. [ContextMenu("Set 'To' to current value")]
  62. public override void SetEndToCurrentValue()
  63. {
  64. this.to = this.value.eulerAngles;
  65. }
  66. [ContextMenu("Assume value of 'From'")]
  67. private void SetCurrentValueToStart()
  68. {
  69. this.value = Quaternion.Euler(this.from);
  70. }
  71. [ContextMenu("Assume value of 'To'")]
  72. private void SetCurrentValueToEnd()
  73. {
  74. this.value = Quaternion.Euler(this.to);
  75. }
  76. public Vector3 from;
  77. public Vector3 to;
  78. private Transform mTrans;
  79. }