Skip to content

Game.UI.Editor.DirectoryPanelBase

Assembly: Assembly-CSharp
Namespace: Game.UI.Editor

Type: public abstract class

Base: EditorPanelBase, SearchField.IAdapter

Summary:
Base class for directory-style item picker panels used in the editor UI. Manages a navigation stack of DirectoryAdapter instances and corresponding pages (PageLayout) displayed in a PageView. Implements SearchField.IAdapter by forwarding the search query to the current directory adapter. Handles building adapter/page pairs, navigating into sub-directories and back navigation.


Fields

  • protected static ILog log = UIManager.log
    Logging instance (static) reused by the panel. Sourced from the UIManager logger.

  • protected const char kDirSeparator = '/'
    Directory separator character used in directory path strings.

  • protected List<Item> m_Items
    The list of all items available to the panel. When building adapters the list is copied into adapter.items.

  • protected Dictionary<string, Item> m_Directories = new Dictionary<string, Item>()
    Mapping of directory path -> Item (or metadata) used to get display names for directories when creating PageLayout titles.

  • protected LocalizedString m_RootDirName
    Localized display name used for the root directory page title (when adapter.directoryPath is null).

  • protected PageView m_PageView
    The PageView widget that hosts the pages created for each directory level. Children and currentPage are updated when navigating.

  • protected readonly List<DirectoryAdapter> m_Stack = new List<DirectoryAdapter>()
    Navigation stack of DirectoryAdapter instances. The last adapter is treated as the "current" directory.

  • protected readonly List<IWidget> m_Pages = new List<IWidget>()
    List of page widgets (PageLayout instances) corresponding to m_Stack. Kept in sync with m_Stack and assigned to m_PageView.children.

Properties

  • string SearchField.IAdapter.searchQuery { get; private set }
    Explicit implementation of SearchField.IAdapter.searchQuery. The getter and setter forward to the searchQuery of the current DirectoryAdapter: m_Stack.Last().searchQuery. Note: because this is an explicit interface implementation you must reference the panel via the interface to access it. If m_Stack is empty, calling this will throw (via Last()) — the adapter stack is expected to contain at least one adapter when search is used.

Constructors

  • public DirectoryPanelBase()
    No explicit constructor is declared in the source; the parameterless default constructor is provided by the compiler. Several fields are initialized inline (m_Directories, m_Stack, m_Pages). Subclasses should initialize required widgets (e.g., m_PageView) and data (m_Items, m_RootDirName) before calling ShowSubDir or relying on the stack.

Methods

  • public abstract void OnSelect(Item item)
    Abstract callback invoked when an item is selected from an ItemPicker on one of the pages. Implementations must define how selection is handled (e.g., placing an item, opening details, etc.).

  • protected virtual void ShowSubDir(string dir)
    Creates a DirectoryAdapter for the given directory path (dir may be null for the root), pushes it onto m_Stack, builds a corresponding page with BuildPage, appends it to m_Pages, updates m_PageView.children and sets m_PageView.currentPage to the new top of the stack. Use to navigate into a directory.

  • private DirectoryAdapter BuildAdapter(string dir)
    Creates and returns a new DirectoryAdapter bound to this panel. Sets adapter.directoryPath = dir and copies the current m_Items into adapter.items (m_Items.ToList()). The adapter is not automatically pushed — ShowSubDir wraps this to push and build the page.

  • private IWidget BuildPage(DirectoryAdapter adapter)
    Builds a PageLayout for the provided adapter. The page title is taken from m_Directories[adapter.directoryPath].displayName when adapter.directoryPath != null, otherwise m_RootDirName is used. If adapter.directoryPath != null a backAction (OnBack) is wired to the page. The page contains a single ItemPicker configured with the adapter, hasFavorites = true and hasImages = false.

  • protected virtual void OnBack()
    Handles back navigation. If there is more than one adapter on m_Stack, removes the top adapter and its corresponding page, clears selectedItem on the new top adapter, updates m_PageView.children and sets m_PageView.currentPage to the new top index. Does nothing if the stack has only one entry.

Usage Example

// Minimal example subclass showing typical usage
public class MyDirectoryPanel : DirectoryPanelBase
{
    public MyDirectoryPanel()
    {
        // Populate items and directories before showing pages
        m_Items = new List<Item>()
        {
            // populate with Item instances
        };

        // Example: set localized root name
        m_RootDirName = new LocalizedString("Root");

        // PageView is typically created by the UI framework; ensure it's present
        m_PageView = new PageView();

        // Show the root page (pass null for root directoryPath)
        ShowSubDir(null);
    }

    public override void OnSelect(Item item)
    {
        // Handle item selection (called from ItemPicker)
        // e.g., place item in editor or open details
    }
}

// Example of using the search adapter (SearchField will use this):
SearchField search = /* obtain search field */;
search.adapter = (SearchField.IAdapter)myDirectoryPanel; // panel implements the adapter explicitly
((SearchField.IAdapter)myDirectoryPanel).searchQuery = "road";