UIButtonRotation.cs 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. using System;
  2. using UnityEngine;
  3. [AddComponentMenu("NGUI/Interaction/Button Rotation")]
  4. public class UIButtonRotation : MonoBehaviour
  5. {
  6. private void Start()
  7. {
  8. if (!this.mStarted)
  9. {
  10. this.mStarted = true;
  11. if (this.tweenTarget == null)
  12. {
  13. this.tweenTarget = base.transform;
  14. }
  15. this.mRot = this.tweenTarget.localRotation;
  16. }
  17. }
  18. private void OnEnable()
  19. {
  20. if (this.mStarted)
  21. {
  22. this.OnHover(UICamera.IsHighlighted(base.gameObject));
  23. }
  24. }
  25. private void OnDisable()
  26. {
  27. if (this.mStarted && this.tweenTarget != null)
  28. {
  29. TweenRotation component = this.tweenTarget.GetComponent<TweenRotation>();
  30. if (component != null)
  31. {
  32. component.value = this.mRot;
  33. component.enabled = false;
  34. }
  35. }
  36. }
  37. private void OnPress(bool isPressed)
  38. {
  39. if (base.enabled)
  40. {
  41. if (!this.mStarted)
  42. {
  43. this.Start();
  44. }
  45. TweenRotation.Begin(this.tweenTarget.gameObject, this.duration, (!isPressed) ? ((!UICamera.IsHighlighted(base.gameObject)) ? this.mRot : (this.mRot * Quaternion.Euler(this.hover))) : (this.mRot * Quaternion.Euler(this.pressed))).method = UITweener.Method.EaseInOut;
  46. }
  47. }
  48. private void OnHover(bool isOver)
  49. {
  50. if (base.enabled)
  51. {
  52. if (!this.mStarted)
  53. {
  54. this.Start();
  55. }
  56. TweenRotation.Begin(this.tweenTarget.gameObject, this.duration, (!isOver) ? this.mRot : (this.mRot * Quaternion.Euler(this.hover))).method = UITweener.Method.EaseInOut;
  57. }
  58. }
  59. private void OnSelect(bool isSelected)
  60. {
  61. if (base.enabled && (!isSelected || UICamera.currentScheme == UICamera.ControlScheme.Controller))
  62. {
  63. this.OnHover(isSelected);
  64. }
  65. }
  66. public Transform tweenTarget;
  67. public Vector3 hover = Vector3.zero;
  68. public Vector3 pressed = Vector3.zero;
  69. public float duration = 0.2f;
  70. private Quaternion mRot;
  71. private bool mStarted;
  72. }