Class HudUi
- Namespace
- TDMaker.Unity.Hud
- Assembly
- TDMaker.Unity.dll
Small helpers that build themed uGUI elements from code.
public static class HudUi
- Inheritance
-
HudUi
- Inherited Members
Fields
UiLayer
The built-in UI layer index.
public const int UiLayer = 5
Field Value
Methods
Align(TextAnchor)
Converts a uGUI anchor to the matching TextMesh Pro alignment.
public static TextAlignmentOptions Align(TextAnchor anchor)
Parameters
anchorTextAnchor
Returns
- TextAlignmentOptions
ApplyFont(TMP_Text, HudTheme)
Assigns the theme's font and material (shadowed when the theme asks for it) to a label.
public static void ApplyFont(TMP_Text label, HudTheme theme)
Parameters
labelTMP_TextthemeHudTheme
Bar(string, Transform, HudTheme, Color, out Image)
Creates a horizontal bar (background + fill); returns the fill rect whose anchorMax.x is the fraction.
public static RectTransform Bar(string name, Transform parent, HudTheme theme, Color fill, out Image fillImage)
Parameters
Returns
- RectTransform
FitUniform(IList<TMP_Text>, float, float)
Gives a group of labels (a row of toggles, a set of cards) one shared font size: the largest size from maxSize down to minSize at which every label fits its rectangle (wrapping labels may break between words but never inside one). Mixed sizes inside one row look accidental; one size reads as a set. Labels that still do not fit at minSize ellipsize. Call after the labels' rectangles are laid out; turns their auto-sizing off.
public static float FitUniform(IList<TMP_Text> labels, float maxSize, float minSize)
Parameters
Returns
Image(string, Transform, Sprite, Color, bool)
Creates an image.
public static Image Image(string name, Transform parent, Sprite sprite, Color color, bool raycast = false)
Parameters
Returns
- Image
Label(string, Transform, HudTheme, float, Color, TextAnchor, string)
Creates a TextMesh Pro label with the theme's font (and drop shadow when textShadow is on). Labels do not wrap and may overflow their rect; set TMPro.TMP_Text.textWrappingMode for wrapping text.
public static TextMeshProUGUI Label(string name, Transform parent, HudTheme theme, float size, Color color, TextAnchor anchor, string text = "")
Parameters
Returns
- TextMeshProUGUI
Place(RectTransform, Vector2, Vector2, Vector2, Vector2)
Anchors at a single point with a pivot, position and size.
public static RectTransform Place(RectTransform rt, Vector2 anchor, Vector2 pivot, Vector2 position, Vector2 size)
Parameters
rtRectTransformanchorVector2pivotVector2positionVector2sizeVector2
Returns
- RectTransform
Radial(string, Transform, Sprite, Color)
Creates a radial fill image (cooldowns, countdown rings).
public static Image Radial(string name, Transform parent, Sprite sprite, Color color)
Parameters
namestringparentTransformspriteSpritecolorColor
Returns
- Image
Rect(string, Transform)
Creates a child RectTransform.
public static RectTransform Rect(string name, Transform parent)
Parameters
namestringparentTransform
Returns
- RectTransform
Rule(string, Transform, HudTheme)
A thin horizontal rule (tinted like section labels) to separate panel sections.
public static Image Rule(string name, Transform parent, HudTheme theme)
Parameters
Returns
- Image
Section(string, Transform, HudTheme, string)
A small section label inside a panel ("ABILITIES", "TARGET"): sectionColor, upper case, medium weight and a little letter spacing, so it reads as structure rather than content.
public static TextMeshProUGUI Section(string name, Transform parent, HudTheme theme, string text = "")
Parameters
Returns
- TextMeshProUGUI
SetActive(Component, bool)
Activates a GameObject only when the state differs.
public static void SetActive(Component component, bool active)
Parameters
componentComponentactivebool
SetColor(Graphic, Color)
Sets a graphic colour only when it differs.
public static void SetColor(Graphic graphic, Color color)
Parameters
graphicGraphiccolorColor
SetFraction(RectTransform, float)
Sets a bar fill fraction (only touches the transform when it changes).
public static void SetFraction(RectTransform fill, float fraction)
Parameters
fillRectTransformfractionfloat
SetOutline(TMP_Text, HudTheme, Color, float)
Gives a label an outline (a shared material cached per font, colour and width; keeps the theme's shadow).
public static void SetOutline(TMP_Text label, HudTheme theme, Color color, float width)
Parameters
SetText(TMP_Text, string)
Sets text only when the reference differs (cached strings make this allocation-free).
public static void SetText(TMP_Text label, string text)
Parameters
labelTMP_Texttextstring
Stretch(RectTransform, float)
Stretches to fill the parent with an inset.
public static RectTransform Stretch(RectTransform rt, float inset = 0)
Parameters
rtRectTransforminsetfloat
Returns
- RectTransform
TextMaterial(TMP_FontAsset, Material, bool, Color, float)
A shared material for font: preset (or the font's material) with an optional drop
shadow (underlay) and outline (outlineWidth 0..1 of the SDF range, 0 = none). Cached, so labels with the
same look share one material and keep batching. Effects the shader does not support are skipped.
public static Material TextMaterial(TMP_FontAsset font, Material preset, bool shadow, Color outline, float outlineWidth)
Parameters
Returns
- Material