Skip to content

Commit

Permalink
fix: support sub emitter with 'PlayOnAwake'
Browse files Browse the repository at this point in the history
  • Loading branch information
mob-sakai committed Feb 18, 2021
1 parent 3bb5241 commit d5ce78a
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
18 changes: 18 additions & 0 deletions Scripts/UIParticle.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -60,6 +61,7 @@ public class UIParticle : MaskableGraphic
private static readonly List<Material> s_PrevMaskMaterials = 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<ParticleSystem> s_ParticleSystems = new List<ParticleSystem>();


/// <summary>
Expand Down Expand Up @@ -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();
}

/// <summary>
/// This function is called when the behaviour becomes disabled.
/// </summary>
Expand Down
10 changes: 10 additions & 0 deletions Scripts/Utils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,16 @@ public static bool AnyFast<T>(this List<T> self) where T : Object

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
Expand Down

0 comments on commit d5ce78a

Please sign in to comment.