forked from BilalY/Rasagar
111 lines
5.9 KiB
Markdown
111 lines
5.9 KiB
Markdown
|
# 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](https://docs.unity3d.com/Documentation/ScriptReference/VFX.VFXSpawnerState-spawnCount.html) 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:
|
||
|
|
||
|
- [Spawn](Context-Spawn.md)
|
||
|
|
||
|
## 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:<br/>• **Single**: The Block spawns a single burst of particles.<br/>• **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:<br/>• **Constant**: This Block spawns a specific number of particles. You can set this number in the **Count** property.<br/>• **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:<br/>• **Constant**: The delay time is of a specific duration. You can set the duration in the **Delay** property.<br/>• **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.<br/>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.<br/>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.<br/>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.<br/>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:
|
||
|
```C#
|
||
|
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:
|
||
|
```C#
|
||
|
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)
|
||
|
{
|
||
|
}
|
||
|
}
|
||
|
```
|