Game.UI.Editor.EditorAssetCategory
Assembly: Assembly-CSharp.dll
Namespace: Game.UI.Editor
Type: class
Base: System.Object
Summary:
Represents an asset category used by the in-game editor UI. An EditorAssetCategory can contain child categories, include or exclude specific prefab entities, define an EntityQuery for automatic membership, and apply a custom filter. It also contains metadata used by the UI (id, path, icon, default selection, and localization key generation). Designed to work with the ECS EntityManager and the game's PrefabSystem to enumerate prefabs or entities for rendering the editor asset lists.
Fields
-
private System.Collections.Generic.List<EditorAssetCategory> m_SubCategories
Holds the child categories. This is the underlying storage for the public subCategories property and is used when iterating child categories for entity/prefab enumeration or creating HierarchyItem entries. -
private HashSet<Entity> <exclude>k__BackingField
Compiler backing field for the private exclude property (stores entities that should be excluded from this category). -
private System.Collections.Generic.List<Entity> <include>k__BackingField
Compiler backing field for the private include property (stores entities explicitly included in this category). -
private string <id>k__BackingField
Compiler backing field for the id auto-property. -
private string <path>k__BackingField
Compiler backing field for the path auto-property. -
private EntityQuery <entityQuery>k__BackingField
Compiler backing field for the entityQuery auto-property. -
private EditorAssetCategorySystem.IEditorAssetCategoryFilter <filter>k__BackingField
Compiler backing field for the filter auto-property. -
private string <icon>k__BackingField
Compiler backing field for the icon auto-property. -
private bool <includeChildCategories>k__BackingField
Compiler backing field for the includeChildCategories auto-property. -
private bool <defaultSelection>k__BackingField
Compiler backing field for the defaultSelection auto-property.
Properties
-
public IReadOnlyList<EditorAssetCategory> subCategories { get; }
Exposes child categories as a read-only list. Backed by m_SubCategories. AddSubCategory should be used to add children. -
public string id { get; set; }
Identifier used as a fallback display name when localization for the path is not found. -
public string path { get; set; }
Path used to form the localization ID for the category title. Used with kNameFormat to build a localized title. -
public EntityQuery entityQuery { get; set; }
An ECS EntityQuery whose results contribute entities to this category when enumerating. If set, GetEntities will iterate archetype chunks from this query. -
public EditorAssetCategorySystem.IEditorAssetCategoryFilter filter { get; set; }
Optional filter instance used to further restrict which entities from entityQuery should be included. If null, all entities from the query are accepted (subject to excludes). -
private HashSet<Entity> exclude { get; set; }
Private property containing entity exclusions — entities explicitly excluded from this category. -
private List<Entity> include { get; set; }
Private property for entities explicitly included in this category (in addition to those discovered via entityQuery and child categories). -
public string icon { get; set; }
Optional icon id/name shown in the UI for this category. -
public bool includeChildCategories { get; set; }
= true
If true, GetEntities will recursively include entities from child categories. Default is true. -
public bool defaultSelection { get; set; }
If true, this category is initially selected in UI lists that use defaultSelection.
Constructors
public EditorAssetCategory()
Default parameterless constructor (implicit). Initializes m_SubCategories to an empty list. Other collections (include/exclude) are allocated lazily when needed.
Methods
-
public void AddSubCategory(EditorAssetCategory category)
Adds a child category to m_SubCategories. Child categories are used when includeChildCategories is true to recursively gather entities/prefabs. -
public HashSet<PrefabBase> GetPrefabs(EntityManager entityManager, PrefabSystem prefabSystem, EntityTypeHandle entityType)
Iterates entities returned by GetEntities(...) and resolves them to PrefabBase instances via PrefabSystem.TryGetPrefab. Returns a HashSet of unique PrefabBase objects represented by the category (and its included entities). Useful for building the UI list of assets. -
public IEnumerable<Entity> GetEntities(EntityManager entityManager, PrefabSystem prefabSystem, EntityTypeHandle entityType)
Core enumeration method. Behavior: - If entityQuery is set, iterates through its archetype chunks and yields entities that pass CheckFilters.
- If includeChildCategories is true, recursively yields entities from subcategories.
-
Yields any entities explicitly added via AddEntity. This method uses the provided EntityTypeHandle to read Entity arrays from chunks and applies filter/exclude logic.
-
public bool IsEmpty(EntityManager entityManager, PrefabSystem prefabSystem, EntityTypeHandle entityType)
Returns whether the category contains any entities. Performs a quick check using entityQuery optimizations: if entityQuery is set and non-empty (IsEmptyIgnoreFilter false), and no filter or excludes are applied, the category is considered non-empty. Otherwise it checks GetEntities().Any(). -
public void AddExclusion(Entity entity)
Adds the given entity to the exclusion set for this category. The exclude collection is lazily created on first use. Excluded entities will be filtered out during GetEntities. -
public void AddEntity(Entity entity)
Adds a single entity to the include list (lazy creation). These entities are always yielded by GetEntities regardless of entityQuery. -
public string GetLocalizationID()
Returns the localization ID for this category title using the format string kNameFormat and the category path: string.Format(kNameFormat, path). -
private bool CheckFilters(Entity entity, EntityManager entityManager, PrefabSystem prefabSystem)
Applies the configured filter and exclude rules for a single entity. Returns true if the entity should be included: - If filter is null, passes.
- If filter != null, calls filter.Contains(entity, entityManager, prefabSystem).
-
If exclude is non-null, excludes entities present in the exclude set.
-
public HierarchyItem<EditorAssetCategory> ToHierarchyItem(int level = 0)
Constructs a HierarchyItemused by the UI hierarchy control. The display name is retrieved from localization via LocalizedString.IdWithFallback(GetLocalizationID(), id). Sets fields such as m_Icon, m_Selectable, m_Selected (defaultSelection), m_Expandable (based on child count), and m_Level.
Usage Example
// Example usage inside an editor UI system:
var rootCategory = new EditorAssetCategory
{
id = "Roads",
path = "roads",
icon = "icon_roads",
defaultSelection = false
};
// Add a subcategory
var smallRoads = new EditorAssetCategory { id = "Small Roads", path = "roads.small", icon = "icon_small_roads" };
rootCategory.AddSubCategory(smallRoads);
// Explicitly include or exclude specific entities
rootCategory.AddEntity(someRoadEntity);
rootCategory.AddExclusion(someDeprecatedRoadEntity);
// Use an EntityQuery to populate category automatically
rootCategory.entityQuery = entityManager.CreateEntityQuery(new EntityQueryDesc {
All = new ComponentType[] { /* components that identify road prefabs */ }
});
// Optionally apply a custom filter (implement IEditorAssetCategoryFilter)
rootCategory.filter = new MyRoadFilter();
// Iterate prefabs for UI listing
var prefabs = rootCategory.GetPrefabs(entityManager, prefabSystem, entityTypeHandle);
foreach (var prefab in prefabs)
{
// populate UI item for prefab
}
Notes: - GetEntities yields live Entity values; callers should not assume stability across frames. - Localization ID pattern: "Editor.ASSET_CATEGORY_TITLE[{0}]" where {0} is replaced by the category.path. Use LocalizedString.IdWithFallback to get a user-visible label.