Skip to content

Game.UI.Editor.TypePickerPanel

Assembly:
Assembly-CSharp (game assembly)

Namespace:
Game.UI.Editor

Type:
public class

Base:
DirectoryPanelBase

Summary:
TypePickerPanel is a UI directory-style picker used to present and select .NET types in a hierarchical, searchable, paged list. It accepts a collection of Item entries (representing types and virtual directories), builds any missing directory entries from item.parentDir (splitting on '/'), and populates a panel containing a SearchField, a PageView, and a Cancel button. Selecting a directory navigates into it; selecting a non-directory item invokes the provided SelectCallback with the chosen Type. The class also provides a helper to enumerate all concrete (non-abstract) subclasses of a generic base type from the executing assembly.


Fields

  • private readonly SelectCallback m_SelectCallback
    Callback invoked when the user selects a non-directory item. Provided by the constructor; receives the selected Type.

(Other storage used by the class—such as m_RootDirName, m_Items, m_Directories, and m_PageView—are members inherited from DirectoryPanelBase and are populated/used by the constructor.)

Properties

  • (none declared in this class)
    All relevant stateful members used by this panel are inherited from DirectoryPanelBase or passed via the constructor.

Constructors

  • public TypePickerPanel(LocalizedString panelTitle, LocalizedString rootDirName, IEnumerable<Item> items, SelectCallback onSelect, Action onCancel)
    Creates a TypePickerPanel:
  • Copies the provided items into an internal list.
  • Validates each Item with assertions (item.type and item.name must not be null; item.directory must be false for provided items).
  • If an Item has an empty displayName, sets it to item.name.
  • Builds missing directory entries from item.parentDir by splitting on '/' and creating directory Item objects (displayName set via LocalizedString.Value for each directory segment) and storing them in m_Directories.
  • Ensures each item's fullName and parentDir are normalized so directory navigation works.
  • Sets the panel title and children widgets: a SearchField (adapter = this), a PageView (currentPage = 0), and a Cancel Button wired to onCancel.
  • Calls ShowSubDir(null) to display the root directory initially.

Methods

  • public delegate void SelectCallback(Type type)
    Delegate type used for selection callbacks. Invoked with the Type selected by the user.

  • public override void OnSelect(Item item)
    Handles item selection from the UI:

  • If item is null: no-op.
  • If item.directory is true: navigates into that directory by calling ShowSubDir(item.relativePath + "/").
  • Otherwise (non-directory item): invokes m_SelectCallback(item.type) to notify the caller of the chosen Type.

  • public static IEnumerable<Type> GetAllConcreteTypesDerivedFrom<T>()
    Helper that returns all non-abstract types from the executing assembly that are subclasses of T:

  • Uses Assembly.GetExecutingAssembly().GetTypes().
  • Filters out abstract types and types that are not subclass of typeof(T).
  • Useful for generating Item lists for the panel when you want all implementations/derivatives of a base type.

Usage Example

// Build a simple list of Items (Item type and exact fields depend on the game's UI item model).
// For illustration assume Item has at least: type, name, displayName, relativePath, parentDir, directory, fullName.

IEnumerable<Item> items = myTypes.Select(t => new Item {
    type = t,
    name = t.Name,
    displayName = LocalizedString.Value(t.Name),
    relativePath = "",      // or set appropriate path like "Group/SubGroup"
    parentDir = null,       // or "Group/SubGroup"
    directory = false,
    fullName = null
});

var picker = new TypePickerPanel(
    panelTitle: LocalizedString.Value("UI.ChooseType"),
    rootDirName: LocalizedString.Value("Root"),
    items: items,
    onSelect: selectedType => {
        Debug.Log($"User selected type: {selectedType.FullName}");
        // handle selection (e.g., instantiate, configure, assign)
    },
    onCancel: () => {
        Debug.Log("Type selection canceled.");
        // close panel or revert UI
    }
);

// Example: get all concrete subclasses of MyBaseClass from the executing assembly:
var derivedTypes = TypePickerPanel.GetAllConcreteTypesDerivedFrom<MyBaseClass>();

Notes and tips: - The constructor asserts item.type and item.name are not null and that provided items are not already marked as directories; missing directories are generated automatically from parentDir. - LocalizedString is used for displayable names — prefer LocalizedString.Value(...) when building Items or when passing titles. - ShowSubDir and layout/paging behavior are implemented in DirectoryPanelBase; this class configures the contents and selection behavior.