Game.City.MilestoneReachedEvent
Assembly: Assembly-CSharp (game code)
Namespace: Game.City
Type: struct
Base: Unity.Entities.IComponentData, Unity.Entities.IQueryTypeParameter
Summary: A small ECS component used to represent that a milestone has been reached. Contains a reference to the milestone entity and an integer index describing which milestone stage or slot was reached. Because it implements IComponentData it can be added to entities, and because it implements IQueryTypeParameter it is intended to be used directly in EntityQuery/ForEach-style queries as an event-like component that systems can react to and then clear.
Fields
-
public Unity.Entities.Entity m_Milestone
This is an Entity reference pointing to the milestone definition or instance that was reached. Consumers typically use this to look up milestone data or to correlate the event with other milestone-related entities. -
public System.Int32 m_Index
An integer describing the milestone index or stage. The exact meaning is game-specific (e.g., milestone level, progression step, or an index into a milestone list).
Properties
- None
Constructors
public MilestoneReachedEvent(Unity.Entities.Entity milestone, System.Int32 index)
Creates a new event instance containing the milestone entity and the associated index.
Parameters: - milestone — Entity that identifies the milestone reached. - index — Numeric index indicating which milestone stage/slot was reached.
Methods
- None (plain data container)
Usage Example
// Example: raising the event by adding the component to an event entity
void RaiseMilestoneEvent(EntityManager em, Entity milestoneEntity, int index)
{
var ev = new Game.City.MilestoneReachedEvent(milestoneEntity, index);
var eventEntity = em.CreateEntity(typeof(Game.City.MilestoneReachedEvent));
em.SetComponentData(eventEntity, ev);
}
// Example: handling the event inside a SystemBase and removing it after processing
public partial class MilestoneEventSystem : SystemBase
{
protected override void OnUpdate()
{
var ecb = new Unity.Collections.NativeList<Entity>(Allocator.Temp);
Entities
.WithAll<Game.City.MilestoneReachedEvent>()
.ForEach((Entity entity, in Game.City.MilestoneReachedEvent ev) =>
{
// Handle the milestone event:
// - ev.m_Milestone: the milestone entity
// - ev.m_Index: which milestone index was reached
UnityEngine.Debug.Log($"Milestone reached: entity={ev.m_Milestone} index={ev.m_Index}");
// mark event entity for removal after iteration
ecb.Add(entity);
})
.WithoutBurst()
.Run();
// Remove processed event entities
var em = World.DefaultGameObjectInjectionWorld.EntityManager;
foreach (var e in ecb)
em.DestroyEntity(e);
ecb.Dispose();
}
}
Notes: - Treat this struct as an ephemeral "event" component: add it when the milestone is reached, have a system read and react to it, then remove or destroy the entity holding the component to avoid repeated processing. - Because it implements IQueryTypeParameter, it is convenient to use directly in query/ForEach patterns.