Skip to content

Game.Prefabs.ContentPrefab

Assembly: Assembly-CSharp (game runtime assembly; the class is compiled into the game's managed assembly)
Namespace: Game.Prefabs

Type: class

Base: PrefabBase

Summary:
ContentPrefab is a prefab type used to represent "content" prefabs (content that can require DLC or a Paradox login). It participates in the prefab → ECS entity conversion by ensuring the entity has a ContentData component and by marking ContentData flags based on declared content requirements (for example DlcRequirement or PdxLoginRequirement). It also exposes an availability check that queries any ContentRequirementBase components attached to this prefab and returns false if any requirement is not satisfied. This class relies on behavior implemented in the PrefabBase class (such as the components collection and helper methods like TryGet() / Has()).


Fields

  • No private fields declared in this type.
    This class uses inherited state from PrefabBase (for example a collection named components and helper methods) but declares no new fields of its own.

Properties

  • No public or private properties declared in this type.
    The prefab interacts with ECS data through methods rather than exposing additional properties; relevant state is stored on the resulting entity's ContentData component.

Constructors

  • public ContentPrefab()
    This class does not declare an explicit constructor; a default public parameterless constructor is provided by the C# compiler. Construction and initialization of prefab instances is normally handled by the game's prefab system.

Methods

  • public bool IsAvailable()
    Checks the prefab's attached components for any ContentRequirementBase instances and calls CheckRequirement() on each. If any requirement check returns false, IsAvailable returns false; otherwise it returns true. Use this to determine whether the content represented by this prefab can be used/instantiated given the current environment (DLC presence, account login, etc.).

Notes: - Iterates the inherited components collection (each element is a ComponentBase). - Recognizes components that implement ContentRequirementBase and calls their CheckRequirement() method. - Example requirement types (seen in code) include DlcRequirement and PdxLoginRequirement.

  • public override void GetPrefabComponents(HashSet<ComponentType> components)
    Augments the set of ComponentType entries required by the prefab's entity archetype. This override first calls the base implementation and then ensures the entity has a ContentData component by adding ComponentType.ReadWrite<ContentData>() to the provided set.

Purpose: - Ensures that when the prefab is converted to an ECS entity, the entity's archetype will include ContentData so that Initialize can operate on it.

  • public override void Initialize(EntityManager entityManager, Entity entity)
    Called during prefab → entity initialization. This override:
  • Calls the base.Initialize(entityManager, entity).
  • Reads the existing ContentData from the entity.
  • If the prefab has a DlcRequirement component (via TryGet), it sets the ContentFlags.RequireDlc flag and writes the DLC id into componentData.m_DlcID.
  • If the prefab has a PdxLoginRequirement (checked via Has()), it sets the ContentFlags.RequirePdxLogin flag.
  • Writes the modified ContentData back to the entity via entityManager.SetComponentData.

Notes and implications: - Assumes the entity already has a ContentData component (GetPrefabComponents added it earlier). - The code uses bitwise flags on ContentData.m_Flags (the ContentFlags enum) to indicate availability conditions. - The DlcRequirement component provides a reference to a DLC object with an id used to populate m_DlcID.

Usage Example

// Example (conceptual) usage inside prefab processing or mod initialization:

// Assume prefab is an instance of ContentPrefab loaded by the prefab manager.
ContentPrefab prefab = /* get prefab instance */;

// 1) Check whether content should be available/instantiable on this machine/account
if (!prefab.IsAvailable())
{
    // Skip creating or presenting this content (e.g., hide it in UI)
    return;
}

// 2) When converting the prefab into an ECS entity, ensure ContentData is part of the archetype
//    (GetPrefabComponents will be called by the prefab system; shown here for illustration)

// 3) Initialize the created entity so the ContentData flags get set according to requirements
EntityManager entityManager = /* obtain EntityManager */;
Entity entity = /* entity created for this prefab, with ContentData component present */;
prefab.Initialize(entityManager, entity);

// After Initialize, entity's ContentData will have flags such as RequireDlc or RequirePdxLogin and
// m_DlcID set if a DlcRequirement was present.

Additional notes: - ContentPrefab delegates actual requirement checks to components derived from ContentRequirementBase. To extend or customize availability logic for new content types, implement a new requirement component deriving from ContentRequirementBase and attach it to the prefab. - Be careful to ensure the entity archetype includes ContentData before calling Initialize; the prefab system normally enforces this via GetPrefabComponents.