| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778 |
- using UnityEngine;
- /// <summary>
- /// Helper script to visualize the map area boundaries in the Unity editor
- /// Attach this to any GameObject in the scene to see the map area outlined
- /// </summary>
- public class MapAreaVisualizer : MonoBehaviour
- {
- [Header("Map Area Settings")]
- [Tooltip("Width of the left UI panel (Map Legend)")]
- public float leftUIWidth = 150f;
- [Tooltip("Width of the right UI panel (Your Team)")]
- public float rightUIWidth = 300f;
- [Tooltip("Height of top UI panels")]
- public float topUIHeight = 0f;
- [Tooltip("Height of bottom UI panels")]
- public float bottomUIHeight = 0f;
- [Header("Visualization")]
- public bool showDebugInfo = false;
- public Color mapAreaColor = Color.green;
- public Color uiAreaColor = Color.red;
- void OnGUI()
- {
- if (!showDebugInfo) return;
- // Calculate map area bounds
- float mapLeft = leftUIWidth;
- float mapRight = Screen.width - rightUIWidth;
- float mapTop = Screen.height - topUIHeight;
- float mapBottom = bottomUIHeight;
- // Draw map area outline
- GUI.color = mapAreaColor;
- DrawRect(new Rect(mapLeft, mapBottom, mapRight - mapLeft, mapTop - mapBottom), 2);
- // Draw UI areas
- GUI.color = uiAreaColor;
- // Left UI area
- DrawRect(new Rect(0, 0, leftUIWidth, Screen.height), 2);
- // Right UI area
- DrawRect(new Rect(mapRight, 0, rightUIWidth, Screen.height), 2);
- // Reset color
- GUI.color = Color.white;
- // Show mouse position and status
- Vector2 mousePos = Input.mousePosition;
- mousePos.y = Screen.height - mousePos.y; // Flip Y for GUI coordinates
- bool inMapArea = mousePos.x >= mapLeft &&
- mousePos.x <= mapRight &&
- mousePos.y >= mapBottom &&
- mousePos.y <= mapTop;
- string status = inMapArea ? "IN MAP AREA" : "IN UI AREA";
- GUI.color = inMapArea ? Color.green : Color.red;
- GUI.Label(new Rect(10, 10, 200, 20), $"Mouse: {status}");
- GUI.Label(new Rect(10, 30, 200, 20), $"Position: {Input.mousePosition.x:F0}, {Input.mousePosition.y:F0}");
- GUI.color = Color.white;
- }
- void DrawRect(Rect rect, float thickness)
- {
- // Top
- GUI.DrawTexture(new Rect(rect.x, rect.y, rect.width, thickness), Texture2D.whiteTexture);
- // Bottom
- GUI.DrawTexture(new Rect(rect.x, rect.y + rect.height - thickness, rect.width, thickness), Texture2D.whiteTexture);
- // Left
- GUI.DrawTexture(new Rect(rect.x, rect.y, thickness, rect.height), Texture2D.whiteTexture);
- // Right
- GUI.DrawTexture(new Rect(rect.x + rect.width - thickness, rect.y, thickness, rect.height), Texture2D.whiteTexture);
- }
- }
|