Skip to content

Game.UI.Widgets.DirectoryPickerButton

Assembly:
Assembly-CSharp

Namespace:
Game.UI.Widgets

Type:
class

Base:
NamedWidgetWithTooltip
Implements: IInvokable, IWidget, IJsonWritable

Summary:
A small UI widget representing a button used to pick a directory. Stores the currently selected directory (private), exposes a human-readable display value, and an Action to invoke when the button is activated. Implements JSON serialization for its key properties (selectedDirectory, displayValue and uiTag) via WriteProperties so the widget state can be persisted or transferred.


Fields

  • private string m_SelectedDirectory
    Holds the currently selected directory path for the widget. This field is private and is written out when WriteProperties is called. There is no public setter provided in this class, so the value is managed internally or set by other parts of the UI system.

Properties

  • public string displayValue { get; set; }
    A string intended for display on the button (label or placeholder). Can be read and modified by callers to change what the widget shows to the user.

  • public Action action { get; set; }
    An Action delegate that is invoked when the widget is triggered via Invoke(). Note: Invoke() calls this delegate directly without a null check in the class code, so callers should ensure it is set before invoking.

  • public override string propertiesTypeName => "Game.UI.Widgets.DirectoryPickerButton"
    Returns the runtime properties type name for this widget. Used by the UI/property system to identify the widget type.

Constructors

  • public DirectoryPickerButton()
    No explicit constructor is defined in the source; the default parameterless constructor is used. Initialization beyond defaults (for example, assigning an action or displayValue) must be done after instantiation.

Methods

  • public void Invoke()
    Calls the configured action delegate: action(). This is how the widget triggers its behavior (e.g., opening a folder chooser). Because the method invokes the delegate without checking for null, ensure action is assigned before calling Invoke() to avoid a NullReferenceException.

  • protected override void WriteProperties(IJsonWriter writer)
    Overrides the base widget property writer to serialize this widget's additional state. Calls base.WriteProperties(writer) and then writes the following properties into the provided IJsonWriter:

  • "selectedDirectory" -> m_SelectedDirectory
  • "displayValue" -> displayValue
  • "uiTag" -> base.uiTag

This allows the widget state to be exported as JSON for saving or communication with other systems.

Usage Example

// Create and configure the directory picker button
var dirButton = new Game.UI.Widgets.DirectoryPickerButton
{
    displayValue = "Choose folder",
    action = () =>
    {
        // Open a directory chooser dialog (implementation depends on your UI layer)
        // Example placeholder:
        UnityEngine.Debug.Log("Directory chooser should open here.");
        // After picking a directory, the UI system or owning code would assign
        // the selected path into the widget's backing field (m_SelectedDirectory)
        // via the appropriate API or internal flow.
    }
};

// Trigger the action (ensure action is not null)
dirButton.Invoke();

// When the UI/property system serializes widgets, WriteProperties will include
// selectedDirectory, displayValue and uiTag.

Notes and caveats: - m_SelectedDirectory is private and there is no public getter/setter in this class. If you need to change or read the selected directory from external code, you will need to use the owning UI system APIs or reflection. - Ensure action is non-null before calling Invoke() to avoid exceptions.