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
-
ObjectComponentBehaviourMonoBehaviourHudButton
- Implements
-
IPointerEnterHandlerIPointerExitHandlerIEventSystemHandler
- Inherited Members
-
MonoBehaviour.IsInvoking()MonoBehaviour.CancelInvoke()MonoBehaviour.StopCoroutine(Coroutine)MonoBehaviour.StopAllCoroutines()MonoBehaviour.destroyCancellationTokenMonoBehaviour.useGUILayoutMonoBehaviour.didStartMonoBehaviour.didAwakeMonoBehaviour.runInEditModeBehaviour.enabledBehaviour.isActiveAndEnabledComponent.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.transformComponent.transformHandleComponent.gameObjectComponent.tagObject.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.nameObject.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
IsPrimary
Whether the button uses the primary action look (SetPrimary(bool)).
public bool IsPrimary { get; }
Property Value
Key
Free slot for the owner (template id ...).
public string Key { get; set; }
Property Value
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
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
Tooltip
Builds the tooltip text when the pointer enters; null hides the tooltip.
public Func<HudButton, string> Tooltip { get; set; }
Property Value
Methods
AddHighlight(Sprite, Color, float)
Adds a selection outline.
public Image AddHighlight(Sprite sprite, Color color, float grow = 6)
Parameters
spriteSpritecolorColorgrowfloat
Returns
- Image
AddShade(Sprite, Color)
Adds a radial shade (for cooldowns) on top of the content.
public Image AddShade(Sprite sprite, Color color)
Parameters
spriteSpritecolorColor
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
namestringparentTransformthemeHudThemebackgroundSpritesizeVector2iconboollabelboolsubLabelbool
Returns
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
OnPointerEnter(PointerEventData)
public void OnPointerEnter(PointerEventData eventData)
Parameters
eventDataPointerEventData
OnPointerExit(PointerEventData)
public void OnPointerExit(PointerEventData eventData)
Parameters
eventDataPointerEventData
SetInteractable(bool)
Enables or disables clicking.
public void SetInteractable(bool value)
Parameters
valuebool
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
valuebool
SetSelected(bool)
Marks the button as the active choice (toggle look).
public void SetSelected(bool value)
Parameters
valuebool
Events
Clicked
Raised on click.
public event Action<HudButton> Clicked
Event Type
Hovered
Raised when the pointer enters (true) or leaves (false).
public event Action<HudButton, bool> Hovered