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

int

Methods

Align(TextAnchor)

Converts a uGUI anchor to the matching TextMesh Pro alignment.

public static TextAlignmentOptions Align(TextAnchor anchor)

Parameters

anchor TextAnchor

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

label TMP_Text
theme HudTheme

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

name string
parent Transform
theme HudTheme
fill Color
fillImage Image

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

labels IList<TMP_Text>
maxSize float
minSize float

Returns

float

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

name string
parent Transform
sprite Sprite
color Color
raycast bool

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

name string
parent Transform
theme HudTheme
size float
color Color
anchor TextAnchor
text string

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

rt RectTransform
anchor Vector2
pivot Vector2
position Vector2
size Vector2

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

name string
parent Transform
sprite Sprite
color Color

Returns

Image

Rect(string, Transform)

Creates a child RectTransform.

public static RectTransform Rect(string name, Transform parent)

Parameters

name string
parent Transform

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

name string
parent Transform
theme HudTheme

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

name string
parent Transform
theme HudTheme
text string

Returns

TextMeshProUGUI

SetActive(Component, bool)

Activates a GameObject only when the state differs.

public static void SetActive(Component component, bool active)

Parameters

component Component
active bool

SetColor(Graphic, Color)

Sets a graphic colour only when it differs.

public static void SetColor(Graphic graphic, Color color)

Parameters

graphic Graphic
color Color

SetFraction(RectTransform, float)

Sets a bar fill fraction (only touches the transform when it changes).

public static void SetFraction(RectTransform fill, float fraction)

Parameters

fill RectTransform
fraction float

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

label TMP_Text
theme HudTheme
color Color
width float

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

label TMP_Text
text string

Stretch(RectTransform, float)

Stretches to fill the parent with an inset.

public static RectTransform Stretch(RectTransform rt, float inset = 0)

Parameters

rt RectTransform
inset float

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

font TMP_FontAsset
preset Material
shadow bool
outline Color
outlineWidth float

Returns

Material