Skip to content

Game.Prefabs.ContentRequirementBase

Assembly:
Assembly-CSharp (game assembly)

Namespace:
Game.Prefabs

Type:
public abstract class

Base:
ComponentBase

Summary:
Base class for prefab content requirement checks used by the game's prefab system. Provides a place to store editor notes and two overridable methods to supply required ECS ComponentType entries for prefab and archetype creation. Concrete implementations must implement CheckRequirement to indicate whether the requirement is satisfied (for example, checking for presence of certain content, DLC, or mod data).


Fields

  • public string m_Notes
    [TextArea] attribute; used as an editable multi-line note in the inspector/editor to document the requirement or provide author notes for this requirement instance.

Properties

  • (none)

Constructors

  • public ContentRequirementBase()
    Implicit parameterless constructor. No special initialization is performed by this base class.

Methods

  • public override void GetPrefabComponents(HashSet<ComponentType> components)
    Called to collect ComponentType entries required for the prefab. Default implementation is empty — override in subclasses to add any ECS component types that must be present on prefabs that rely on this requirement.

  • public override void GetArchetypeComponents(HashSet<ComponentType> components)
    Called to collect ComponentType entries required for the archetype. Default implementation is empty — override in subclasses to add any ECS component types that must be present on archetypes that rely on this requirement.

  • public abstract bool CheckRequirement()
    Must be implemented by subclasses. Return true if the requirement is satisfied (e.g., the needed content is available), false otherwise. This is used by the prefab/content-loading logic to decide whether the prefab should be allowed/instanced or flagged as missing/invalid.

Usage Example

using System.Collections.Generic;
using Unity.Entities;
using Game.Prefabs;

public class MyContentRequirement : ContentRequirementBase
{
    // Optional: editor note visible in inspector
    // public string m_Notes = "Requires My Custom Asset/DLC";

    public override void GetPrefabComponents(HashSet<ComponentType> components)
    {
        // Example: declare that prefabs requiring this also require a specific ECS component
        // components.Add(ComponentType.ReadOnly<MyCustomComponent>());
    }

    public override void GetArchetypeComponents(HashSet<ComponentType> components)
    {
        // Example: declare components needed on the archetype level
        // components.Add(ComponentType.ReadWrite<MyCustomState>());
    }

    public override bool CheckRequirement()
    {
        // Implement actual check here, e.g.:
        // - verify a content package is installed
        // - check for presence of a specific asset by name or GUID
        // - verify a mod setting or external dependency
        //
        // Return true if available, false if missing.
        return true;
    }
}

{{ Additional notes: - GetPrefabComponents and GetArchetypeComponents are intended to inform the ECS/prefab builder which ComponentTypes to include so entities created from the prefab/archetype have the expected components. - Because the base implementations are empty, subclasses should call no base method (there's nothing to preserve) unless future game updates add behavior. - m_Notes uses Unity's TextArea attribute to make multiline text convenient in the inspector/editor. - This class is abstract; it will typically be used as a scriptable requirement attached to prefab definition assets so the game's content validation can accept or reject prefabs at load/instantiation time. }}