Game.Prefabs.StorageLimit
Assembly:
Namespace: Game.Prefabs
Type: class
Base: ComponentBase
Summary:
Component placed on prefabs (buildings, building extensions and marker objects) to provide a storage capacity limit when the prefab is converted into an entity. The class registers and initializes a StorageLimitData component on the created Entity with the configured limit value. The ComponentMenu attribute restricts this component to BuildingPrefab, BuildingExtensionPrefab and MarkerObjectPrefab prefab types.
Fields
public System.Int32 storageLimit
Numeric limit that will be written into the StorageLimitData.m_Limit field when the prefab is instantiated as an Entity. Set this in the prefab (inspector) or via code to control the storage capacity for the created entity.
Properties
- This type does not declare any properties.
Constructors
public StorageLimit()
Default constructor (implicit). No special runtime construction logic beyond the base ComponentBase initialization.
Methods
-
public override void GetPrefabComponents(System.Collections.Generic.HashSet<Unity.Entities.ComponentType> components)
Adds the required component type(s) to the set used when collecting components that should be added to the entity when the prefab is converted. This implementation adds ComponentType.ReadWrite(). -
public override void GetArchetypeComponents(System.Collections.Generic.HashSet<Unity.Entities.ComponentType> components)
No archetype components are added by this component. Method is intentionally empty in this class. -
public override void Initialize(Unity.Entities.EntityManager entityManager, Unity.Entities.Entity entity)
Called when the prefab is converted into an Entity. Writes a StorageLimitData instance to the entity using the configured storageLimit: entityManager.SetComponentData(entity, new StorageLimitData { m_Limit = storageLimit });
Usage Example
// Typical pattern: set storageLimit on the prefab in the editor or via code.
// When the prefab is instantiated and converted to an Entity, Initialize(...) will run
// and write the value into StorageLimitData.m_Limit.
[ComponentMenu("Buildings/")]
public class ExampleBuildingPrefab : BuildingPrefab
{
// In the inspector this component can be added and configured.
public StorageLimit storageLimitComponent;
void Awake()
{
// Ensure it's set (if you want to set via script)
if (storageLimitComponent != null)
storageLimitComponent.storageLimit = 200;
}
// Example of manual initialization (normally done by the prefab conversion system)
public void ApplyToEntity(EntityManager em, Entity e)
{
storageLimitComponent?.Initialize(em, e);
// After this, the entity will have StorageLimitData.m_Limit == 200
}
}
// Alternatively, directly set the component data on the entity:
entityManager.SetComponentData(entity, new StorageLimitData { m_Limit = 200 });