Game.Prefabs.TutorialActivationEvent
Assembly: Assembly-CSharp (game)
Namespace: Game.Prefabs
Type: class
Base: ComponentBase
Summary:
Component prefab used to attach one or more Tutorial prefabs to a trigger-like prefab. At prefab initialization it writes one TutorialActivationEventData entry per referenced TutorialPrefab into the entity's DynamicBuffer, resolving the TutorialPrefab references to their corresponding entities via the PrefabSystem. This allows systems to know which tutorials are associated with this activation event when the prefab is instantiated in the ECS world.
Fields
public TutorialPrefab[] m_Tutorials
Array of TutorialPrefab references assigned on the prefab. Each element is resolved to an Entity (via PrefabSystem) and added to the TutorialActivationEventData buffer during LateInitialize.
Properties
- This class does not declare any public properties.
Constructors
public TutorialActivationEvent()
Implicit default constructor (not explicitly declared in the source).
Methods
-
public override void GetArchetypeComponents(HashSet<ComponentType> components)
Intentionally empty in this implementation. The prefab does not add any archetype components through this method. -
public override void GetPrefabComponents(HashSet<ComponentType> components)
AddsTutorialActivationEventData
(ReadWrite) to the prefab components set. This ensures instantiated entities for this prefab will have a DynamicBufferavailable. -
public override void GetDependencies(List<PrefabBase> prefabs)
Adds all referenced TutorialPrefab instances (from m_Tutorials) to the prefab dependency list so those prefabs are ensured to be available/loaded before this prefab. -
public override void LateInitialize(EntityManager entityManager, Entity entity)
Resolves each TutorialPrefab in m_Tutorials to an Entity using the world's PrefabSystem and appends a TutorialActivationEventData entry to the entity's DynamicBufferfor each tutorial. Implementation details: - Obtains the PrefabSystem via
entityManager.World.GetOrCreateSystemManaged<PrefabSystem>()
. - Retrieves the buffer with
entityManager.GetBuffer<TutorialActivationEventData>(entity)
. - For each TutorialPrefab reference, calls
PrefabSystem.GetEntity(prefab)
and addsnew TutorialActivationEventData { m_Tutorial = resolvedEntity }
to the buffer.
Usage Example
// Example: assign TutorialPrefab references on a prefab (e.g. in inspector or via code)
// When the prefab is converted/instantiated, LateInitialize will populate the buffer.
public class ExamplePrefabSetup : ComponentBase
{
public TutorialPrefab[] tutorials;
public override void GetPrefabComponents(HashSet<ComponentType> components)
{
components.Add(ComponentType.ReadWrite<TutorialActivationEventData>());
}
public override void LateInitialize(EntityManager entityManager, Entity entity)
{
var prefabSystem = entityManager.World.GetOrCreateSystemManaged<PrefabSystem>();
var buffer = entityManager.GetBuffer<TutorialActivationEventData>(entity);
if (tutorials != null)
{
for (int i = 0; i < tutorials.Length; i++)
{
buffer.Add(new TutorialActivationEventData
{
m_Tutorial = prefabSystem.GetEntity(tutorials[i])
});
}
}
}
}
Notes and tips: - Ensure referenced TutorialPrefab assets are valid and included in the prefab's dependencies (GetDependencies handles adding them). - The presence of TutorialActivationEventData buffer on the instantiated entity makes it easy for runtime systems to iterate and trigger/tutorial logic when the activation event occurs.