diff --git a/Scripts/UIParticle.cs b/Scripts/UIParticle.cs index 9b9bfa5..11e4be9 100755 --- a/Scripts/UIParticle.cs +++ b/Scripts/UIParticle.cs @@ -1,6 +1,7 @@ #if UNITY_2019_3_11 || UNITY_2019_3_12 || UNITY_2019_3_13 || UNITY_2019_3_14 || UNITY_2019_3_15 || UNITY_2019_4_OR_NEWER #define SERIALIZE_FIELD_MASKABLE #endif +using System.Collections; using System.Collections.Generic; using System.Runtime.CompilerServices; using Coffee.UIParticleExtensions; @@ -60,6 +61,7 @@ public class UIParticle : MaskableGraphic private static readonly List s_PrevMaskMaterials = new List(); private static readonly List s_PrevModifiedMaterials = new List(); private static readonly List s_Components = new List(); + private static readonly List s_ParticleSystems = new List(); /// @@ -407,6 +409,22 @@ protected override void OnEnable() InitializeIfNeeded(); } + private new IEnumerator Start() + { + // #148: Particle Sub Emitter not showing when start game + var hasPlayingSubEmitter = particles.AnyFast(ps => + { + ps.GetComponentsInChildren(false, s_ParticleSystems); + return s_ParticleSystems.AnyFast(p => p.isPlaying && p.subEmitters.enabled); + }); + s_ParticleSystems.Clear(); + if (!hasPlayingSubEmitter) yield break; + + Stop(); + yield return null; + Play(); + } + /// /// This function is called when the behaviour becomes disabled. /// diff --git a/Scripts/Utils.cs b/Scripts/Utils.cs index 79bee49..d47a2d1 100644 --- a/Scripts/Utils.cs +++ b/Scripts/Utils.cs @@ -65,6 +65,16 @@ public static bool AnyFast(this List self) where T : Object return false; } + + public static bool AnyFast(this List self, Predicate predicate) where T : Object + { + for (var i = 0; i < self.Count; ++i) + { + if (self[i] && predicate(self[i])) return true; + } + + return false; + } } internal static class MeshExtensions