Skip to content

Game.Prefabs.UIObject

Assembly: Assembly-CSharp
Namespace: Game.Prefabs

Type: class

Base: ComponentBase

Summary:
UIObject is a prefab component that represents an in-game UI element. It associates the prefab with a UI group (UIGroupPrefab), holds an ordering priority, an editor-visible icon reference, and a flag to indicate debug-only objects. At initialization it writes UIObjectData to the entity (unless the object is debug-only and the build is not a debug build), resolves/adds the group element to the prefab system, and exposes mod tag information derived from the assigned UI group/category/menu.


Fields

  • public UIGroupPrefab m_Group
    Reference to the UI group (or category) this UI object belongs to. When present, LateInitialize resolves the corresponding entity for the group via PrefabSystem and calls m_Group.AddElement to register the UI element with that group.

  • public int m_Priority
    Integer priority used to order UI elements. Value is written into the UIObjectData component during LateInitialize.

  • public string m_Icon
    Icon identifier displayed/edited in the prefab inspector. Decorated with [CustomField(typeof(UIIconField))] so the editor will present a custom icon picker/editor.

  • public bool m_IsDebugObject
    If true, this prefab is treated as debug-only: components and data for this object are only added at runtime when UnityEngine.Debug.isDebugBuild is true. Used to exclude debug UI objects from release builds.

Properties

  • public override IEnumerable<string> modTags { get; }
    Yields mod tags for the prefab. Behavior:
  • First yields all tags returned by base.modTags.
  • If m_Group is a UIAssetCategoryPrefab (named category), yields "UI" + category.name.
  • If category.name starts with "Props" also yields "UIProps".
  • If category.m_Menu is not null, also yields "UI" + category.m_Menu.name. These tags are useful for filtering or presenting prefabs by UI category/menu in modding tools.

Constructors

  • public UIObject()
    Default constructor (no explicit constructor is defined in source; default parameterless constructor provided).

Methods

  • public override void GetDependencies(List<PrefabBase> prefabs)
    Adds m_Group to the given prefabs list (if non-null) so the group prefab is treated as a dependency. Calls base.GetDependencies(prefabs) first.

  • public override void GetPrefabComponents(HashSet<ComponentType> components)
    If the object is not debug-only or the build is a debug build, adds ComponentType.ReadWrite() to the provided components set. This ensures the UIObjectData component gets created on the prefab entity.

  • public override void GetArchetypeComponents(HashSet<ComponentType> components)
    No archetype components are added by UIObject (method intentionally empty in the source).

  • public override void LateInitialize(EntityManager entityManager, Entity entity)
    Performs runtime initialization for the prefab entity:

  • Calls base.LateInitialize.
  • If not a debug-only object (or running a debug build), resolves the group entity (Entity.Null if no group).
  • If m_Group is set, obtains the group's entity via PrefabSystem.GetEntity(m_Group) and calls m_Group.AddElement(entityManager, entity) to register the element with the group.
  • Writes a UIObjectData component to the entity with m_Group set to the resolved group entity and m_Priority set to the field value. This populates runtime ECS data used by UI systems.

Usage Example

// Example: create/configure a UIObject prefab instance in code (typically done in editor)
var uiObject = new UIObject
{
    m_Group = myGroupPrefab,    // UIGroupPrefab reference
    m_Priority = 100,          // ordering priority
    m_Icon = "Buildings/House",// icon id shown in inspector (UIIconField)
    m_IsDebugObject = false    // include in release builds
};

// At runtime, LateInitialize is called by the prefab system and will:
// - register this element with m_Group (if set)
// - add UIObjectData to the entity with m_Group entity and m_Priority