Game.Companies.ResourceBuyer
Assembly:
Assembly-CSharp (typical for Cities: Skylines 2 mods; actual assembly may vary)
Namespace: Game.Companies
Type: struct ResourceBuyer
Base: System.ValueType
Summary: A DOTS component (IComponentData) representing an entity that requests/buys a specific economy resource. Used by company/AI systems to record who will pay, what resource and how much is required, and where the demand is located. Implements ISerializable so it can be written to/read from save data and IQueryTypeParameter for ECS query usage.
Fields
-
public Unity.Entities.Entity m_Payer
Represents the Entity that will pay for the resource. Serialized/deserialized as an Entity; callers should be aware of entity remapping when loading/saving across contexts. -
public SetupTargetFlags m_Flags
Flags describing setup/target options for the resource request. Serialized as a byte; cast back to SetupTargetFlags during deserialization. -
public Game.Economy.Resource m_ResourceNeeded
The resource type being requested. During serialization this is stored as a signed byte index (EconomyUtils.GetResourceIndex) and restored via EconomyUtils.GetResource(sbyte). -
public int m_AmountNeeded
The quantity of the resource required. -
public Unity.Mathematics.float3 m_Location
World position associated with the resource demand (float3). Serialized directly.
Properties
- None (no explicit properties defined)
Constructors
public ResourceBuyer()
Default value-type constructor (compiler-provided). All fields will contain default values until explicitly set.
Methods
public void Serialize<TWriter>(TWriter writer) where TWriter : IWriter
Serializes fields in this order:- m_Payer written as Entity
- m_Flags written as a single byte
- m_ResourceNeeded written as sbyte via EconomyUtils.GetResourceIndex(...)
- m_AmountNeeded written as int
-
m_Location written as float3 TWriter must implement IWriter. Note: resource index is stored in an sbyte — ensure the resource index range fits sbyte.
-
public void Deserialize<TReader>(TReader reader) where TReader : IReader
Deserializes fields in the same order they were written. Reads payer, flags (byte), resource index (sbyte), amountNeeded (int), and location (float3). Reconstructs: - m_Flags = (SetupTargetFlags)value;
- m_ResourceNeeded = EconomyUtils.GetResource(value2); Uses ref locals to populate fields.
Usage Example
// Create and initialize a ResourceBuyer component and add it to an entity.
var buyer = new ResourceBuyer
{
m_Payer = payerEntity,
m_Flags = SetupTargetFlags.None,
m_ResourceNeeded = EconomyUtils.GetResource(0), // or a specific Resource value
m_AmountNeeded = 50,
m_Location = new float3(100f, 0f, 200f)
};
// Add to an entity via EntityManager (DOTS)
entityManager.AddComponentData(targetEntity, buyer);
// The system handling company resource requests will read this component and process the purchase.
Additional notes: - The component is small and POD-style to be efficient in ECS; prefer modifying whole struct instances rather than individual boxed operations. - When saving/loading game data, Entity values must be remapped to the current session's entity IDs — IWriter/IReader implementations typically handle entity remapping. - EconomyUtils is used for mapping between Resource and a compact index; ensure custom resources (if any) are compatible with the index range (sbyte).