Skip to content

Game.UI.Menu.DirectoryPickerField

Assembly: Assembly-CSharp.dll
Namespace: Game.UI.Menu

Type: class

Base: Field, IInvokable, IWidget, IJsonWritable, IWarning

Summary:
DirectoryPickerField is a UI field used to represent and edit a directory path (string). It exposes an invokable action (typically to open a folder picker UI), a runtime-evaluated warning state via a Func (warningAction), and writes its warning state when serialized to JSON. The class overrides the widget update to evaluate the warningAction each update and raises a properties change when the warning state changes.


Fields

  • private bool m_Warning
    Stores the current cached warning state. This is the backing state used by the public warning property.

  • private System.Func<bool> <warningAction>k__BackingField
    Backing field generated for the auto-property warningAction (public Func warningAction { get; set; }). Holds the delegate that is invoked each Update to recompute the warning state (can be null).

  • private System.Action <action>k__BackingField
    Backing field generated for the auto-property action (public Action action { get; set; }). Holds the delegate executed when Invoke() is called.

Properties

  • public System.Func<bool> warningAction { get; set; }
    Optional delegate that, if set, is evaluated each Update to determine whether the field should be in a warning state. The delegate should return true when the field should display a warning. Setting this property simply assigns the delegate; the actual warning state is cached in m_Warning and updated during Update().

  • public override string propertiesTypeName => "Game.UI.Widgets.DirectoryPickerField"
    String identifying the widget type name used by the UI/widget system when serializing/deserializing or creating the widget in the editor.

  • public System.Action action { get; set; }
    Delegate that will be invoked when Invoke() is called. Typically used to open a directory picker dialog or perform the pick action.

  • public bool warning { get; set; }
    Public boolean property reflecting the current warning state. The setter clears any warningAction delegate (sets warningAction = null) and sets the cached m_Warning flag directly. Getting returns the current cached m_Warning.

Constructors

  • public DirectoryPickerField()
    Default constructor (compiler-provided). Initializes a new instance of DirectoryPickerField. No special initialization logic is declared in the class source.

Methods

  • public void Invoke()
    Calls the action delegate if one is assigned. Typical use: the UI control triggers Invoke to open a directory chooser.

  • protected override WidgetChanges Update()
    Overrides the base Field.Update() to additionally evaluate warningAction (if non-null). If warningAction() returns a value different from the cached m_Warning, the cached value is updated and the method adds WidgetChanges.Properties to the returned WidgetChanges flags so the UI system knows properties changed and the widget should be refreshed.

  • protected override void WriteProperties(IJsonWriter writer)
    Writes serializable properties to the provided IJsonWriter. Calls base.WriteProperties(writer) then emits a "warning" boolean property with the current warning value. Used when the widget is serialized to JSON (for layout persistence, debugging, or editor tooling).

Usage Example

// Example: create and configure a DirectoryPickerField inside widget initialization
[Preserve]
protected override void OnCreate()
{
    base.OnCreate();

    var dirField = new DirectoryPickerField();

    // set the action to open a folder picker when invoked
    dirField.action = () =>
    {
        // OpenFolderPicker is an example helper; replace with actual implementation
        string selectedPath = OpenFolderPicker();
        if (!string.IsNullOrEmpty(selectedPath))
            dirField.value = selectedPath; // assumes Field<string> exposes 'value'
    };

    // set a warningAction so the field shows a warning when empty
    dirField.warningAction = () => string.IsNullOrEmpty(dirField.value);

    // manually invoke (e.g., when user presses a button)
    // dirField.Invoke();
}

Notes and best practices: - Use warningAction when the warning state should be derived dynamically (e.g., validation). If you want to set the warning state manually, assign the public warning property, which clears any warningAction. - Ensure that the action delegate performs UI-safe operations (run on main thread / UI context) since Invoke may be called from UI event handlers.