From f1fbd9dacd37896868de465f50c806ff94f703e1 Mon Sep 17 00:00:00 2001 From: "Simon (darkside) Jackson" Date: Sun, 19 Apr 2020 11:42:58 +0100 Subject: [PATCH] Added ability to recognise when "PlayOnAwake" was disabled for a Particle System Also added three programmatic calls to Play, Pause and Stop the effect. --- Scripts/Effects/UIParticleSystem.cs | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/Scripts/Effects/UIParticleSystem.cs b/Scripts/Effects/UIParticleSystem.cs index abf0fa5..f6705ab 100644 --- a/Scripts/Effects/UIParticleSystem.cs +++ b/Scripts/Effects/UIParticleSystem.cs @@ -25,6 +25,7 @@ namespace UnityEngine.UI.Extensions private int textureSheetAnimationFrames; private Vector2 textureSheetAnimationFrameSize; private ParticleSystemRenderer pRenderer; + private bool isInitialised = false; private Material currentMaterial; @@ -149,6 +150,12 @@ namespace UnityEngine.UI.Extensions return; } + if (!isInitialised && !pSystem.main.playOnAwake) + { + pSystem.Stop(false, ParticleSystemStopBehavior.StopEmittingAndClear); + isInitialised = true; + } + Vector2 temp = Vector2.zero; Vector2 corner1 = Vector2.zero; Vector2 corner2 = Vector2.zero; @@ -330,7 +337,7 @@ namespace UnityEngine.UI.Extensions } } - void Update() + private void Update() { if (!fixedTime && Application.isPlaying) { @@ -346,7 +353,7 @@ namespace UnityEngine.UI.Extensions } } - void LateUpdate() + private void LateUpdate() { if (!Application.isPlaying) { @@ -377,6 +384,21 @@ namespace UnityEngine.UI.Extensions currentMaterial = null; currentTexture = null; } + + public void StartParticleEmission() + { + pSystem.Play(); + } + + public void StopParticleEmission() + { + pSystem.Stop(false, ParticleSystemStopBehavior.StopEmittingAndClear); + } + + public void PauseParticleEmission() + { + pSystem.Stop(false, ParticleSystemStopBehavior.StopEmitting); + } } #endif } \ No newline at end of file