33 lines
1.2 KiB
C#
33 lines
1.2 KiB
C#
|
using UnityEngine;
|
|||
|
|
|||
|
namespace Terkoiz.MapZoneHighlighter
|
|||
|
{
|
|||
|
public static class UIDrawingUtil
|
|||
|
{
|
|||
|
public static void DrawString(Vector2 position, string label, Color color, bool centered = true)
|
|||
|
{
|
|||
|
GUI.color = color;
|
|||
|
DrawString(position, label, centered);
|
|||
|
}
|
|||
|
|
|||
|
public static void DrawString(Vector2 position, string label, bool centered = true)
|
|||
|
{
|
|||
|
var content = new GUIContent(label);
|
|||
|
var size = new GUIStyle(GUI.skin.label).CalcSize(content);
|
|||
|
var upperLeft = centered ? position - size / 2f : position;
|
|||
|
GUI.Label(new Rect(upperLeft, size), content);
|
|||
|
}
|
|||
|
|
|||
|
public static Vector3 WorldPointToScreenPoint(Vector3 worldPoint)
|
|||
|
{
|
|||
|
Vector3 screenPoint = Camera.main.WorldToScreenPoint(worldPoint);
|
|||
|
screenPoint.y = Screen.height - screenPoint.y;
|
|||
|
return screenPoint;
|
|||
|
}
|
|||
|
|
|||
|
public static bool IsScreenPointVisible(Vector3 screenPoint)
|
|||
|
{
|
|||
|
return screenPoint.z > 0.01f && screenPoint.x > -5f && screenPoint.y > -5f && screenPoint.x < Screen.width && screenPoint.y < Screen.height;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|