Skip to content

Game.Prefabs.ThemeObject

Assembly:
Assembly-CSharp.dll

Namespace:
Game.Prefabs

Type:
class ThemeObject

Base:
ComponentBase

Summary:
ThemeObject is a prefab component that links a prefab to a ThemePrefab. It: - Exposes the theme reference (m_Theme) which is included in the prefab's mod tags when present. - Declares an object requirement component (ObjectRequirementElement) for the prefab so the prefab system can resolve theme-based object requirements at runtime. - Adds the referenced ThemePrefab to the prefab dependency list. - During entity initialization (LateInitialize) it writes an ObjectRequirementElement into the entity's buffer pointing to the runtime Entity for the ThemePrefab, using ObjectRequirementType.IgnoreExplicit.


Fields

  • public ThemePrefab m_Theme
    Reference to the ThemePrefab asset used by this prefab. This is serialized on the prefab and used both for dependency tracking and to populate mod tags and object requirements.

Properties

  • public override IEnumerable<string> modTags { get }
    Returns the base mod tags and, if m_Theme is not null, also yields the theme's name (m_Theme.name). This makes the theme name available as a mod tag for filtering/searching.

Constructors

  • public ThemeObject()
    No explicit constructor is defined; the default parameterless constructor is used. Initialization is performed by the prefab system and LateInitialize.

Methods

  • public override void GetDependencies(List<PrefabBase> prefabs)
    Adds the referenced ThemePrefab (m_Theme) to the provided prefab dependency list and calls the base implementation. Ensures the theme asset is considered a dependency of this prefab.

  • public override void GetPrefabComponents(HashSet<ComponentType> components)
    Adds ComponentType.ReadWrite() to the set of prefab components. This indicates the prefab will require a buffer of ObjectRequirementElement at the entity level.

  • public override void GetArchetypeComponents(HashSet<ComponentType> components)
    Empty override. No extra archetype components are added here beyond those declared in GetPrefabComponents.

  • public override void LateInitialize(EntityManager entityManager, Entity entity)
    Called after the entity is created. Behavior:

  • Retrieves the PrefabSystem instance from the world.
  • Gets the DynamicBuffer for the entity.
  • Appends a new ObjectRequirementElement to the buffer referencing the runtime entity for m_Theme (obtained via PrefabSystem.GetEntity(m_Theme)), using the current length as the index and ObjectRequirementType.IgnoreExplicit as the requirement type. This links the instantiated entity with the ThemePrefab at runtime so any systems that process object requirements can find and use the theme.

Notes and implementation details: - Relies on PrefabSystem being present in the same World; PrefabSystem is used to map a PrefabBase (ThemePrefab) to its runtime Entity. - The method assumes the DynamicBuffer exists; GetPrefabComponents ensuring the buffer component is part of the prefab archetype. - ObjectRequirementType.IgnoreExplicit indicates the requirement should ignore explicit assignments and be satisfied from the theme/collection.

Usage Example

// Example: a prefab MonoBehaviour that holds ThemeObject (set in the editor)
public class MyThemedPrefab : PrefabBase
{
    public ThemeObject themeObject; // assign in inspector to link a ThemePrefab

    // During prefab creation you don't need to do anything special:
    // ThemeObject.GetDependencies will add the ThemePrefab to dependency list,
    // and LateInitialize will add the ObjectRequirementElement to the entity buffer.
}

Additional editor usage: - In the prefab inspector, add the ThemeObject component and set m_Theme to a ThemePrefab asset. When the prefab is converted to an entity/prefab, the ThemePrefab will be recorded as a dependency and an object requirement entry will be added at runtime.