Game.Prefabs.CitizenRequirementData
Assembly:
Game
Namespace:
Game.Prefabs
Type:
struct
Base:
System.ValueType, Unity.Entities.IComponentData, Unity.Entities.IQueryTypeParameter
Summary:
A plain ECS component that describes minimum requirements for a citizen-related prefab. It stores integer thresholds used by spawning/availability systems to determine whether a prefab is eligible (for example, a building or service that needs a minimum population or minimum happiness to appear/activate). Being a struct implementing IComponentData, it is a blittable data container suitable for use in jobs and queries.
Fields
-
public int m_MinimumPopulation
Minimum required population for the prefab to be considered available/valid. Typical use: compare current city population against this value. Default value is 0 when the struct is default-constructed. -
public int m_MinimumHappiness
Minimum required happiness value for the prefab to be considered available/valid. Typically expressed on the same scale the game uses for happiness (commonly 0–100); default is 0.
Properties
- None.
This type exposes only public fields and does not declare properties.
Constructors
public CitizenRequirementData()
Implicit parameterless/default constructor provided by C# for structs. You can also construct with an object initializer: new CitizenRequirementData { m_MinimumPopulation = 100, m_MinimumHappiness = 75 };
Methods
- None.
This component contains only data. Any logic that interprets these values should live in systems or jobs that read this component.
Usage Example
// Add the component to an entity (EntityManager example)
var requirements = new CitizenRequirementData {
m_MinimumPopulation = 500,
m_MinimumHappiness = 60
};
entityManager.AddComponentData(prefabEntity, requirements);
// Read in a SystemBase using Entities.ForEach
public partial class PrefabAvailabilitySystem : SystemBase
{
protected override void OnUpdate()
{
int currentPopulation = /* obtain from game state */;
int currentHappiness = /* obtain from game state */;
Entities
.WithAll<SomePrefabTag>()
.ForEach((Entity e, in CitizenRequirementData req) =>
{
bool isAvailable = currentPopulation >= req.m_MinimumPopulation &&
currentHappiness >= req.m_MinimumHappiness;
// handle availability (enable/disable prefab, set flags, etc.)
}).Run();
}
}
// Or read via EntityManager
var reqData = entityManager.GetComponentData<CitizenRequirementData>(prefabEntity);
if (gamePopulation >= reqData.m_MinimumPopulation && gameHappiness >= reqData.m_MinimumHappiness)
{
// allow spawning or mark as unlocked
}