Game.Prefabs.LeisureProvider
Assembly: Assembly-CSharp.dll
Namespace: Game.Prefabs
Type: class
Base: ComponentBase
Summary:
LeisureProvider is a prefab component used by building prefabs (including building extensions and company prefabs) to provide leisure-related services. It exposes inspector-configurable fields for efficiency, resource type and leisure category, and populates the corresponding ECS component (LeisureProviderData) when the prefab is initialized. It also conditionally adds an archetype component (Game.Buildings.LeisureProvider) when m_Efficiency > 0 so runtime systems can target only active leisure providers.
Fields
-
public int m_Efficiency
Controls how efficient the leisure provider is. Used when creating the LeisureProviderData component and to conditionally add the Game.Buildings.LeisureProvider archetype component when > 0. -
public ResourceInEditor m_Resources
Marked [HideInInspector] for the prefab inspector. Represents the resource produced/consumed by this leisure provider in the editor. Converted to the runtime resource representation via EconomyUtils.GetResource(...) when initializing the ECS component. -
public LeisureType m_LeisureType
Specifies the leisure category/type (enum) provided by this prefab. Stored in the LeisureProviderData component for use by game systems and agents.
Properties
- (None declared in this class)
Constructors
public LeisureProvider()
Implicit default constructor. Typical usage is to configure public fields in the prefab inspector rather than constructing instances at runtime.
Methods
public override void GetPrefabComponents(HashSet<ComponentType> components)
Adds the ECS component types that should always be present on entities created from this prefab. Implementation adds:-
ComponentType.ReadWrite<LeisureProviderData>()
-
public override void GetArchetypeComponents(HashSet<ComponentType> components)
Adds optional archetype component types conditionally based on prefab settings. Ifm_Efficiency > 0
, this method adds: -
ComponentType.ReadWrite<Game.Buildings.LeisureProvider>()
This conditional addition allows systems to filter entities that actively provide leisure. -
public override void Initialize(EntityManager entityManager, Entity entity)
Populates the entity'sLeisureProviderData
component using the prefab's inspector values: - Sets
m_Efficiency
from the prefab field. - Converts
m_Resources
usingEconomyUtils.GetResource(...)
and assigns to the component. - Sets
m_LeisureType
from the prefab field.
This ensures the ECS entity has runtime data matching the prefab configuration.
Usage Example
// This mirrors the class behavior: when the prefab is instantiated the ECS data is set.
public override void Initialize(EntityManager entityManager, Entity entity)
{
base.Initialize(entityManager, entity);
entityManager.SetComponentData(entity, new LeisureProviderData
{
m_Efficiency = m_Efficiency,
m_Resources = EconomyUtils.GetResource(m_Resources),
m_LeisureType = m_LeisureType
});
}
Additional notes: - LeisureProviderData is the ECS component that systems and agents read at runtime. Ensure its fields match what your systems expect. - EconomyUtils.GetResource converts the editor-facing ResourceInEditor to the runtime resource identifier/structure. - If you want systems to treat a prefab as an active leisure provider, set m_Efficiency > 0 so the archetype component Game.Buildings.LeisureProvider is included.