Game.Prefabs.TutorialUpgradeTriggerPrefab
Assembly: Assembly-CSharp (typical Unity game assembly for game code)
Namespace: Game.Prefabs
Type: class
Base: TutorialTriggerPrefabBase
Summary:
Prefab component class used to define a tutorial upgrade trigger prefab for the game's ECS-based prefab system. The class ensures that the prefab will include the UpgradeTriggerData ECS component (with read/write access). It is decorated with a ComponentMenu attribute so it appears under "Tutorials/Triggers/" in the Unity component menu. This class is part of the tutorial/trigger prefab definitions and integrates with Unity.Entities (DOTS/ECS) to add the required component type to the prefab entity.
Fields
- None declared in this class.
This prefab class relies on its base class for any fields and does not introduce instance fields of its own.
Properties
- None declared in this class.
All behavior is provided by overriding methods from the base class rather than exposing new properties.
Constructors
public TutorialUpgradeTriggerPrefab()
Default constructor (implicit). No custom construction logic is defined in the source; initialization is handled by the Unity/Prefab system and the base class.
Methods
public override void GetPrefabComponents(HashSet<ComponentType> components)
Overrides the base prefab component collection method. Implementation details:- Calls
base.GetPrefabComponents(components)
to include components defined by the base class. - Adds
ComponentType.ReadWrite<UpgradeTriggerData>()
to the provided set so the resulting prefab entity will contain the UpgradeTriggerData component with read/write access. - Requires Unity.Entities (ComponentType, HashSet
) and the UpgradeTriggerData type (expected to be in Game.Tutorials).
Notes: - The addition of UpgradeTriggerData indicates this prefab is intended to represent an upgrade-related tutorial trigger entity in the ECS world. - Ensure UpgradeTriggerData is implemented and available to the assembly where this prefab is used.
Usage Example
using System;
using System.Collections.Generic;
using Game.Tutorials;
using Unity.Entities;
namespace Game.Prefabs
{
[ComponentMenu("Tutorials/Triggers/", new Type[] { })]
public class TutorialUpgradeTriggerPrefab : TutorialTriggerPrefabBase
{
public override void GetPrefabComponents(HashSet<ComponentType> components)
{
base.GetPrefabComponents(components);
components.Add(ComponentType.ReadWrite<UpgradeTriggerData>());
}
}
}
{{ Additional info:
- ComponentMenu attribute: places this prefab script in Unity's "Add Component" menu under Tutorials/Triggers.
- This pattern is commonly used to create ECS-compatible prefabs: the prefab class declares which ECS component types the entity should have at spawn time.
- If you need the data to be read-only for some systems, consider adding ReadOnly variants where appropriate, but here ReadWrite is used because the trigger likely mutates or is mutated by systems.
- Confirm the UpgradeTriggerData struct/component is properly defined in the Game.Tutorials namespace and declared as an IComponentData (or appropriate ECS component) so ComponentType.ReadWrite