Game.Prefabs.VehicleSelectRequirementData
Assembly: Assembly-CSharp
Namespace: Game.Prefabs
Type: struct
Base: System.ValueType
Summary:
Helper data struct used by ECS systems to evaluate whether a vehicle prefab (or candidate entity in a chunk) satisfies selection requirements. It wraps ComponentTypeHandle/BufferTypeHandle/ComponentLookup objects for Locked, ObjectRequirementElement buffers and ThemeData, caches the default theme entity from CityConfigurationSystem, and provides methods to sample chunk data and check per-entity requirements (including lock status and grouped object requirements with theme matching).
Fields
-
internal EnabledMask m_LockedMask
(inside nested Chunk)
Used to check the Enabled/Disabled (Locked) state of entities in an ArchetypeChunk. When a bit for an index is set it indicates the Locked component is enabled for that entity. -
internal BufferAccessor<ObjectRequirementElement> m_ObjectRequirements
(inside nested Chunk)
Accessor to the dynamic buffer of ObjectRequirementElement for each entity in the chunk. Used to read requirement entries per entity. -
private ComponentTypeHandle<Locked> m_LockedType
ComponentTypeHandle for the Locked component (read-only). Initialized in the constructor and updated each frame via Update(system). Used by GetChunk to obtain the enabled mask for Locked. -
private BufferTypeHandle<ObjectRequirementElement> m_ObjectRequirementType
BufferTypeHandle for the ObjectRequirementElement buffer (read-only). Initialized in the constructor and updated each frame via Update(system). Used by GetChunk to obtain the buffer accessor. -
private ComponentLookup<ThemeData> m_ThemeData
ComponentLookup (formerly ComponentDataFromEntity) for ThemeData (read-only). Used during requirement checking when ignoreTheme is true to test whether a theme entity has ThemeData. -
private Entity m_DefaultTheme
Cached default theme Entity supplied by CityConfigurationSystem.defaultTheme. Used when checking object requirements: an ObjectRequirementElement can match the default theme.
Properties
- This struct exposes no public properties.
Constructors
public VehicleSelectRequirementData(SystemBase system)
Initializes internal ComponentTypeHandle/BufferTypeHandle/ComponentLookup in read-only mode and sets the default theme to Entity.Null. Callers should construct this in a SystemBase (e.g., OnCreate) and call Update() each frame before use.
Methods
-
public void Update(SystemBase system, CityConfigurationSystem cityConfigurationSystem)
Updates the ComponentTypeHandle/BufferTypeHandle/ComponentLookup with the current SystemBase context and caches cityConfigurationSystem.defaultTheme into m_DefaultTheme. Must be called each frame (or whenever the system's version changes) before calling GetChunk or CheckRequirements. -
public Chunk GetChunk(ArchetypeChunk chunk)
Creates and returns a Chunk struct populated with the Locked enabled mask and the ObjectRequirement buffer accessor for the provided ArchetypeChunk. Requires that Update(...) has been called so the handles are current. -
public bool CheckRequirements(ref Chunk chunk, int index, bool ignoreTheme = false)
Evaluates whether the entity at the given chunk index meets selection requirements: -
Returns false immediately if the Locked enabled mask is valid and the Locked bit is set for the index.
- If the entity has an ObjectRequirementElement buffer, it iterates the buffer entries grouped by m_Group. For each group, at least one entry must match:
- A match occurs when the requirement's m_Requirement equals the cached default theme entity (m_DefaultTheme), OR
- If ignoreTheme is true and the requirement's m_Requirement entity has a ThemeData component (checked via m_ThemeData.HasComponent), that counts as a match.
- If any group has no matching element, the method returns false.
- If all checks pass, returns true.
Notes: - The method relies on the ordering of ObjectRequirementElement entries to be grouped by m_Group. It uses a sentinel/group-change pattern to determine when a new requirement group starts and ensures at least one entry per group satisfies the match condition. - ignoreTheme modifies semantics so that, instead of only matching the cached default theme entity, any entity that itself has ThemeData is considered a match.
Usage Example
public partial class VehicleSelectionSystem : SystemBase
{
private VehicleSelectRequirementData m_Requirements;
private CityConfigurationSystem m_CityConfig; // assumed to be resolved elsewhere
protected override void OnCreate()
{
base.OnCreate();
m_Requirements = new VehicleSelectRequirementData(this);
}
protected override void OnUpdate()
{
// Ensure handles and default theme are up-to-date
m_Requirements.Update(this, m_CityConfig);
// Example of iterating archetype chunks (pseudo-code)
Entities
.WithName("CheckVehicleRequirements")
.WithAll<SomeVehicleTag>()
.ForEach((ArchetypeChunk chunk, int chunkIndex) =>
{
var c = m_Requirements.GetChunk(chunk);
for (int i = 0; i < chunk.Count; i++)
{
bool allowed = m_Requirements.CheckRequirements(ref c, i, ignoreTheme: false);
if (allowed)
{
// Entity at index i meets selection requirements
}
}
}).ScheduleParallel();
}
}
This struct is intended to be used inside ECS systems that need to determine whether vehicle prefabs/entities are selectable given locks, object requirements and theme rules. Ensure Update(...) is called before GetChunk(...) or CheckRequirements(...).