Game.Prefabs.TutorialAlternative
Assembly: Game (inferred)
Namespace: Game.Prefabs
Type: class
Base: ComponentBase
Summary:
A prefab component used by the tutorial system to declare alternative tutorial prefabs. When one of the listed alternatives is already completed, this tutorial can be treated as skipped in tutorial lists. The component stores references to alternative TutorialPrefab instances and, at LateInitialize, converts those references into runtime entity references (Game.Tutorials.TutorialAlternative buffer entries) so the ECS/tutorial systems can check/consume them.
Fields
public TutorialPrefab[] m_Alternatives
Tooltip: "If one of the alternatives is completed, this is skipped in tutorial list."
[NotNull] — expected to be set in the prefab/inspector.
This array holds references to other TutorialPrefab assets that serve as alternatives. During LateInitialize each entry is converted to an entity reference and added to the entity's DynamicBuffer. If left null or empty, no alternatives are registered.
Properties
- None.
This component exposes no runtime properties; it only exposes the m_Alternatives field in the prefab.
Constructors
public TutorialAlternative()
Default parameterless constructor (no custom initialization performed in code).
Methods
-
public override void GetArchetypeComponents(HashSet<ComponentType> components)
This override intentionally does nothing in the current implementation (no archetype components are added here). -
public override void GetPrefabComponents(HashSet<ComponentType> components)
Adds the ECS component type required by this prefab at spawn time: components.Add(ComponentType.ReadWrite());
This ensures the entity backing the prefab contains a DynamicBufferso alternative references can be stored. -
public override void GetDependencies(List<PrefabBase> prefabs)
Calls base.GetDependencies(prefabs) and then adds each TutorialPrefab referenced in m_Alternatives to the provided prefabs list. This makes sure those prefabs are considered dependencies and loaded before/with this prefab. -
public override void LateInitialize(EntityManager entityManager, Entity entity)
Performs runtime initialization after the entity is created: - Calls base.LateInitialize(entityManager, entity).
- Retrieves (or creates) the PrefabSystem from entityManager.World.
- Gets the DynamicBuffer
on the entity. - Iterates m_Alternatives and for each TutorialPrefab adds a Game.Tutorials.TutorialAlternative entry to the buffer with m_Alternative set to the entity returned by PrefabSystem.GetEntity(tutorialPrefab).
This converts inspector-assigned TutorialPrefab references into ECS entity references that the tutorial systems can use at runtime. Be sure m_Alternatives is populated; otherwise no buffer entries are added.
Usage Example
// Typical pattern is to assign m_Alternatives in the prefab/inspector.
// At runtime LateInitialize will populate the entity buffer with entity references.
public override void LateInitialize(EntityManager entityManager, Entity entity)
{
base.LateInitialize(entityManager, entity);
// Get or create the PrefabSystem (managed)
PrefabSystem prefabSystem = entityManager.World.GetOrCreateSystemManaged<PrefabSystem>();
// Get the dynamic buffer that stores alternative tutorial entity references
DynamicBuffer<Game.Tutorials.TutorialAlternative> buffer = entityManager.GetBuffer<Game.Tutorials.TutorialAlternative>(entity);
// Convert assigned TutorialPrefab references into entity references for the buffer
foreach (TutorialPrefab tutorialPrefab in m_Alternatives)
{
buffer.Add(new Game.Tutorials.TutorialAlternative
{
m_Alternative = prefabSystem.GetEntity(tutorialPrefab)
});
}
}
Notes and tips: - The [NotNull] attribute indicates you should assign alternatives in the prefab inspector. If no alternatives are set, nothing is added to the buffer. - The Game.Tutorials.TutorialAlternative buffer entries contain entity references; other systems will typically query that buffer to determine whether this tutorial should be skipped when any alternative is completed.