1234567891011121314151617181920212223242526272829303132333435363738 |
- using System;
- using UnityEngine;
- [AddComponentMenu("NGUI/Interaction/Center Scroll View on Click2")]
- public class UICenterOnClick2 : MonoBehaviour
- {
- private void OnSelect(bool isSelected)
- {
- if (isSelected)
- {
- this.OnClick();
- }
- }
- private void OnClick()
- {
- UICenterOnChild uicenterOnChild = NGUITools.FindInParents<UICenterOnChild>(base.gameObject);
- UIPanel uipanel = NGUITools.FindInParents<UIPanel>(base.gameObject);
- if (uicenterOnChild != null)
- {
- 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);
- }
- }
- }
|