Skip to content

Game.Buildings.CrimeProducer

Assembly:
Assembly-CSharp (typical runtime assembly for game code; actual assembly may vary)

Namespace: Game.Buildings

Type: struct CrimeProducer

Base: IComponentData, IQueryTypeParameter, ISerializable

Summary: CrimeProducer is an ECS component (IComponentData) representing a building-level crime producer used by the game's systems. It stores a reference to a patrol request entity, a numeric crime value, and a dispatch index. The struct implements ISerializable to support save/load of its fields and IQueryTypeParameter to be usable as a query parameter in Unity.Entities queries. Serialization is ordered and version-aware: the dispatch index is only deserialized when the saved data version includes the dispatch index field.


Fields

  • public Unity.Entities.Entity m_PatrolRequest Reference to an Entity representing a patrol request associated with this crime producer (e.g., a call for law-enforcement response). Serialized first.

  • public System.Single m_Crime Floating-point value representing the crime amount or severity produced by this building. Serialized second.

  • public System.Byte m_DispatchIndex Byte index used for dispatching/responding logic. Serialized third; when deserializing it is read only if the save data version includes Version.requestDispatchIndex.

Properties

  • None This struct exposes its data as public fields and does not declare managed properties.

Constructors

  • public CrimeProducer() Default value-type constructor is used. Fields will be default-initialized (Entity = Entity.Null, m_Crime = 0f, m_DispatchIndex = 0) unless set explicitly.

Methods

  • public void Serialize<TWriter>(TWriter writer) where TWriter : IWriter Writes the component fields to the provided writer in this order:
  • m_PatrolRequest (Entity)
  • m_Crime (float)
  • m_DispatchIndex (byte) This deterministic order must be preserved for compatibility with Deserialize.

  • public void Deserialize<TReader>(TReader reader) where TReader : IReader Reads fields back from the provided reader in the same order they were written. Important detail: reading of m_DispatchIndex is conditional — it only occurs when reader.context.version >= Version.requestDispatchIndex. This makes deserialization backward-compatible with older save versions that did not include the dispatch index field.

Notes: - The code uses ref locals when reading into fields (reader.Read(out refField)) to assign directly into struct fields. - The Version.requestDispatchIndex symbol is a versioning constant used by the game's serialization system to gate newer fields.

Usage Example

// Example: creating and adding this component to an entity (pseudo-code)
var crime = new Game.Buildings.CrimeProducer {
    m_PatrolRequest = Entity.Null,
    m_Crime = 12.5f,
    m_DispatchIndex = 1
};

entityManager.AddComponentData(someBuildingEntity, crime);

// Example: serialization flow (pseudo)
// writer: an implementation of IWriter provided by the game's serialization system
crime.Serialize(writer);

// Example: deserialization flow (pseudo)
// reader: an implementation of IReader; reader.context.version controls conditional reads
var loadedCrime = new Game.Buildings.CrimeProducer();
loadedCrime.Deserialize(reader);
entityManager.SetComponentData(someBuildingEntity, loadedCrime);

{{ Additional notes: Ensure that when interacting with this component in systems you respect the dispatch index versioning — older saves may not contain the dispatch index, so code that relies on a valid m_DispatchIndex should handle default/absent values gracefully. Because this is a value type (struct) used with Unity.Entities, prefer using EntityManager/System APIs when modifying components at runtime. }}