Game.Companies.WorkProvider
Assembly: Assembly-CSharp (game code)
Namespace: Game.Companies
Type: public struct
Base: System.ValueType, implements Unity.Entities.IComponentData, Unity.Entities.IQueryTypeParameter, Colossal.Serialization.Entities.ISerializable
Summary: WorkProvider is a lightweight ECS component used by company/building systems to describe available workforce and notification/cooldown behaviour. It stores the maximum number of worker slots, multiple cooldown timers used for notification throttling, and references to notification entities. It implements custom binary serialization/deserialization to maintain compatibility across game versions.
Fields
-
public int m_MaxWorkers
Stores the number of worker slots the provider exposes (maximum workers). -
public short m_UneducatedCooldown
Cooldown (in game ticks/units) used for uneducated worker-related notifications or processing. Only read/written when the saved data version includes company notifications. -
public short m_EducatedCooldown
Cooldown used for educated worker-related notifications/processing. Also gated by the company notifications version check. -
public Entity m_UneducatedNotificationEntity
Entity reference used to represent or spawn the notification for uneducated worker events. Serialized conditionally depending on version. -
public Entity m_EducatedNotificationEntity
Entity reference used to represent or spawn the notification for educated worker events. Serialized conditionally depending on version. -
public short m_EfficiencyCooldown
Cooldown related to building/company efficiency changes; read/written only if the data version includes the building efficiency rework.
Properties
- None declared in this type. The struct exposes only public fields and explicit serialization methods.
Constructors
public WorkProvider()
Implicit parameterless struct constructor generated by C#. All fields default to 0 / Entity.Null. No explicit custom constructor is defined in the source.
Methods
public void Serialize<TWriter>(TWriter writer) where TWriter : IWriter
Writes the component fields to the provided writer in a fixed order:- m_MaxWorkers
- m_UneducatedCooldown
- m_EducatedCooldown
- m_UneducatedNotificationEntity
- m_EducatedNotificationEntity
-
m_EfficiencyCooldown This method assumes the writer is configured for the game's expected format.
-
public void Deserialize<TReader>(TReader reader) where TReader : IReader
Reads fields from the provided reader with version checks to preserve backward compatibility: - Always reads m_MaxWorkers.
- If reader.context.version >= Version.companyNotifications, reads the two notification cooldowns and the two notification Entity references (m_UneducatedCooldown, m_EducatedCooldown, m_UneducatedNotificationEntity, m_EducatedNotificationEntity).
- If reader.context.version >= Version.buildingEfficiencyRework, reads m_EfficiencyCooldown. The method uses ref locals to read directly into the struct fields. The Version identifiers refer to the game's save/serialization versioning constants (defined elsewhere in the codebase).
Usage Example
// Example: creating and assigning a WorkProvider component to an Entity in a system
var workProvider = new WorkProvider {
m_MaxWorkers = 12,
m_UneducatedCooldown = 300,
m_EducatedCooldown = 200,
m_UneducatedNotificationEntity = Entity.Null, // assign a valid notification entity if used
m_EducatedNotificationEntity = Entity.Null,
m_EfficiencyCooldown = 100
};
// Using an EntityManager to add the component to an entity
EntityManager entityManager = World.DefaultGameObjectInjectionWorld.EntityManager;
Entity companyEntity = entityManager.CreateEntity();
entityManager.AddComponentData(companyEntity, workProvider);
Additional notes: - Serialization relies on Colossal’s reader/writer abstractions; ensure the read/write order and version checks match other code that produces/consumes game saves. - Because this is a struct component for Unity.Entities, use AddComponentData / SetComponentData to modify instances on entities in systems.