UICenterOnClick2.cs 1.0 KB

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