fix: support sub emitter with 'PlayOnAwake'

pull/150/head
mob-sakai 2021-02-18 01:55:53 +09:00
parent 3bb5241275
commit d5ce78ae5a
2 changed files with 28 additions and 0 deletions

View File

@ -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 #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 #define SERIALIZE_FIELD_MASKABLE
#endif #endif
using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
using Coffee.UIParticleExtensions; using Coffee.UIParticleExtensions;
@ -60,6 +61,7 @@ namespace Coffee.UIExtensions
private static readonly List<Material> s_PrevMaskMaterials = new List<Material>(); private static readonly List<Material> s_PrevMaskMaterials = new List<Material>();
private static readonly List<Material> s_PrevModifiedMaterials = new List<Material>(); private static readonly List<Material> s_PrevModifiedMaterials = new List<Material>();
private static readonly List<Component> s_Components = new List<Component>(); private static readonly List<Component> s_Components = new List<Component>();
private static readonly List<ParticleSystem> s_ParticleSystems = new List<ParticleSystem>();
/// <summary> /// <summary>
@ -407,6 +409,22 @@ namespace Coffee.UIExtensions
InitializeIfNeeded(); 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();
}
/// <summary> /// <summary>
/// This function is called when the behaviour becomes disabled. /// This function is called when the behaviour becomes disabled.
/// </summary> /// </summary>

View File

@ -65,6 +65,16 @@ namespace Coffee.UIParticleExtensions
return false; return false;
} }
public static bool AnyFast<T>(this List<T> self, Predicate<T> 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 internal static class MeshExtensions