refactor: refactor UIParticle

pull/197/head
mob-sakai 2021-09-21 16:39:45 +09:00
parent 47b29fa55a
commit 82eb90244c
1 changed files with 21 additions and 8 deletions

View File

@ -61,6 +61,10 @@ namespace Coffee.UIExtensions
set { } set { }
} }
/// <summary>
/// Shrink rendering by material on refresh.
/// NOTE: This option will improve canvas batching and performance, but in some cases the rendering is not correct.
/// </summary>
public bool shrinkByMaterial public bool shrinkByMaterial
{ {
get { return m_ShrinkByMaterial; } get { return m_ShrinkByMaterial; }
@ -124,7 +128,10 @@ namespace Coffee.UIExtensions
public void Play() public void Play()
{ {
particles.Exec(p => p.Play()); particles.Exec(p =>
{
p.Simulate(0, false, true);
});
} }
public void Pause() public void Pause()
@ -193,7 +200,7 @@ namespace Coffee.UIExtensions
foreach (var ps in particles) foreach (var ps in particles)
{ {
var tsa = ps.textureSheetAnimation; var tsa = ps.textureSheetAnimation;
if (tsa.mode == ParticleSystemAnimationMode.Sprites && tsa.uvChannelMask == (UVChannelFlags) 0) if (tsa.mode == ParticleSystemAnimationMode.Sprites && tsa.uvChannelMask == 0)
tsa.uvChannelMask = UVChannelFlags.UV0; tsa.uvChannelMask = UVChannelFlags.UV0;
} }
@ -302,10 +309,10 @@ namespace Coffee.UIExtensions
internal void UpdateMaterialProperties() internal void UpdateMaterialProperties()
{ {
if (m_AnimatableProperties.Length == 0) return; var count = activeMeshIndices.CountFast();
if (m_AnimatableProperties.Length == 0 || count == 0) return;
// //
var count = activeMeshIndices.CountFast();
var materialCount = Mathf.Max(8, count); var materialCount = Mathf.Max(8, count);
canvasRenderer.materialCount = materialCount; canvasRenderer.materialCount = materialCount;
var j = 0; var j = 0;
@ -374,7 +381,7 @@ namespace Coffee.UIExtensions
var delayToPlay = particles.AnyFast(ps => var delayToPlay = particles.AnyFast(ps =>
{ {
ps.GetComponentsInChildren(false, s_ParticleSystems); ps.GetComponentsInChildren(false, s_ParticleSystems);
return s_ParticleSystems.AnyFast(p => p.isPlaying && (p.subEmitters.enabled || p.main.prewarm)); return s_ParticleSystems.AnyFast(p => p.isPlaying); //&& (p.subEmitters.enabled || p.main.prewarm));
}); });
s_ParticleSystems.Clear(); s_ParticleSystems.Clear();
if (!delayToPlay) yield break; if (!delayToPlay) yield break;
@ -442,15 +449,21 @@ namespace Coffee.UIExtensions
} }
#if UNITY_EDITOR #if UNITY_EDITOR
protected override void Reset()
{
InitializeIfNeeded();
base.Reset();
}
protected override void OnValidate() protected override void OnValidate()
{ {
#if !SERIALIZE_FIELD_MASKABLE
maskable = m_Maskable;
#endif
SetLayoutDirty(); SetLayoutDirty();
SetVerticesDirty(); SetVerticesDirty();
m_ShouldRecalculateStencil = true; m_ShouldRecalculateStencil = true;
RecalculateClipping(); RecalculateClipping();
#if !SERIALIZE_FIELD_MASKABLE
maskable = m_Maskable;
#endif
} }
#endif #endif
} }