Skip to content

Game.Prefabs.ServiceCompany

Assembly: Assembly-CSharp
Namespace: Game.Prefabs

Type: class

Base: ComponentBase

Summary:
Represents a prefab component that describes a service company in the game. This component exposes editable prefab fields (maximum service, workers per cell and service consumption) and, during prefab-to-entity initialization, writes a ServiceCompanyData component to the entity and ensures the archetype contains ServiceAvailable. Intended for use with the game's ECS conversion flow for company / service systems. Depends on the ECS component types ServiceCompanyData and ServiceAvailable (defined elsewhere).


Fields

  • public int m_MaxService
    Maximum amount of service this company can provide (configured on the prefab).

  • public float m_MaxWorkersPerCell
    Maximum number of workers per grid cell allowed for this company (configured on the prefab).

  • public int m_ServiceConsuming = 1
    The amount of service consumed per leisure tick. Has a Tooltip attribute reading "The service consumed per leisure tick". Default value is 1.

Properties

  • None (this component exposes only public fields and overrides methods; no public properties are declared).

Constructors

  • public ServiceCompany()
    Default parameterless constructor. Field initializers set m_ServiceConsuming = 1; otherwise fields use their default values.

Methods

  • public override void GetPrefabComponents(HashSet<ComponentType> components)
    Adds runtime ECS components required on the prefab's converted entity. Specifically, it adds ComponentType.ReadWrite<ServiceCompanyData>(), indicating the entity should have a writable ServiceCompanyData component populated during initialization.

  • public override void GetArchetypeComponents(HashSet<ComponentType> components)
    Adds archetype-level components required for entities of this prefab. Specifically, it adds ComponentType.ReadWrite<ServiceAvailable>(), ensuring the entity archetype includes the ServiceAvailable component.

  • public override void Initialize(EntityManager entityManager, Entity entity)
    Called during prefab conversion to entities. Writes a ServiceCompanyData instance to the provided entity using EntityManager.SetComponentData, copying values from the prefab fields:

  • m_MaxService -> ServiceCompanyData.m_MaxService
  • sets ServiceCompanyData.m_WorkPerUnit = 0
  • m_MaxWorkersPerCell -> ServiceCompanyData.m_MaxWorkersPerCell
  • m_ServiceConsuming -> ServiceCompanyData.m_ServiceConsuming

Use this method to ensure the entity has the expected component state coming out of conversion.

Usage Example

// Example: configuring the prefab fields in code, then converting/initializing the entity.
ServiceCompany prefabComp = /* obtain reference to prefab component */;
prefabComp.m_MaxService = 200;
prefabComp.m_MaxWorkersPerCell = 2.5f;
prefabComp.m_ServiceConsuming = 1;

// During conversion the engine will call:
EntityManager em = World.DefaultGameObjectInjectionWorld.EntityManager;
Entity archetypeEntity = em.CreateEntity(); // typically handled by the conversion system
prefabComp.Initialize(em, archetypeEntity);

// After Initialize, the entity has a ServiceCompanyData component with the values copied from the prefab.

Notes: - This component is intended to be attached to Unity prefab authoring objects. The game's conversion system or custom conversion code should call GetPrefabComponents/GetArchetypeComponents and Initialize to create the proper ECS components. - ServiceCompanyData and ServiceAvailable must be present in the project (their definitions are not included here).