Game.Companies.StorageLimitData
Assembly: Game
Namespace: Game.Companies
Type: public struct
Base: Implements IComponentData, IQueryTypeParameter, ISerializable, ICombineData
Summary: StorageLimitData is a small ECS component/serializable struct that stores a base storage limit multiplier (m_Limit). It provides utilities to compute an adjusted storage capacity for warehouse-like buildings by taking into account the spawnable building's level and the building lot area. It also supports serialization/deserialization and combination (aggregation) of limits when multiple sources are merged.
Fields
public int m_Limit
Holds the base storage limit multiplier. This value is used in calculations (see GetAdjustedLimitForWarehouse). It is serialized/deserialized by the ISerializable implementation and can be combined with other StorageLimitData instances using Combine.
Properties
- This type defines no properties.
Constructors
- Default parameterless struct constructor (public).
As a struct, StorageLimitData is value-type initialized with m_Limit == 0 by default. You can initialize it inline, e.g.new StorageLimitData { m_Limit = 5 }
.
Methods
public int GetAdjustedLimitForWarehouse(SpawnableBuildingData spawnable, BuildingData building)
Calculates and returns the effective storage limit for a warehouse-like building using the formula: m_Limit * spawnable.m_Level * building.m_LotSize.x * building.m_LotSize.y.public void Serialize<TWriter>(TWriter writer) where TWriter : IWriter
Writes m_Limit to the provided writer. Used by the game's serialization system to persist this component.public void Deserialize<TReader>(TReader reader) where TReader : IReader
Reads m_Limit from the provided reader during deserialization.public void Combine(StorageLimitData otherData)
Adds otherData.m_Limit to this.m_Limit. Useful when aggregating multiple StorageLimitData instances (for example when combining data from multiple sources/entities).
Implements:
- IComponentData: allows the struct to be used as an ECS component.
- IQueryTypeParameter: usable in query-type parameter contexts (game-specific ECS query helpers).
- ISerializable: enables custom binary serialization/deserialization via the provided writer/reader interfaces.
- ICombineData
Usage Example
// Simple usage examples:
// 1) Creating and using the struct directly:
var storage = new StorageLimitData { m_Limit = 10 };
// Assume these are available from game data:
SpawnableBuildingData spawnable = new SpawnableBuildingData { m_Level = 2 };
BuildingData building = new BuildingData { m_LotSize = new Unity.Mathematics.int2(3, 4) };
// Compute adjusted limit:
int adjusted = storage.GetAdjustedLimitForWarehouse(spawnable, building);
// adjusted == 10 * 2 * 3 * 4 == 240
// 2) Adding as an ECS component (EntityManager example):
var em = Unity.Entities.World.DefaultGameObjectInjectionWorld.EntityManager;
var entity = em.CreateEntity();
em.AddComponentData(entity, new StorageLimitData { m_Limit = 5 });
// 3) Combining two StorageLimitData instances:
var a = new StorageLimitData { m_Limit = 7 };
var b = new StorageLimitData { m_Limit = 3 };
a.Combine(b); // a.m_Limit == 10
// 4) Serialization / Deserialization (pseudocode - depends on game's writer/reader impl):
// writer.Write and reader.Read are provided by the game's serialization system.