Game.UI.Editor.SearchField
Assembly: Assembly-CSharp
Namespace: Game.UI.Editor
Type: class
Base: Widget
Summary:
SearchField is a UI widget used to represent a searchable text field in editor UI. It exposes a simple adapter interface (IAdapter) that provides a single string property searchQuery which the widget binds to. The widget supports JSON read/write operations via IJsonWritable/ISettable and signals property changes when the adapter's value changes. Note: the widget expects adapter to be set before calling SetValue or relying on Update, otherwise accessing adapter.searchQuery will throw.
Fields
-
private string m_Value
Holds the current cached value of the search field. This value is compared with adapter.searchQuery in Update to detect changes and is written out by WriteProperties. It may be null until first sync. -
public IAdapter adapter { get; set; }
Adapter instance used to get/set the underlying search query. This is a public auto-property (not a backing field) but listed here because it is a key member the widget relies on. The adapter must implement the nested IAdapter interface.
Properties
-
public bool shouldTriggerValueChangedEvent { get; }
Always returns true. Indicates that this widget should trigger a value-changed event when its value changes (used by the UI framework that consumes widgets). -
public IAdapter adapter { get; set; }
(Repeated from Fields for clarity) The adapter used to bind the widget to an external searchQuery value.
Constructors
public SearchField()
No explicit constructor is defined in the class file; the default parameterless constructor is available. After construction, set adapter before interacting with the widget to avoid null-reference access.
Methods
-
public void SetValue(IJsonReader reader)
Reads a string from the provided IJsonReader and forwards it to SetValue(string). This implements part of ISettable/IJsonWritable behavior to import state from JSON. -
public void SetValue(string value)
If the provided value differs from the cached m_Value, assigns the value to adapter.searchQuery. Note: this writes to the adapter (push model). Requires adapter to be non-null. -
protected override WidgetChanges Update()
Called by the UI framework to let the widget refresh. Compares adapter.searchQuery with the cached m_Value; if they differ, sets the WidgetChanges.Properties flag and updates m_Value to match the adapter. Returns accumulated WidgetChanges. Requires adapter to be non-null. -
protected override void WriteProperties(IJsonWriter writer)
Writes the widget's properties to the given IJsonWriter. Writes a property named "value" with the current m_Value (or empty string if null). Also calls the base implementation. -
public interface IAdapter
(nested)
Defines a single property: string searchQuery { get; set; }
Implement this interface to back the SearchField with whichever model/store you need. The widget reads from and writes to this property.
Behavior notes / tips: - The widget uses the adapter as the single source of truth for the search text. SetValue(string) updates the adapter; Update() pulls from the adapter and updates the widget's cached value and UI state. - Because the widget accesses adapter.searchQuery directly, ensure adapter is assigned (not null) before using SetValue, Update, or letting the UI system tick the widget. - The widget participates in JSON serialization/deserialization by reading a string value via SetValue(IJsonReader) and writing "value" via WriteProperties.
Usage Example
// Simple adapter implementation
class MySearchAdapter : SearchField.IAdapter
{
public string searchQuery { get; set; } = string.Empty;
}
// Example usage in UI creation code
var field = new SearchField();
field.adapter = new MySearchAdapter();
// Push a value into the adapter via the widget API
field.SetValue("main street");
// Later, the UI system will call Update(), which will detect changes
// between adapter.searchQuery and the widget's cached m_Value and mark
// properties dirty when appropriate.
// JSON import example (IJsonReader provided by the framework)
IJsonReader reader = /* obtained from framework */;
field.SetValue(reader);
// JSON export will include the current "value" via WriteProperties.