Skip to content

Game.UI.Widgets.Button

Assembly: Game (likely Assembly-CSharp.dll)
Namespace: Game.UI.Widgets

Type: class

Base: NamedWidgetWithTooltip
Implements: IInvokable, IWidget, IJsonWritable, IDisableCallback

Summary:
A simple UI button widget that exposes a public Action delegate which is executed when the button is invoked. The class provides a programmatic Invoke() method (from IInvokable) that calls the assigned action. Note: Invoke() calls the delegate directly without a null-check, so ensure action is assigned before calling to avoid a NullReferenceException.


Fields

  • This class does not declare any private or public fields in the provided source. All state is exposed via properties or inherited from the base class.
    {{ Additional implementation-specific state is provided by the base class NamedWidgetWithTooltip and by the interfaces. }}

Properties

  • public System.Action action { get; set; }
    Assign a callback to be executed when the button is invoked. Typical usage is to set this to a lambda or method that performs the button's action. Because Invoke() calls this delegate directly, check for null or ensure it is assigned before invocation.

Constructors

  • public Button()
    The default constructor is compiler-generated (no explicit constructor defined in the source). Initialization logic (if any) is expected to be handled by the base class or by consumers after construction.

Methods

  • public void Invoke()
    Calls the assigned action delegate: action(); Implements IInvokable.Invoke. This method does not perform a null-check on action and will throw a NullReferenceException if action is null. Callers should ensure action is assigned or wrap the call in a null-check when invoking externally.

Usage Example

// Create a button and assign an action
var btn = new Game.UI.Widgets.Button();
btn.action = () => {
    Debug.Log("Button pressed!");
};

// Invoke programmatically (ensure action is assigned)
btn.Invoke();

// Alternatively, you might assign action to call a method:
btn.action = OnMyButtonPressed;

void OnMyButtonPressed()
{
    // perform logic
}

{{ Notes: - Integrates with the UI system via its base class; how the button is rendered and receives input is handled by NamedWidgetWithTooltip and the UI framework. - Because it implements IJsonWritable, the widget may support serialization; check the implementation provided by the framework or base types for JSON behavior. - If you need safer invocation, wrap action invocation with a null check: if (btn.action != null) btn.Invoke(); }}