Game.UI.Editor.FilePickerAdapter
Assembly:
Namespace: Game.UI.Editor
Type: class
Base: System.Object
Summary:
Adapter that bridges a collection of FileItem objects to several UI picker interfaces used by the editor (ItemPicker
Fields
-
private string m_SearchQuery = string.Empty
Holds the current search query used to filter m_Items. Empty string means no filtering. -
private List<FileItem> m_Items
The complete, sorted list of FileItem instances provided at construction. -
private List<FileItem> m_FilteredItems
The current filtered subset of m_Items after applying m_SearchQuery. Used by the ItemPicker adapter. -
private bool m_FilteredItemsChanged
Flag set when UpdateFilteredItems alters m_FilteredItems. Reset by the explicit ItemPicker.Update implementation. -
[CanBeNull] private FileItem m_SelectedItem
Currently selected FileItem. Nullable. -
private int m_ColumnCount
Number of columns the UI should use to display items. Persisted to editor settings when changed. -
public Action<FileItem> EventItemSelected
Event/action invoked when an item is selected via the explicit ItemPicker.IAdapter.selectedItem setter. May be null.
Properties
-
public FileItem selectedItem { get; set; }
Gets or sets the currently selected item (backed by m_SelectedItem). Setting this property only updates the stored selection; it does not invoke EventItemSelected. -
FileItem ItemPicker<FileItem>.IAdapter.selectedItem { get; set; }
Explicit interface implementation used by the ItemPicker. Getting returns the current selection. Setting updates m_SelectedItem and invokes EventItemSelected (if non-null). This is the path to notify listeners when the picker UI changes selection. -
List<FileItem> ItemPicker<FileItem>.IAdapter.items => m_FilteredItems
Explicit read-only interface property returning the currently filtered list shown by the picker. -
public string searchQuery { get; set; }
Public search query property. When changed, triggers UpdateFilteredItems() to rebuild m_FilteredItems. Matching is performed with StringComparison.OrdinalIgnoreCase against FileItem.path. -
int ItemPickerFooter.IAdapter.length => m_FilteredItems.Count
Explicit interface property returning the length of the filtered list (used by footer UI). -
public int columnCount { get; set; }
Number of columns for the asset picker grid. When set, the value is stored into SharedSettings.instance?.editor?.assetPickerColumnCount (if editor settings are available). The constructor initializes this from the same settings, defaulting to 4 if not present.
Constructors
public FilePickerAdapter(IEnumerable<FileItem> items)
Initializes the adapter from a sequence of FileItem. The constructor:- Copies items into m_Items and sorts them (using FileItem's comparison),
- Copies items into m_FilteredItems (initially unfiltered),
- Loads m_ColumnCount from SharedSettings.instance.editor.assetPickerColumnCount or defaults to 4.
Methods
-
public FileItem SelectItemByName(string name, StringComparison comparisonType)
Searches the full m_Items list for the first FileItem whose path equals name according to the provided comparisonType. Sets m_SelectedItem to the found item (or null if not found) and returns it. Does not raise EventItemSelected. -
private void UpdateFilteredItems()
Rebuilds m_FilteredItems from m_Items according to m_SearchQuery: - If m_SearchQuery is null or empty, copies all items.
-
Otherwise, includes items where item.path.IndexOf(m_SearchQuery, StringComparison.OrdinalIgnoreCase) != -1 (case-insensitive substring match). Sets m_FilteredItemsChanged = true to indicate the visible set changed.
-
bool ItemPicker<FileItem>.IAdapter.Update()
Explicit interface implementation called by the picker UI to check whether the filtered items changed. Returns the current value of m_FilteredItemsChanged and resets it to false. -
void ItemPicker<FileItem>.IAdapter.SetFavorite(int index, bool favorite)
Explicit interface implementation intended to mark an item as favorite. Currently implemented as a no-op.
Usage Example
// Construct adapter with a collection of FileItem
var adapter = new FilePickerAdapter(allFileItems);
// Listen to selection changes coming from the picker UI
adapter.EventItemSelected = item =>
{
if (item != null)
{
Console.WriteLine("Selected: " + item.path);
}
};
// Set a search query to filter shown items (case-insensitive substring match)
adapter.searchQuery = "bridge";
// Ask the adapter to select an item by exact path (ordinal ignore case or other comparison)
var selected = adapter.SelectItemByName("assets/bridge.bundle", StringComparison.OrdinalIgnoreCase);
// Read the filtered items (via explicit interface in picker UI; shown here for example)
var filtered = ((ItemPicker<FileItem>.IAdapter)adapter).items;
// Change column count (also persisted to SharedSettings.instance.editor.assetPickerColumnCount if available)
adapter.columnCount = 6;
Notes: - Filtering is performed on FileItem.path with case-insensitive substring matching. - The explicit ItemPicker selectedItem setter invokes EventItemSelected; direct assignment to the public selectedItem property does not. - The adapter stores and restores the column count via SharedSettings; if settings are unavailable it defaults to 4.