123456789101112131415161718192021222324252627282930313233 |
- using System;
- using UnityEngine;
- [AddComponentMenu("NGUI/Interaction/Center Scroll View on Click")]
- public class UICenterOnClick : MonoBehaviour
- {
- private void OnClick()
- {
- UICenterOnChild uicenterOnChild = NGUITools.FindInParents<UICenterOnChild>(base.gameObject);
- UIPanel uipanel = NGUITools.FindInParents<UIPanel>(base.gameObject);
- if (uicenterOnChild != null)
- {
- if (uicenterOnChild.enabled)
- {
- uicenterOnChild.CenterOn(base.transform);
- }
- }
- else if (uipanel != null && uipanel.clipping != UIDrawCall.Clipping.None)
- {
- UIScrollView component = uipanel.GetComponent<UIScrollView>();
- Vector3 pos = -uipanel.cachedTransform.InverseTransformPoint(base.transform.position);
- if (!component.canMoveHorizontally)
- {
- pos.x = uipanel.cachedTransform.localPosition.x;
- }
- if (!component.canMoveVertically)
- {
- pos.y = uipanel.cachedTransform.localPosition.y;
- }
- SpringPanel.Begin(uipanel.cachedGameObject, pos, 6f);
- }
- }
- }
|