Game.EffectPrefab
Assembly:
Game
Namespace:
Game.Prefabs
Type:
class
Base:
TransformPrefab
Summary:
EffectPrefab is a prefab class used to define and initialize effect entities in the ECS world. It exposes an EffectCondition to control when the effect should be active and a flag to disable distance-based owner culling. The prefab contributes EffectData as a prefab component and ensures runtime instances get an EffectInstance component and an appropriate EntityArchetype that includes the components gathered from contained components plus Created and Updated markers. During LateInitialize it writes an EffectData component on the instantiated entity containing the resolved archetype, condition flags, and owner-culling setting.
Fields
-
public EffectCondition m_Conditions
Holds the effect activation flags (required, forbidden and intensity flags). These are copied into the runtime EffectData during LateInitialize to define when the effect should run. -
public bool m_DisableDistanceCulling
If true, owner distance-based culling is disabled for this effect. During LateInitialize this value is inverted and stored into EffectData.m_OwnerCulling (m_OwnerCulling = !m_DisableDistanceCulling).
Properties
- None.
Constructors
public EffectPrefab()
Implicit parameterless constructor (no custom construction logic in the source).
Methods
-
public override void GetDependencies(List<PrefabBase> prefabs)
Calls the base implementation. Intended extension point to add other prefab dependencies required by this effect. -
public override void GetArchetypeComponents(HashSet<ComponentType> components)
Adds the runtime component types required for effect instances. Calls base then adds ComponentType.ReadWrite() so that entity instances created from the archetype will include EffectInstance. -
public override void GetPrefabComponents(HashSet<ComponentType> components)
Adds prefab-time component types required by the prefab. Calls base then adds ComponentType.ReadWrite() so the prefab entity will contain EffectData. -
public override void LateInitialize(EntityManager entityManager, Entity entity)
Finalizes the prefab instance after creation. It: - Calls base.LateInitialize.
- Resolves the entity archetype by calling GetArchetype(entityManager, entity).
-
Writes an EffectData component onto the entity with:
- m_Archetype = resolved archetype,
- m_Flags copied from m_Conditions (m_RequiredFlags, m_ForbiddenFlags, m_IntensityFlags),
- m_OwnerCulling = !m_DisableDistanceCulling.
-
private EntityArchetype GetArchetype(EntityManager entityManager, Entity entity)
Private helper that: - Collects all ComponentBase instances owned by this prefab (via GetComponents(list)).
- Calls GetArchetypeComponents on each component to accumulate component types into a HashSet.
- Adds Created and Updated marker component types.
- Calls entityManager.CreateArchetype(...) with the accumulated component types and returns the resulting EntityArchetype. This archetype is used in EffectData to describe the runtime instance layout.
Usage Example
[Preserve]
protected override void LateInitialize(EntityManager entityManager, Entity entity)
{
base.LateInitialize(entityManager, entity);
// After base initialization, you can tweak the EffectData if needed.
var data = entityManager.GetComponentData<EffectData>(entity);
// e.g. force owner culling off for this instance
data.m_OwnerCulling = false;
entityManager.SetComponentData(entity, data);
}
{{ Additional notes: - Important referenced types: EffectCondition, EffectData, EffectInstance, ComponentBase, PrefabBase, TransformPrefab, PrefabUtils, Created, Updated. - The prefab builds a runtime archetype by aggregating GetArchetypeComponents() from its child components. Ensure your custom components implement GetArchetypeComponents when adding new component types to the prefab. - m_DisableDistanceCulling is stored inverted in m_OwnerCulling (true => culling enabled, false => culling disabled). }}