Skip to content

Game.Prefabs.EffectSource

Assembly: Assembly-CSharp
Namespace: Game.Prefabs

Type: class

Base: ComponentBase

Summary:
EffectSource is a prefab component that defines one or more visual/particle effects and optional animation curves for those effects. When a prefab containing this component is initialized it registers required ECS components and fills DynamicBuffers (Effect and EffectAnimation) on the entity. It also exposes nested data types for per-effect settings (EffectSettings) and per-animation properties (AnimationProperties). This component is intended for use in prefabs to drive particle/visual effect instances in-game.


Fields

  • public List<EffectSettings> m_Effects
    List of effects that will be instantiated for the prefab. Each entry is an EffectSettings object that points to an EffectPrefab and contains transform, scale, intensity and linking information (parent mesh index, animation index). During LateInitialize each non-null EffectSettings entry is converted into an Effect element and added to the entity's Effect DynamicBuffer.

  • public List<AnimationProperties> m_AnimationCurves
    Optional list of animation curves describing per-effect animations. If non-empty, the component will ensure that an EffectAnimation buffer exists and will populate it. Each AnimationProperties entry contains a duration (in seconds) and a Unity AnimationCurve which is converted to an internal AnimationCurve1.

Nested types (inner classes)

  • public class EffectSettings
  • public EffectPrefab m_Effect — reference to the effect prefab to instantiate.
  • public float3 m_PositionOffset — local position offset for the effect (has [InputField] and [RangeN(-10000f, 10000f, true)] attributes in the source).
  • public quaternion m_Rotation — local rotation; defaults to quaternion.identity.
  • public float3 m_Scale — local scale; defaults to (1,1,1).
  • public float m_Intensity — intensity multiplier for the effect; default is 1. If set to 0 in serialized data, LateInitialize will reset it to 1.
  • public int m_ParentMesh — index of the parent mesh to attach to (if used by the effect system).
  • public int m_AnimationIndex — index into the animation curves list (default -1 means no animation).

  • public class AnimationProperties

  • public float m_Duration — duration in seconds.
  • public AnimationCurve m_Curve — Unity AnimationCurve used to drive animation; converted to AnimationCurve1 at initialization.

Properties

  • This class does not declare any public properties.

Constructors

  • public EffectSource()
    Default constructor (implicit). The component is normally instantiated/edited by prefab tooling; no special construction logic is present in the source.

Methods

  • public override void GetPrefabComponents(HashSet<ComponentType> components)
    Adds ECS component requirements for entities created from this prefab:
  • Always adds Effect (read/write).
  • If m_AnimationCurves is present and non-empty, also adds EffectAnimation (read/write).

  • public override void GetArchetypeComponents(HashSet<ComponentType> components)
    Adds additional archetype-level components required at runtime:

  • Adds EnabledEffect (read/write).

  • public override void GetDependencies(List<PrefabBase> prefabs)
    Collects referenced prefabs so they are included in the prefab load order. For each EffectSettings entry with a non-null m_Effect, the referenced EffectPrefab is added to the provided prefabs list.

  • public override void LateInitialize(EntityManager entityManager, Entity entity)
    Performs runtime initialization on the entity:

  • Retrieves the managed PrefabSystem from the World.
  • If m_Effects is present, gets the DynamicBuffer for the entity, ensures capacity, and adds an Effect element per EffectSettings:
    • Resolves the referenced effect prefab to an Entity using PrefabSystem.GetEntity(effectPrefab).
    • Copies position, rotation, scale, intensity, parent mesh and animation index into the Effect struct.
    • If m_Intensity is 0 in serialized data, it's set to 1 to avoid zero intensity.
  • If m_AnimationCurves is present and non-empty, resizes the DynamicBuffer and fills each entry:
    • Converts duration in seconds to frames by rounding to nearest int of (duration * 60) and stores as uint m_DurationFrames.
    • Converts Unity's AnimationCurve to the internal AnimationCurve1.

Notes: - LateInitialize uses Unity.Entities.DynamicBuffer to populate buffers on the entity. - Animation durations are converted assuming a 60 FPS frame rate (duration * 60).

Usage Example

// Example: programmatically create/prepare EffectSource data (typically done in the editor).
var effectSource = new EffectSource();

// Add one effect setting.
var settings = new EffectSource.EffectSettings
{
    m_Effect = myEffectPrefab, // EffectPrefab reference (asset)
    m_PositionOffset = new float3(0f, 1.5f, 0f),
    m_Rotation = quaternion.identity,
    m_Scale = new float3(1f, 1f, 1f),
    m_Intensity = 1f,
    m_ParentMesh = -1,
    m_AnimationIndex = -1
};
effectSource.m_Effects = new List<EffectSource.EffectSettings> { settings };

// Add an animation curve (optional).
effectSource.m_AnimationCurves = new List<EffectSource.AnimationProperties>
{
    new EffectSource.AnimationProperties {
        m_Duration = 2.0f,
        m_Curve = AnimationCurve.EaseInOut(0f, 0f, 1f, 1f)
    }
};

// At runtime, LateInitialize will be called by the prefab system to:
//  - add Effect entries to the entity's DynamicBuffer<Effect>
//  - add EffectAnimation entries (duration converted to frames) to DynamicBuffer<EffectAnimation>

If you want, I can also produce a short reference for the Effect and EffectAnimation buffer layouts (field meanings) or show how to read those buffers in a system.