#if GRAPH_DESIGNER /// --------------------------------------------- /// Behavior Designer /// Copyright (c) Opsive. All Rights Reserved. /// https://www.opsive.com /// --------------------------------------------- namespace Opsive.BehaviorDesigner.Runtime.Tasks.Actions.ParticlesTasks { using Opsive.GraphDesigner.Runtime.Variables; using UnityEngine; [Opsive.Shared.Utility.Category("Particles")] [Opsive.Shared.Utility.Description("Bursts particles with count, cycles, and interval control.")] public class Burst : TargetGameObjectAction { [Tooltip("The number of particles to burst.")] [SerializeField] protected SharedVariable m_BurstCount = 10; [Tooltip("The number of burst cycles.")] [SerializeField] protected SharedVariable m_Cycles = 1; [Tooltip("The interval between bursts (seconds).")] [SerializeField] protected SharedVariable m_Interval = 0.0f; private ParticleSystem m_ResolvedParticleSystem; private int m_CurrentCycle; private float m_NextBurstTime; /// /// Called when the state machine is initialized. /// /// /// Initializes the target GameObject. /// protected override void InitializeTarget() { base.InitializeTarget(); m_ResolvedParticleSystem = m_ResolvedGameObject.GetComponent(); } /// /// Called when the action starts. /// public override void OnStart() { base.OnStart(); m_CurrentCycle = 0; m_NextBurstTime = 0.0f; } /// /// Updates the particle burst. /// /// The status of the action. public override TaskStatus OnUpdate() { if (m_ResolvedParticleSystem == null) { return TaskStatus.Success; } if (m_CurrentCycle < m_Cycles.Value && Time.time >= m_NextBurstTime) { m_ResolvedParticleSystem.Emit(m_BurstCount.Value); m_CurrentCycle++; m_NextBurstTime = Time.time + m_Interval.Value; } if (m_CurrentCycle >= m_Cycles.Value) { return TaskStatus.Success; } return TaskStatus.Success; } /// /// Resets the action values back to their default. /// public override void Reset() { base.Reset(); m_BurstCount = 10; m_Cycles = 1; m_Interval = 0.0f; } } } #endif