fix to emit

This commit is contained in:
mob-sakai
2022-06-16 22:43:23 +09:00
parent 386170cbf6
commit d9e7eb9732
4 changed files with 41 additions and 1 deletions

View File

@@ -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;