GetScrollRectAlginPointTool.cs 1.2 KB

123456789101112131415161718192021222324252627282930313233
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. using UnityEditor;
  6. public class GetScrollRectAlginPointTool
  7. {
  8. [MenuItem("RO_Tool/UI/提取ScrollRect的对齐点", true)]
  9. private static bool CanUseTool()
  10. {
  11. GameObject activeGameObject = Selection.activeGameObject;
  12. if (!activeGameObject) return false;
  13. ScrollRect scrollRect = activeGameObject.GetComponent<ScrollRect>();
  14. if (!scrollRect) return false;
  15. return true;
  16. }
  17. [MenuItem("RO_Tool/UI/提取ScrollRect的对齐点")]
  18. private static void UseTool()
  19. {
  20. GameObject activeGameObject = Selection.activeGameObject;
  21. ScrollRect scrollRect = activeGameObject.GetComponent<ScrollRect>();
  22. Vector2 normalizedPosition = scrollRect.normalizedPosition;
  23. Vector2 viewPortSize = scrollRect.viewport.rect.size;
  24. Vector2 contentSize = scrollRect.content.rect.size;
  25. Vector2 vaildSize = contentSize - viewPortSize;
  26. Vector2 point = normalizedPosition * vaildSize;
  27. point = point - vaildSize * 0.5f;
  28. GUIUtility.systemCopyBuffer = point.x + ";" + point.y;
  29. Debug.LogError(point.x + ";" + point.y);
  30. }
  31. }