From d9e7eb973283118d5d799794933a818a628897bd Mon Sep 17 00:00:00 2001 From: mob-sakai Date: Thu, 16 Jun 2022 22:43:23 +0900 Subject: [PATCH] fix to emit --- Scripts/UIParticle.cs | 8 ++++++++ Scripts/UIParticle.cs.meta | 2 +- Scripts/UIParticleRenderer.cs | 26 ++++++++++++++++++++++++++ Scripts/UIParticleUpdater.cs | 6 ++++++ 4 files changed, 41 insertions(+), 1 deletion(-) diff --git a/Scripts/UIParticle.cs b/Scripts/UIParticle.cs index 696b642..2cb6754 100644 --- a/Scripts/UIParticle.cs +++ b/Scripts/UIParticle.cs @@ -311,6 +311,14 @@ namespace Coffee.UIExtensions } } + internal void UpdateParticleCount() + { + for (var i = 0; i < m_Renderers.Count; i++) + { + m_Renderers[i].UpdateParticleCount(); + } + } + protected override void OnEnable() { #if !SERIALIZE_FIELD_MASKABLE diff --git a/Scripts/UIParticle.cs.meta b/Scripts/UIParticle.cs.meta index ab809ed..1dc794d 100644 --- a/Scripts/UIParticle.cs.meta +++ b/Scripts/UIParticle.cs.meta @@ -4,7 +4,7 @@ MonoImporter: externalObjects: {} serializedVersion: 2 defaultReferences: [] - executionOrder: -100 + executionOrder: 0 icon: {instanceID: 0} userData: assetBundleName: diff --git a/Scripts/UIParticleRenderer.cs b/Scripts/UIParticleRenderer.cs index 638ec0a..d1778da 100644 --- a/Scripts/UIParticleRenderer.cs +++ b/Scripts/UIParticleRenderer.cs @@ -21,6 +21,7 @@ namespace Coffee.UIExtensions private ParticleSystemRenderer _renderer; private ParticleSystem _particleSystem; + internal int _prevParticleCount = 0; //private ParticleSystem _emitter; private UIParticle _parent; private int _index; @@ -111,6 +112,7 @@ namespace Coffee.UIExtensions _parent = null; _particleSystem = null; _renderer = null; + _prevParticleCount = 0; if (0 <= index ) { _index = index; @@ -135,6 +137,7 @@ namespace Coffee.UIExtensions if (_particleSystem.isPlaying) { _particleSystem.Clear(); + _particleSystem.Pause(); } _prewarm = _particleSystem.main.prewarm; @@ -157,6 +160,7 @@ namespace Coffee.UIExtensions _prevPsPos = _particleSystem.transform.position; _prevScreenSize = new Vector2Int(Screen.width, Screen.height); _delay = true; + _prevParticleCount = 0; canvasRenderer.SetTexture(null); @@ -301,6 +305,12 @@ namespace Coffee.UIExtensions s_Renderers.Clear(); } + internal void UpdateParticleCount() + { + if (!_particleSystem) return; + _prevParticleCount = _particleSystem.particleCount; + } + protected override void OnEnable() { base.OnEnable(); @@ -447,6 +457,22 @@ namespace Coffee.UIExtensions return; } + // Emitted particles found. + if (_prevParticleCount != _particleSystem.particleCount) + { + var size = _particleSystem.particleCount; + var particles = ParticleSystemExtensions.GetParticleArray(size); + _particleSystem.GetParticles(particles, size); + for (var i = _prevParticleCount; i < size; i++) + { + var p = particles[i]; + p.position = p.position.GetScaled(scale.Inverse()); + particles[i] = p; + } + + _particleSystem.SetParticles(particles, size); + } + // get world position. var psTransform = _particleSystem.transform; var originWorldPosition = psTransform.position; diff --git a/Scripts/UIParticleUpdater.cs b/Scripts/UIParticleUpdater.cs index 0a67067..e27bf2a 100644 --- a/Scripts/UIParticleUpdater.cs +++ b/Scripts/UIParticleUpdater.cs @@ -93,6 +93,12 @@ namespace Coffee.UIExtensions { s_ActiveAttractors[i].Attract(); } + + // UpdateParticleCount. + for (var i = 0; i < s_ActiveParticles.Count; i++) + { + s_ActiveParticles[i].UpdateParticleCount(); + } } public static void GetGroupedRenderers(int groupId, int index, List results)