using UnityEngine;
namespace DCFApixels
{
///
/// All additional settings for text rendering are stored here.
///
public readonly struct DebugXTextSettings
{
public const TextAnchor DEFAULT_TEXT_ANCHOR = TextAnchor.MiddleLeft;
public const int DEFAULT_FONT_SIZE = 16;
public const float SCREEN_SPACE_SCALE_FACTOR = 0f;
public const float WORLD_SPACE_SCALE_FACTOR = 1f;
public static readonly DebugXTextSettings Default = new DebugXTextSettings(DEFAULT_FONT_SIZE, DEFAULT_TEXT_ANCHOR, default, 0);
public static readonly DebugXTextSettings WorldSpaceScale = Default.SetWorldSpaceScaleFactor();
///
/// Font size. Default is .
///
public readonly int FontSize;
///
/// Text alignment. Default is .
///
public readonly TextAnchor TextAnchor;
public readonly Color BackgroundColor;
public readonly float WorldSpaceScaleFactor;
// ReSharper disable once UnusedMember.Global
public bool IsHasBackground => BackgroundColor.a > 0;
public DebugXTextSettings(int fontSize, TextAnchor textAnchor, Color backgroundColor, float worldSpaceScaleFactor)
{
FontSize = fontSize;
TextAnchor = textAnchor;
BackgroundColor = backgroundColor;
WorldSpaceScaleFactor = worldSpaceScaleFactor;
}
///
/// Set font size. Default is .
///
public DebugXTextSettings SetSize(int fontSize)
{
return new DebugXTextSettings(fontSize, TextAnchor, BackgroundColor, WorldSpaceScaleFactor);
}
///
/// Sets text alignment. Default is .
///
public DebugXTextSettings SetAnchor(TextAnchor textAnchor)
{
return new DebugXTextSettings(FontSize, textAnchor, BackgroundColor, WorldSpaceScaleFactor);
}
///
/// Sets background image color behind text. Ignored if transparent.
///
public DebugXTextSettings SetBackground(Color backgroundColor)
{
return new DebugXTextSettings(FontSize, TextAnchor, backgroundColor, WorldSpaceScaleFactor);
}
///
/// Synchronizes the text scale in screen space. The text will remain the same size on the screen.
///
// ReSharper disable once UnusedMember.Global
public DebugXTextSettings SetScreenSpaceScaleFactor()
{
return SetCustomSpaceScaleFactor(SCREEN_SPACE_SCALE_FACTOR);
}
///
/// Synchronizes the text scale in world space. The text will remain the same size on the scene.
///
public DebugXTextSettings SetWorldSpaceScaleFactor()
{
return SetCustomSpaceScaleFactor(WORLD_SPACE_SCALE_FACTOR);
}
///
/// Allows you to control the text scale depending on the camera zoom.
///
///
///
/// 0 - screen space
/// 1 - world space
/// Values in between [0.00 - 1.00] blend these spaces together.
///
public DebugXTextSettings SetCustomSpaceScaleFactor(float factor)
{
return new DebugXTextSettings(FontSize, TextAnchor, BackgroundColor, factor);
}
}
}