Game.Companies.BuyingCompany
Assembly:
Namespace: Game.Companies
Type: struct
Base: IComponentData, IQueryTypeParameter, ISerializable
Summary:
Represents a simple ECS component used to store buying-related data for a company in Cities: Skylines 2. It stores a reference to the last trade partner (Entity) and a floating-point mean input trip length. The struct implements Colossal.Serialization.Entities.ISerializable to allow its data to be written to and read from game save/state streams.
Fields
-
public Unity.Entities.Entity m_LastTradePartner
Stores an Entity reference to the last company (or other entity) that this company traded with. This is used to track recent trade counterparties for logic that needs to reference the most recent partner. -
public System.Single m_MeanInputTripLength
A floating-point value representing the mean length of input trips (e.g., average travel distance/time for incoming goods or resources). Used by company logic to maintain statistics related to supply/inputs.
Properties
- This type has no properties. The data is exposed directly via the public fields above.
Constructors
public BuyingCompany()
No explicit constructors are defined in the source: the struct uses the default parameterless constructor provided by C#. When added to an entity, initialize fields as needed (for example set m_LastTradePartner = Entity.Null and m_MeanInputTripLength = 0f).
Methods
-
public void Serialize<TWriter>(TWriter writer) where TWriter : IWriter
Writes the component's state to the provided writer. The method writes m_LastTradePartner followed by m_MeanInputTripLength in that order. Used during saving/serialization of entity data. -
public void Deserialize<TReader>(TReader reader) where TReader : IReader
Reads the component's state from the provided reader. The method reads into m_LastTradePartner and m_MeanInputTripLength in the same order they were written. Used during load/deserialization of entity data.
Remarks: These methods implement the ISerializable pattern from Colossal.Serialization.Entities. They directly read/write the underlying fields and rely on the caller's reader/writer to handle Entity references correctly (mapping across save/load where necessary).
Usage Example
// Example: creating an entity and attaching a BuyingCompany component,
// then initializing its fields.
using Unity.Entities;
using Game.Companies;
public class CompanyBootstrap
{
public void CreateCompany(EntityManager entityManager)
{
// Create an entity with the BuyingCompany component type
EntityArchetype archetype = entityManager.CreateArchetype(typeof(BuyingCompany));
Entity companyEntity = entityManager.CreateEntity(archetype);
// Initialize component data
BuyingCompany buying = new BuyingCompany
{
m_LastTradePartner = Entity.Null, // no partner yet
m_MeanInputTripLength = 0f
};
// Assign to the entity
entityManager.SetComponentData(companyEntity, buying);
}
}
// Serialization/deserialization are handled by the game's save/load subsystems
// which invoke Serialize<TWriter>/Deserialize<TReader> via the ISerializable contract.