Game.City.ServiceImportBudget
Assembly: Assembly-CSharp
Namespace: Game.City
Type: struct
Base: IBufferElementData, ISerializable
Summary:
ServiceImportBudget is a small ECS buffer element that represents an import budget for a specific player resource (e.g. electricity, water, goods). It is serializable via Colossal.Serialization and intended to be stored in a DynamicBuffer
Fields
-
public PlayerResource m_Resource
Represents the type of player resource this budget applies to. PlayerResource is expected to be an enum (e.g. Electricity, Water, Goods, etc.). The value is serialized as an int. -
public int m_MaximumBudget
Maximum allowed import budget for the specified resource. Stored and serialized as a plain 32-bit integer.
Properties
- This type defines no managed properties. It is a plain struct with public fields and implements the serialization methods required by ISerializable.
Constructors
- No explicit constructors are defined. The struct uses the default parameterless constructor provided by C# (fields default to their default values).
Methods
-
public void Serialize<TWriter>(TWriter writer) where TWriter : IWriter
Writes the struct state to the provided writer. It writes the m_Resource value as an int (casting the enum) followed by the m_MaximumBudget integer. This is used by Colossal.Serialization to persist or transmit the buffer element. -
public void Deserialize<TReader>(TReader reader) where TReader : IReader
Reads the struct state from the provided reader. It reads an int and casts it to PlayerResource for m_Resource, then reads the m_MaximumBudget value. This restores the struct state when loading or receiving serialized data.
Usage Example
// Add or get a DynamicBuffer<ServiceImportBudget> on an entity
var buffer = entityManager.AddBuffer<ServiceImportBudget>(entity);
// Add a budget for electricity (assuming PlayerResource.Electricity exists)
buffer.Add(new ServiceImportBudget {
m_Resource = PlayerResource.Electricity,
m_MaximumBudget = 10000
});
// Later, iterate the buffer to apply/import budgets
foreach (var budget in buffer)
{
// budget.m_Resource and budget.m_MaximumBudget are available here
ApplyImportBudget(budget.m_Resource, budget.m_MaximumBudget);
}
// Serialization is handled by Colossal.Serialization by calling Serialize/Deserialize.
// No additional code is required for the ISerializable contract beyond implementing the methods.
Notes:
- Because this is an IBufferElementData, it is intended to be stored in Unity.Entities.DynamicBuffer