UICenterOnClick.cs 975 B

123456789101112131415161718192021222324252627282930313233
  1. using System;
  2. using UnityEngine;
  3. [AddComponentMenu("NGUI/Interaction/Center Scroll View on Click")]
  4. public class UICenterOnClick : MonoBehaviour
  5. {
  6. private void OnClick()
  7. {
  8. UICenterOnChild uicenterOnChild = NGUITools.FindInParents<UICenterOnChild>(base.gameObject);
  9. UIPanel uipanel = NGUITools.FindInParents<UIPanel>(base.gameObject);
  10. if (uicenterOnChild != null)
  11. {
  12. if (uicenterOnChild.enabled)
  13. {
  14. uicenterOnChild.CenterOn(base.transform);
  15. }
  16. }
  17. else if (uipanel != null && uipanel.clipping != UIDrawCall.Clipping.None)
  18. {
  19. UIScrollView component = uipanel.GetComponent<UIScrollView>();
  20. Vector3 pos = -uipanel.cachedTransform.InverseTransformPoint(base.transform.position);
  21. if (!component.canMoveHorizontally)
  22. {
  23. pos.x = uipanel.cachedTransform.localPosition.x;
  24. }
  25. if (!component.canMoveVertically)
  26. {
  27. pos.y = uipanel.cachedTransform.localPosition.y;
  28. }
  29. SpringPanel.Begin(uipanel.cachedGameObject, pos, 6f);
  30. }
  31. }
  32. }