using System; using UnityEngine; [AddComponentMenu("NGUI/Interaction/Button Offset")] public class UIButtonOffset : MonoBehaviour { private void Start() { if (!this.mStarted) { this.mStarted = true; if (this.tweenTarget == null) { this.tweenTarget = base.transform; } this.mPos = this.tweenTarget.localPosition; } } private void OnEnable() { if (this.mStarted) { this.OnHover(UICamera.IsHighlighted(base.gameObject)); } } private void OnDisable() { if (this.mStarted && this.tweenTarget != null) { TweenPosition component = this.tweenTarget.GetComponent(); if (component != null) { component.value = this.mPos; component.enabled = false; } } } private void OnPress(bool isPressed) { if (base.enabled) { if (!this.mStarted) { this.Start(); } TweenPosition.Begin(this.tweenTarget.gameObject, this.duration, (!isPressed) ? ((!UICamera.IsHighlighted(base.gameObject)) ? this.mPos : (this.mPos + this.hover)) : (this.mPos + this.pressed)).method = UITweener.Method.EaseInOut; } } private void OnHover(bool isOver) { if (base.enabled) { if (!this.mStarted) { this.Start(); } TweenPosition.Begin(this.tweenTarget.gameObject, this.duration, (!isOver) ? this.mPos : (this.mPos + 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 = new Vector3(2f, -2f); public float duration = 0.2f; private Vector3 mPos; private bool mStarted; }