Game.Companies.TransportCompanyData
Assembly: Assembly-CSharp
Namespace: Game.Companies
Type: struct
Base: IComponentData, IQueryTypeParameter, ISerializable
Summary: TransportCompanyData is a lightweight ECS component that stores the maximum number of transports for a transport company. It is blittable and intended to be attached to entities representing transport companies. The type implements ISerializable so its value is saved/loaded by the game's serialization system and IQueryTypeParameter so it can be used in ECS queries.
Fields
-
public int m_MaxTransports
Holds the maximum allowed transports for the company. Default is 0 when the struct is created with the default constructor. Use this field to control or query the transport capacity for company logic, UI, or balancing code. -
(no other fields)
Properties
- None
Constructors
public TransportCompanyData()
Default parameterless struct constructor (provided by C#). Initializes m_MaxTransports to 0. When creating instances, prefer the object initializer to set a meaningful value, e.g. new TransportCompanyData { m_MaxTransports = 10 }.
Methods
-
public void Serialize<TWriter>(TWriter writer) where TWriter : IWriter
Writes the component state into the provided writer. Currently only writes the single int field m_MaxTransports. Keep serialization order consistent across versions. -
public void Deserialize<TReader>(TReader reader) where TReader : IReader
Reads the component state from the provided reader. Expects the same ordering and types as Serialize (reads an int into m_MaxTransports). When changing the component layout, update these methods to maintain compatibility.
Usage Example
// Create an entity and attach the TransportCompanyData component
var entityManager = Unity.Entities.World.DefaultGameObjectInjectionWorld.EntityManager;
var companyEntity = entityManager.CreateEntity(typeof(Game.Companies.TransportCompanyData));
// Set the maximum transports for this company
entityManager.SetComponentData(companyEntity, new Game.Companies.TransportCompanyData {
m_MaxTransports = 12
});
// Reading the data later
var data = entityManager.GetComponentData<Game.Companies.TransportCompanyData>(companyEntity);
int max = data.m_MaxTransports;
Notes: - Because this is a plain IComponentData struct, it is safe and efficient to use inside Jobs and queries. - If you extend the component with additional fields, update Serialize/Deserialize to preserve save/load compatibility and consider versioning.