Game.Prefabs.ServiceBudget
Assembly: Assembly-CSharp
Namespace: Game.Prefabs
Type: struct ServiceBudget
Base: IComponentData, IQueryTypeParameter, ISerializable
Summary:
ServiceBudget is a lightweight Unity ECS component that stores an integer budget value for a service. It implements ISerializable so it can be read/written by the game's serialization system (used for saving/loading prefabs or entity data) and IQueryTypeParameter so it can be used in ECS queries. The integer typically represents a budget level (for example, a percentage or discrete budget tier), but the exact interpretation depends on the consuming systems.
Fields
public int m_Budget
Stores the budget value for the service. Default value is 0 when the struct is default-constructed. The valid range/meaning is determined by systems that read this component (commonly treated as a percentage or level).
Properties
- This type defines no C# properties; it exposes a single public field (m_Budget).
Constructors
public ServiceBudget()
The struct uses the implicit default constructor. When created without initialization, m_Budget is 0. You can initialize explicitly via object initializer:new ServiceBudget { m_Budget = 75 }
.
Methods
-
public void Deserialize<TReader>(TReader reader) where TReader : IReader
Reads the m_Budget value from the provided reader. Used by the game's serialization/deserialization pipeline to restore component state. -
public void Serialize<TWriter>(TWriter writer) where TWriter : IWriter
Writes the m_Budget value to the provided writer. Used by the game's serialization pipeline when saving prefabs or entity state.
Usage Example
// Adding the component to an entity with a budget of 75
var budgetComponent = new Game.Prefabs.ServiceBudget { m_Budget = 75 };
entityManager.AddComponentData(entity, budgetComponent);
// Reading the budget back
var readBudget = entityManager.GetComponentData<Game.Prefabs.ServiceBudget>(entity);
int budgetValue = readBudget.m_Budget;
// Serialization is handled by the game's IReader/IWriter implementations:
// Example pseudo-usage inside a serializer (game provides concrete reader/writer):
[Preserve]
public void SaveComponent<TWriter>(ref Game.Prefabs.ServiceBudget comp, TWriter writer) where TWriter : IWriter
{
comp.Serialize(writer);
}
{{ Additional notes: - This struct is intended to be small and blittable for efficient use with Unity's ECS. - Because it uses a public field rather than properties, it is simple to serialize and copy between native/managed contexts. - When designing systems that consume this component, validate or clamp m_Budget as needed to the expected range for your game logic. }}