123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384 |
- using System;
- using UnityEngine;
- [AddComponentMenu("NGUI/Interaction/Button Rotation")]
- public class UIButtonRotation : MonoBehaviour
- {
- private void Start()
- {
- if (!this.mStarted)
- {
- this.mStarted = true;
- if (this.tweenTarget == null)
- {
- this.tweenTarget = base.transform;
- }
- this.mRot = this.tweenTarget.localRotation;
- }
- }
- private void OnEnable()
- {
- if (this.mStarted)
- {
- this.OnHover(UICamera.IsHighlighted(base.gameObject));
- }
- }
- private void OnDisable()
- {
- if (this.mStarted && this.tweenTarget != null)
- {
- TweenRotation component = this.tweenTarget.GetComponent<TweenRotation>();
- if (component != null)
- {
- component.value = this.mRot;
- component.enabled = false;
- }
- }
- }
- private void OnPress(bool isPressed)
- {
- if (base.enabled)
- {
- if (!this.mStarted)
- {
- this.Start();
- }
- 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;
- }
- }
- private void OnHover(bool isOver)
- {
- if (base.enabled)
- {
- if (!this.mStarted)
- {
- this.Start();
- }
- TweenRotation.Begin(this.tweenTarget.gameObject, this.duration, (!isOver) ? this.mRot : (this.mRot * Quaternion.Euler(this.hover))).method = UITweener.Method.EaseInOut;
- }
- }
- private void OnSelect(bool isSelected)
- {
- if (base.enabled && (!isSelected || UICamera.currentScheme == UICamera.ControlScheme.Controller))
- {
- this.OnHover(isSelected);
- }
- }
- public Transform tweenTarget;
- public Vector3 hover = Vector3.zero;
- public Vector3 pressed = Vector3.zero;
- public float duration = 0.2f;
- private Quaternion mRot;
- private bool mStarted;
- }
|