Rasagar/Library/PackageCache/com.unity.visualeffectgraph/Documentation~/Block-Burst.md
2024-08-26 23:07:20 +03:00

5.9 KiB

Single/Periodic Burst

Menu Path:

  • Spawn > Single Burst
  • Spawn > Periodic Burst

The Single/Periodic Burst Block spawns a number of particles instantly either once, or periodically using a delay. When this Block triggers a burst of particles to spawn, it increments the spawnCount instantly. If you change the Repeat setting to Periodic, this Block changes its name to Periodic Burst and spawns bursts of particles after a delay.

Block compatibility

This Block is compatible with the following Contexts:

Block settings

Setting Type Description
Repeat Enum (Inspector) The mode this Block uses to determine whether to trigger the birth only once or repeat it after a delay. The options are:
Single: The Block spawns a single burst of particles.
Periodic: The Block spawns multiple bursts of particles. After it spawns a burst of particles, it waits for the time you specify in Delay and spawns another burst.
Spawn Mode Enum The mode this Block uses to determine how many particles to spawn. The options are:
Constant: This Block spawns a specific number of particles. You can set this number in the Count property.
Random: This Block spawns a random number of particles between two boundaries. If you select this mode, the Count property becomes a Vector 2 where the x-axis represents one boundary value and the y-axis represents the other boundary value.
Delay Mode Enum The mode this Block uses to determine how to calculate a delay time for use between bursts. The options are:
Constant: The delay time is of a specific duration. You can set the duration in the Delay property.
Random: The delay time is of a random duration between two boundaries. If you select this mode, the Delay property becomes a Vector 2 where the x-axis represents one boundary value and the y-axis represents the other boundary value.

Block properties

Input Type Description
Count float/Vector2 The number of particles to spawn.
If you set Spawn Mode to Constant, this property is a float type and the value you set is the specific number of particles to spawn.
If you set Spawn Mode to Random, this property is a Vector 2 where the x-axis represents one boundary value and the y-axis represents the other boundary value. When spawning a burst of particles, this Block uses a random number between these two values to determine how many particles to spawn.
Delay float/Vector2 The duration of the delay this Block waits for before it spawns a burst of particles.
If you set Delay Mode to Constant, this property is a float type and the value you set is the specific delay duration this Block waits for between particle spawns.
If you set Delay Mode to Random, this property is a Vector 2 where the x-axis represents one boundary value and the y-axis represents the other boundary value. When the Block initiates a delay, it uses a random number between these two values to determine the delay duration.

Remarks

You can emulate the single burst behavior with the following equivalent custom spawner callback implementation:

class SingleBurstEquivalent : VFXSpawnerCallbacks
{
    public class InputProperties
    {
        public float Count = 1.0f;
        public float Delay = 2.0f;
    }

    static private readonly int countID = Shader.PropertyToID("Count");
    static private readonly int delayID = Shader.PropertyToID("Delay");

    public sealed override void OnPlay(VFXSpawnerState state, VFXExpressionValues vfxValues, VisualEffect vfxComponent)
    {
    }

    private float m_NextBurstTime;
    private bool m_Sleeping;

    public sealed override void OnUpdate(VFXSpawnerState state, VFXExpressionValues vfxValues, VisualEffect vfxComponent)
    {
        if (state.newLoop)
        {
            m_NextBurstTime = vfxValues.GetFloat(delayID);
            m_Sleeping = false;
        }

        if (!m_Sleeping && state.playing && state.totalTime >= m_NextBurstTime)
        {
            state.spawnCount += vfxValues.GetFloat(countID);
            m_Sleeping = true;
        }
    }

    public sealed override void OnStop(VFXSpawnerState state, VFXExpressionValues vfxValues, VisualEffect vfxComponent)
    {
    }
}

You can emulate the periodic burst behavior with the following equivalent custom spawner callback implementation:

class PeriodicBurstEquivalent : VFXSpawnerCallbacks
{
    public class InputProperties
    {
        public float Count = 1.0f;
        public float Delay = 2.0f;
    }

    static private readonly int countID = Shader.PropertyToID("Count");
    static private readonly int delayID = Shader.PropertyToID("Delay");

    public sealed override void OnPlay(VFXSpawnerState state, VFXExpressionValues vfxValues, VisualEffect vfxComponent)
    {
    }

    private float m_NextBurstTime;

    public sealed override void OnUpdate(VFXSpawnerState state, VFXExpressionValues vfxValues, VisualEffect vfxComponent)
    {
        if (state.newLoop)
        {
            m_NextBurstTime = vfxValues.GetFloat(delayID);
        }

        if (state.playing && state.totalTime >= m_NextBurstTime)
        {
            m_NextBurstTime += vfxValues.GetFloat(delayID);
            state.spawnCount += vfxValues.GetFloat(countID);
        }
    }

    public sealed override void OnStop(VFXSpawnerState state, VFXExpressionValues vfxValues, VisualEffect vfxComponent)
    {
    }
}