Game.Prefabs.EventPrefab
Assembly: Assembly-CSharp (game's managed assembly)
Namespace: Game.Prefabs
Type: class
Base: PrefabBase
Summary:
EventPrefab is a prefab definition used by the game's event system. It declares which components an event prefab will provide at prefab-time (EventData) and which runtime event component archetype instances will include (Game.Events.Event). During initialization it collects archetype components from any child ComponentBase instances on the prefab, adds the common Created/Updated tags, builds an ECS archetype and stores it in EventData together with a concurrency limit (m_ConcurrentLimit). This archetype is later used to instantiate event entities at runtime.
Fields
public int m_ConcurrentLimit
Controls how many simultaneous instances of this event are allowed (the concurrency limit). The value is written into the EventData component (m_ConcurrentLimit) when the prefab's archetype is refreshed in LateInitialize/RefreshArchetype.
Properties
- None declared on this type.
Constructors
public EventPrefab()
Default constructor (inherited behavior). No explicit constructor is declared in the source file; standard Unity/MonoBehaviour construction applies and initialization is performed in LateInitialize.
Methods
-
public override void GetPrefabComponents(HashSet<ComponentType> components)
Adds the set of component types that must exist on the prefab entity itself. This override calls the base implementation and adds ComponentType.ReadWrite() so the prefab entity will contain EventData. -
public override void GetArchetypeComponents(HashSet<ComponentType> components)
Adds the component types that will be part of runtime event instances created from this prefab. This override calls the base implementation and adds ComponentType.ReadWrite(). -
public override void LateInitialize(EntityManager entityManager, Entity entity)
Called during prefab initialization. This override calls the base LateInitialize and then calls RefreshArchetype to compute and store the runtime archetype and concurrency limit into EventData for the prefab entity. -
protected virtual void RefreshArchetype(EntityManager entityManager, Entity entity)
Collects ComponentBase-derived components attached to the prefab, queries each for their archetype components, and builds a combined HashSet of ComponentType. It then adds Created and Updated tag components, creates an ECS archetype from the combined component types, and writes an EventData struct to the prefab entity containing: - m_Archetype: the created archetype for runtime instances
- m_ConcurrentLimit: the prefab's m_ConcurrentLimit value
This method is protected and virtual so derived prefabs can extend or modify the collected archetype components before the archetype is created.
Notes and implementation details:
- The method constructs a List
Usage Example
// Example: customizing an EventPrefab in code
public class MyEventPrefab : EventPrefab
{
void Awake()
{
// configure concurrency before initialization if needed (or set in Inspector)
m_ConcurrentLimit = 3;
}
// Optionally override to customize archetype composition
protected override void RefreshArchetype(EntityManager entityManager, Entity entity)
{
// call base to collect components and create the archetype
base.RefreshArchetype(entityManager, entity);
// You can modify the created EventData after base.RefreshArchetype if needed:
var data = entityManager.GetComponentData<EventData>(entity);
// Inspect or adjust data.m_Archetype / data.m_ConcurrentLimit here if required.
entityManager.SetComponentData(entity, data);
}
}
Additional notes: - This prefab class relies on Unity.Entities (ECS) APIs: EntityManager, Entity, ComponentType, and CreateArchetype. - RefreshArchetype should run after all ComponentBase children have been added to the prefab (which is why it's invoked from LateInitialize). - The created archetype is stored in EventData; systems that spawn event instances will use that archetype to create entities matching the prefab's runtime composition.