Unity-DebugX/Runtime/Gizmos/Text/TextDrawHandlerExtensions.cs
2025-03-05 18:50:22 +08:00

34 lines
1.2 KiB
C#

using System.Runtime.CompilerServices;
using UnityEngine;
namespace DCFApixels
{
using DrawHandler = DebugX.DrawHandler;
using IN = MethodImplAttribute;
public static class TextDrawHandlerExtensions
{
private const MethodImplOptions LINE = DebugX.LINE;
#if DEBUG
private static bool _singleWarningToggle = true;
#endif
[IN(LINE)]
public static DrawHandler Text(this DrawHandler h, Vector3 position, object text) => h.Text(position, text, DebugXTextSettings.Default);
[IN(LINE)]
public static DrawHandler Text(this DrawHandler h, Vector3 position, object text, DebugXTextSettings settings)
{
if(settings.FontSize <= float.Epsilon)
{
#if DEBUG
if (_singleWarningToggle)
{
Debug.LogWarning("Text rendering requires FontSize > 0, otherwise the text will be invisible. To avoid invalid parameters, use DebugXTextSettings.Default instead of manual instantiation.");
_singleWarningToggle = false;
}
#endif
settings = settings.SetSize(DebugXTextSettings.DEFAULT_FONT_SIZE);
}
return h.Gizmo(new TextGizmo(position, text, settings));
}
}
}