Class HudButton

Namespace
TDMaker.Unity.Hud
Assembly
TDMaker.Unity.dll

A themed button built from code: background, optional icon, label, secondary label, cooldown shade and badge. Reports hover for tooltips and previews. Setters only touch components when a value changes.

public sealed class HudButton : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler, IEventSystemHandler
Inheritance
Object
Component
Behaviour
MonoBehaviour
HudButton
Implements
IPointerEnterHandler
IPointerExitHandler
IEventSystemHandler
Inherited Members
MonoBehaviour.IsInvoking()
MonoBehaviour.CancelInvoke()
MonoBehaviour.StopCoroutine(Coroutine)
MonoBehaviour.StopAllCoroutines()
MonoBehaviour.destroyCancellationToken
MonoBehaviour.useGUILayout
MonoBehaviour.didStart
MonoBehaviour.didAwake
MonoBehaviour.runInEditMode
Behaviour.enabled
Behaviour.isActiveAndEnabled
Component.GetComponent<T>()
Component.TryGetComponent<T>(out T)
Component.GetComponentInChildren<T>()
Component.GetComponentsInChildren<T>()
Component.GetComponentInParent<T>()
Component.GetComponentsInParent<T>()
Component.GetComponents<T>()
Component.GetComponentIndex()
Component.CompareTag(TagHandle)
Component.transform
Component.transformHandle
Component.gameObject
Component.tag
Object.GetEntityId()
Object.GetInstanceID()
Object.GetHashCode()
Object.InstantiateAsync<T>(T)
Object.InstantiateAsync<T>(T, Transform)
Object.InstantiateAsync<T>(T, Vector3, Quaternion)
Object.InstantiateAsync<T>(T, Transform, Vector3, Quaternion)
Object.Instantiate(Object, Vector3, Quaternion)
Object.Instantiate(Object, Vector3, Quaternion, Transform)
Object.Instantiate(Object)
Object.Instantiate(Object, Scene)
Object.Instantiate<T>(T, InstantiateParameters)
Object.Instantiate<T>(T, Vector3, Quaternion, InstantiateParameters)
Object.Instantiate(Object, Transform)
Object.Instantiate<T>(T)
Object.Instantiate<T>(T, Vector3, Quaternion)
Object.Instantiate<T>(T, Vector3, Quaternion, Transform)
Object.Instantiate<T>(T, Transform)
Object.Destroy(Object)
Object.DestroyImmediate(Object)
Object.DontDestroyOnLoad(Object)
Object.DestroyObject(Object)
Object.FindObjectsOfType<T>()
Object.FindObjectsByType<T>(FindObjectsSortMode)
Object.FindObjectsByType<T>(FindObjectsInactive, FindObjectsSortMode)
Object.FindObjectOfType<T>()
Object.FindFirstObjectByType<T>()
Object.FindAnyObjectByType<T>()
Object.FindFirstObjectByType<T>(FindObjectsInactive)
Object.FindAnyObjectByType<T>(FindObjectsInactive)
Object.FindObjectsByType<T>()
Object.FindObjectsByType<T>(FindObjectsInactive)
Object.ToString()
Object.name
Object.hideFlags

Constructors

HudButton()

public HudButton()

Properties

Background

Background image (the button's target graphic).

public Image Background { get; }

Property Value

Image

Button

The underlying uGUI button.

public Button Button { get; }

Property Value

Button

Frame

The theme's trim over a rectangular button (buttonFrameColor), or null.

public Image Frame { get; }

Property Value

Image

Highlight

Outline shown when the button is selected.

public Image Highlight { get; }

Property Value

Image

Icon

Optional icon.

public Image Icon { get; }

Property Value

Image

IsHovered

Whether the pointer is over the button.

public bool IsHovered { get; }

Property Value

bool

IsPrimary

Whether the button uses the primary action look (SetPrimary(bool)).

public bool IsPrimary { get; }

Property Value

bool

Key

Free slot for the owner (template id ...).

public string Key { get; set; }

Property Value

string

Label

Main label.

public TextMeshProUGUI Label { get; }

Property Value

TextMeshProUGUI

PreviewsTemplate

When true, hovering previews the template named by Key (range and placement ghost).

public bool PreviewsTemplate { get; set; }

Property Value

bool

Shade

Radial shade drawn over the button (cooldowns).

public Image Shade { get; }

Property Value

Image

SubLabel

Secondary label (cost, timer).

public TextMeshProUGUI SubLabel { get; }

Property Value

TextMeshProUGUI

Tag

Free slot for the owner (index, id ...).

public int Tag { get; set; }

Property Value

int

Tooltip

Builds the tooltip text when the pointer enters; null hides the tooltip.

public Func<HudButton, string> Tooltip { get; set; }

Property Value

Func<HudButton, string>

Methods

AddHighlight(Sprite, Color, float)

Adds a selection outline.

public Image AddHighlight(Sprite sprite, Color color, float grow = 6)

Parameters

sprite Sprite
color Color
grow float

Returns

Image

AddShade(Sprite, Color)

Adds a radial shade (for cooldowns) on top of the content.

public Image AddShade(Sprite sprite, Color color)

Parameters

sprite Sprite
color Color

Returns

Image

Create(string, Transform, HudTheme, Sprite, Vector2, bool, bool, bool)

Creates a button under parent.

public static HudButton Create(string name, Transform parent, HudTheme theme, Sprite background, Vector2 size, bool icon, bool label, bool subLabel)

Parameters

name string
parent Transform
theme HudTheme
background Sprite
size Vector2
icon bool
label bool
subLabel bool

Returns

HudButton

LayoutText(bool, bool, float, float, float)

Centers ordinary labels; cards reserve separate title and footer rows, with optional icon and rank space. Explicit font sizes are retained across layouts so auto-fitting a narrow card never shrinks its future maximum.

public void LayoutText(bool leadingIcon = false, bool alignLeft = false, float footerRightInset = 0, float fontSize = 0, float subFontSize = 0)

Parameters

leadingIcon bool
alignLeft bool
footerRightInset float
fontSize float
subFontSize float

OnPointerEnter(PointerEventData)

public void OnPointerEnter(PointerEventData eventData)

Parameters

eventData PointerEventData

OnPointerExit(PointerEventData)

public void OnPointerExit(PointerEventData eventData)

Parameters

eventData PointerEventData

SetInteractable(bool)

Enables or disables clicking.

public void SetInteractable(bool value)

Parameters

value bool

SetPrimary(bool)

Gives the button the theme's primary action look (primaryButtonColor face and primaryTextColor label): one per screen for the action most players take next.

public void SetPrimary(bool value)

Parameters

value bool

SetSelected(bool)

Marks the button as the active choice (toggle look).

public void SetSelected(bool value)

Parameters

value bool

Events

Clicked

Raised on click.

public event Action<HudButton> Clicked

Event Type

Action<HudButton>

Hovered

Raised when the pointer enters (true) or leaves (false).

public event Action<HudButton, bool> Hovered

Event Type

Action<HudButton, bool>