From d5ce78ae5acf2740ba7fdc6cde9f197c4e165484 Mon Sep 17 00:00:00 2001 From: mob-sakai Date: Thu, 18 Feb 2021 01:55:53 +0900 Subject: [PATCH] fix: support sub emitter with 'PlayOnAwake' --- Scripts/UIParticle.cs | 18 ++++++++++++++++++ Scripts/Utils.cs | 10 ++++++++++ 2 files changed, 28 insertions(+) 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 @@ namespace Coffee.UIExtensions 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 @@ namespace Coffee.UIExtensions 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 @@ namespace Coffee.UIParticleExtensions 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