refactor
parent
4fa43eda4b
commit
37d0c4b711
|
@ -14,7 +14,7 @@ namespace Coffee.UIExtensions
|
||||||
internal class UIParticleRenderer : MaskableGraphic
|
internal class UIParticleRenderer : MaskableGraphic
|
||||||
{
|
{
|
||||||
private static readonly CombineInstance[] s_CombineInstances = new CombineInstance[] { new CombineInstance() };
|
private static readonly CombineInstance[] s_CombineInstances = new CombineInstance[] { new CombineInstance() };
|
||||||
private static ParticleSystem.Particle[] s_Particles = new ParticleSystem.Particle[2048];
|
//private static ParticleSystem.Particle[] s_Particles = new ParticleSystem.Particle[2048];
|
||||||
private static readonly List<Material> s_Materials = new List<Material>(2);
|
private static readonly List<Material> s_Materials = new List<Material>(2);
|
||||||
private static MaterialPropertyBlock s_Mpb;
|
private static MaterialPropertyBlock s_Mpb;
|
||||||
private static readonly List<UIParticleRenderer> s_Renderers = new List<UIParticleRenderer>();
|
private static readonly List<UIParticleRenderer> s_Renderers = new List<UIParticleRenderer>();
|
||||||
|
@ -401,22 +401,19 @@ namespace Coffee.UIExtensions
|
||||||
{
|
{
|
||||||
// Update particle array size and get particles.
|
// Update particle array size and get particles.
|
||||||
var size = _particleSystem.particleCount;
|
var size = _particleSystem.particleCount;
|
||||||
if (s_Particles.Length < size)
|
var particles = ParticleSystemExtensions.GetParticleArray(size);
|
||||||
{
|
_particleSystem.GetParticles(particles, size);
|
||||||
s_Particles = new ParticleSystem.Particle[Mathf.NextPowerOfTwo(size)];
|
|
||||||
}
|
|
||||||
_particleSystem.GetParticles(s_Particles, size);
|
|
||||||
|
|
||||||
// Resolusion resolver:
|
// Resolusion resolver:
|
||||||
// (psPos / scale) / (prevPsPos / prevScale) -> psPos * scale.inv * prevPsPos.inv * prevScale
|
// (psPos / scale) / (prevPsPos / prevScale) -> psPos * scale.inv * prevPsPos.inv * prevScale
|
||||||
var modifier = psPos.GetScaled(scale.Inverse(), _prevPsPos.Inverse(), _prevScale);
|
var modifier = psPos.GetScaled(scale.Inverse(), _prevPsPos.Inverse(), _prevScale);
|
||||||
for (var i = 0; i < size; i++)
|
for (var i = 0; i < size; i++)
|
||||||
{
|
{
|
||||||
var particle = s_Particles[i];
|
var particle = particles[i];
|
||||||
particle.position = particle.position.GetScaled(modifier);
|
particle.position = particle.position.GetScaled(modifier);
|
||||||
s_Particles[i] = particle;
|
particles[i] = particle;
|
||||||
}
|
}
|
||||||
_particleSystem.SetParticles(s_Particles, size);
|
_particleSystem.SetParticles(particles, size);
|
||||||
|
|
||||||
// Delay: Do not progress in the frame where the resolution has been changed.
|
// Delay: Do not progress in the frame where the resolution has been changed.
|
||||||
_delay = true;
|
_delay = true;
|
||||||
|
@ -483,22 +480,17 @@ namespace Coffee.UIExtensions
|
||||||
diffPos.y *= 1f - 1f / Mathf.Max(0.001f, scale.y);
|
diffPos.y *= 1f - 1f / Mathf.Max(0.001f, scale.y);
|
||||||
diffPos.z *= 1f - 1f / Mathf.Max(0.001f, scale.z);
|
diffPos.z *= 1f - 1f / Mathf.Max(0.001f, scale.z);
|
||||||
|
|
||||||
var count = _particleSystem.particleCount;
|
var size = _particleSystem.particleCount;
|
||||||
if (s_Particles.Length < count)
|
var particles = ParticleSystemExtensions.GetParticleArray(size);
|
||||||
|
_particleSystem.GetParticles(particles, size);
|
||||||
|
for (var i = 0; i < size; i++)
|
||||||
{
|
{
|
||||||
var size = Mathf.NextPowerOfTwo(count);
|
var p = particles[i];
|
||||||
s_Particles = new ParticleSystem.Particle[size];
|
|
||||||
}
|
|
||||||
|
|
||||||
_particleSystem.GetParticles(s_Particles);
|
|
||||||
for (var j = 0; j < count; j++)
|
|
||||||
{
|
|
||||||
var p = s_Particles[j];
|
|
||||||
p.position += diffPos;
|
p.position += diffPos;
|
||||||
s_Particles[j] = p;
|
particles[i] = p;
|
||||||
}
|
}
|
||||||
|
|
||||||
_particleSystem.SetParticles(s_Particles, count);
|
_particleSystem.SetParticles(particles, size);
|
||||||
Profiler.EndSample();
|
Profiler.EndSample();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -71,6 +71,21 @@ namespace Coffee.UIParticleExtensions
|
||||||
|
|
||||||
public static class ParticleSystemExtensions
|
public static class ParticleSystemExtensions
|
||||||
{
|
{
|
||||||
|
private static ParticleSystem.Particle[] s_TmpParticles = new ParticleSystem.Particle[2048];
|
||||||
|
|
||||||
|
public static ParticleSystem.Particle[] GetParticleArray(int size)
|
||||||
|
{
|
||||||
|
if (s_TmpParticles.Length < size)
|
||||||
|
{
|
||||||
|
while(s_TmpParticles.Length < size)
|
||||||
|
{
|
||||||
|
size = Mathf.NextPowerOfTwo(size);
|
||||||
|
}
|
||||||
|
s_TmpParticles = new ParticleSystem.Particle[size];
|
||||||
|
}
|
||||||
|
return s_TmpParticles;
|
||||||
|
}
|
||||||
|
|
||||||
public static bool CanBakeMesh(this ParticleSystemRenderer self)
|
public static bool CanBakeMesh(this ParticleSystemRenderer self)
|
||||||
{
|
{
|
||||||
// #69: Editor crashes when mesh is set to null when `ParticleSystem.RenderMode = Mesh`
|
// #69: Editor crashes when mesh is set to null when `ParticleSystem.RenderMode = Mesh`
|
||||||
|
|
Loading…
Reference in New Issue