MapAreaVisualizer.cs 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. using UnityEngine;
  2. /// <summary>
  3. /// Helper script to visualize the map area boundaries in the Unity editor
  4. /// Attach this to any GameObject in the scene to see the map area outlined
  5. /// </summary>
  6. public class MapAreaVisualizer : MonoBehaviour
  7. {
  8. [Header("Map Area Settings")]
  9. [Tooltip("Width of the left UI panel (Map Legend)")]
  10. public float leftUIWidth = 150f;
  11. [Tooltip("Width of the right UI panel (Your Team)")]
  12. public float rightUIWidth = 300f;
  13. [Tooltip("Height of top UI panels")]
  14. public float topUIHeight = 0f;
  15. [Tooltip("Height of bottom UI panels")]
  16. public float bottomUIHeight = 0f;
  17. [Header("Visualization")]
  18. public bool showDebugInfo = false;
  19. public Color mapAreaColor = Color.green;
  20. public Color uiAreaColor = Color.red;
  21. void OnGUI()
  22. {
  23. if (!showDebugInfo) return;
  24. // Calculate map area bounds
  25. float mapLeft = leftUIWidth;
  26. float mapRight = Screen.width - rightUIWidth;
  27. float mapTop = Screen.height - topUIHeight;
  28. float mapBottom = bottomUIHeight;
  29. // Draw map area outline
  30. GUI.color = mapAreaColor;
  31. DrawRect(new Rect(mapLeft, mapBottom, mapRight - mapLeft, mapTop - mapBottom), 2);
  32. // Draw UI areas
  33. GUI.color = uiAreaColor;
  34. // Left UI area
  35. DrawRect(new Rect(0, 0, leftUIWidth, Screen.height), 2);
  36. // Right UI area
  37. DrawRect(new Rect(mapRight, 0, rightUIWidth, Screen.height), 2);
  38. // Reset color
  39. GUI.color = Color.white;
  40. // Show mouse position and status
  41. Vector2 mousePos = Input.mousePosition;
  42. mousePos.y = Screen.height - mousePos.y; // Flip Y for GUI coordinates
  43. bool inMapArea = mousePos.x >= mapLeft &&
  44. mousePos.x <= mapRight &&
  45. mousePos.y >= mapBottom &&
  46. mousePos.y <= mapTop;
  47. string status = inMapArea ? "IN MAP AREA" : "IN UI AREA";
  48. GUI.color = inMapArea ? Color.green : Color.red;
  49. GUI.Label(new Rect(10, 10, 200, 20), $"Mouse: {status}");
  50. GUI.Label(new Rect(10, 30, 200, 20), $"Position: {Input.mousePosition.x:F0}, {Input.mousePosition.y:F0}");
  51. GUI.color = Color.white;
  52. }
  53. void DrawRect(Rect rect, float thickness)
  54. {
  55. // Top
  56. GUI.DrawTexture(new Rect(rect.x, rect.y, rect.width, thickness), Texture2D.whiteTexture);
  57. // Bottom
  58. GUI.DrawTexture(new Rect(rect.x, rect.y + rect.height - thickness, rect.width, thickness), Texture2D.whiteTexture);
  59. // Left
  60. GUI.DrawTexture(new Rect(rect.x, rect.y, thickness, rect.height), Texture2D.whiteTexture);
  61. // Right
  62. GUI.DrawTexture(new Rect(rect.x + rect.width - thickness, rect.y, thickness, rect.height), Texture2D.whiteTexture);
  63. }
  64. }