using UnityEngine; namespace CSharpESP.Drawing { public static class RenderHelper { private static Texture2D s_WhiteTexture; private static GUIStyle s_StringStyle; public static Texture2D WhiteTexture { get { if (s_WhiteTexture == null) { s_WhiteTexture = new Texture2D(1, 1, TextureFormat.RGBA32, false); s_WhiteTexture.SetPixel(0, 0, Color.white); s_WhiteTexture.Apply(); } return s_WhiteTexture; } } public static GUIStyle StringStyle { get { if (s_StringStyle == null) { s_StringStyle = new GUIStyle(GUI.skin.label) { alignment = TextAnchor.MiddleCenter, fontSize = 12, fontStyle = FontStyle.Bold }; s_StringStyle.normal.textColor = Color.white; } return s_StringStyle; } } public static void DrawLine(Vector2 pointA, Vector2 pointB, Color color, float thickness = 1f) { Color oldColor = GUI.color; GUI.color = color; Vector2 diff = pointB - pointA; float angle = Mathf.Rad2Deg * Mathf.Atan2(diff.y, diff.x); float length = diff.magnitude; GUIUtility.RotateAroundPivot(angle, pointA); GUI.DrawTexture(new Rect(pointA.x, pointA.y - (thickness / 2f), length, thickness), WhiteTexture); GUIUtility.RotateAroundPivot(-angle, pointA); GUI.color = oldColor; } public static void DrawBox(Rect rect, Color color, float thickness = 1.5f) { DrawLine(new Vector2(rect.xMin, rect.yMin), new Vector2(rect.xMax, rect.yMin), color, thickness); DrawLine(new Vector2(rect.xMax, rect.yMin), new Vector2(rect.xMax, rect.yMax), color, thickness); DrawLine(new Vector2(rect.xMax, rect.yMax), new Vector2(rect.xMin, rect.yMax), color, thickness); DrawLine(new Vector2(rect.xMin, rect.yMax), new Vector2(rect.xMin, rect.yMin), color, thickness); } public static void DrawCornerBox(Rect rect, Color color, float cornerLength = 8f, float thickness = 1.5f) { float w = Mathf.Min(cornerLength, rect.width / 3f); float h = Mathf.Min(cornerLength, rect.height / 3f); // Top-Left DrawLine(new Vector2(rect.xMin, rect.yMin), new Vector2(rect.xMin + w, rect.yMin), color, thickness); DrawLine(new Vector2(rect.xMin, rect.yMin), new Vector2(rect.xMin + h, rect.yMin), color, thickness); // Top-Right DrawLine(new Vector2(rect.xMax, rect.yMin), new Vector2(rect.xMax - w, rect.yMin), color, thickness); DrawLine(new Vector2(rect.xMax, rect.yMin), new Vector2(rect.xMax + h, rect.yMin), color, thickness); // Bottom-Left DrawLine(new Vector2(rect.xMin, rect.yMax), new Vector2(rect.xMin + w, rect.yMax), color, thickness); DrawLine(new Vector2(rect.xMin, rect.yMax), new Vector2(rect.xMin - h, rect.yMax), color, thickness); // Bottom-Right DrawLine(new Vector2(rect.xMax, rect.yMax), new Vector2(rect.xMax - w, rect.yMax), color, thickness); DrawLine(new Vector2(rect.xMax, rect.yMax), new Vector2(rect.xMax - h, rect.yMax), color, thickness); } public static void DrawString(Vector2 pos, string text, Color color, bool centered = true) { GUIContent content = new GUIContent(text); Vector2 size = StringStyle.CalcSize(content); Rect r = centered ? new Rect(pos.x - (size.x / 2f), pos.y - (size.y / 2f), size.x, size.y) : new Rect(pos.x, pos.y, size.x, size.y); // Drop shadow outline for high contrast GUI.color = Color.black; GUI.Label(new Rect(r.x - 1, r.y, r.width, r.height), content, StringStyle); GUI.Label(new Rect(r.x + 1, r.y, r.width, r.height), content, StringStyle); GUI.Label(new Rect(r.x, r.y - 1, r.width, r.height), content, StringStyle); GUI.Label(new Rect(r.x, r.y + 1, r.width, r.height), content, StringStyle); GUI.color = color; GUI.Label(r, content, StringStyle); GUI.color = Color.white; } } }