From 08c4aba8ab9b5a041d4350a72dae62d25530afca Mon Sep 17 00:00:00 2001 From: mob-sakai Date: Fri, 20 Nov 2020 10:44:17 +0900 Subject: [PATCH] feat: ignore rendering of particle systems that do not have a SharedMaterial and TrailMaterial Close #118 --- Scripts/UIParticleUpdater.cs | 3 ++- Scripts/Utils.cs | 8 ++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/Scripts/UIParticleUpdater.cs b/Scripts/UIParticleUpdater.cs index 0f78156..1428407 100755 --- a/Scripts/UIParticleUpdater.cs +++ b/Scripts/UIParticleUpdater.cs @@ -164,6 +164,8 @@ private static void BakeMesh(UIParticle particle) // No particle to render. var currentPs = particle.particles[i]; if (!currentPs || !currentPs.IsAlive() || currentPs.particleCount == 0) continue; + var r = currentPs.GetComponent(); + if (!r.sharedMaterial && !r.trailMaterial) continue; // Calc matrix. Profiler.BeginSample("[UIParticle] Bake Mesh > Calc matrix"); @@ -218,7 +220,6 @@ private static void BakeMesh(UIParticle particle) #endif // Bake main particles. - var r = currentPs.GetComponent(); if (CanBakeMesh(r)) { Profiler.BeginSample("[UIParticle] Bake Mesh > Bake Main Particles"); diff --git a/Scripts/Utils.cs b/Scripts/Utils.cs index ebc4278..87e9fa5 100644 --- a/Scripts/Utils.cs +++ b/Scripts/Utils.cs @@ -194,8 +194,12 @@ public static void SortForRendering(this List self, Transform tr var bRenderer = b.GetComponent(); // Render queue: ascending - var aMat = aRenderer.sharedMaterial; - var bMat = bRenderer.sharedMaterial; + var aMat = aRenderer.sharedMaterial ?? aRenderer.trailMaterial; + var bMat = bRenderer.sharedMaterial ?? bRenderer.trailMaterial; + if (!aMat && !bMat) return 0; + if (!aMat) return -1; + if (!bMat) return 1; + if (aMat.renderQueue != bMat.renderQueue) return aMat.renderQueue - bMat.renderQueue;