using UnityEngine; [AddComponentMenu("NGUI/Interaction/Center Scroll View on Click")] public class UICenterOnClick : MonoBehaviour { [SerializeField] private Transform _otherCenteringTarget; private void OnClick() { UICenterOnChild uICenterOnChild = NGUITools.FindInParents(base.gameObject); UIPanel uIPanel = NGUITools.FindInParents(base.gameObject); if (uICenterOnChild != null) { if (uICenterOnChild.enabled) { if (_otherCenteringTarget != null) { uICenterOnChild.CenterOn(_otherCenteringTarget); } else { uICenterOnChild.CenterOn(base.transform); } } } else if (uIPanel != null && uIPanel.clipping != UIDrawCall.Clipping.None) { UIScrollView component = uIPanel.GetComponent(); 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); } } }