You've already forked ParticleEffectForUGUI
mirror of
https://github.com/mob-sakai/ParticleEffectForUGUI.git
synced 2026-05-14 20:20:06 +00:00
3.0.0-preview.28
# [3.0.0-preview.28](https://github.com/mob-sakai/ParticleEffectForUGUI/compare/v3.0.0-preview.27...v3.0.0-preview.28) (2020-09-01)
### Features
* support AnimatableProperty for multiple materials ([062d988](062d9887fb))
This commit is contained in:
@@ -16,18 +16,12 @@ namespace Coffee.UIExtensions
|
||||
{
|
||||
if (!particle) return;
|
||||
s_ActiveParticles.Add(particle);
|
||||
|
||||
MeshHelper.Register();
|
||||
BakingCamera.Register();
|
||||
}
|
||||
|
||||
public static void Unregister(UIParticle particle)
|
||||
{
|
||||
if (!particle) return;
|
||||
s_ActiveParticles.Remove(particle);
|
||||
|
||||
MeshHelper.Unregister();
|
||||
BakingCamera.Unregister();
|
||||
}
|
||||
|
||||
#if UNITY_EDITOR
|
||||
@@ -36,6 +30,10 @@ namespace Coffee.UIExtensions
|
||||
[RuntimeInitializeOnLoadMethod]
|
||||
private static void InitializeOnLoad()
|
||||
{
|
||||
MeshHelper.Init();
|
||||
MeshPool.Init();
|
||||
CombineInstanceArrayPool.Init();
|
||||
|
||||
Canvas.willRenderCanvases -= Refresh;
|
||||
Canvas.willRenderCanvases += Refresh;
|
||||
}
|
||||
@@ -59,26 +57,26 @@ namespace Coffee.UIExtensions
|
||||
{
|
||||
if (!particle || !particle.canvas || !particle.canvasRenderer) return;
|
||||
|
||||
Profiler.BeginSample("Modify scale");
|
||||
Profiler.BeginSample("[UIParticle] Modify scale");
|
||||
ModifyScale(particle);
|
||||
Profiler.EndSample();
|
||||
|
||||
Profiler.BeginSample("Bake mesh");
|
||||
Profiler.BeginSample("[UIParticle] Bake mesh");
|
||||
BakeMesh(particle);
|
||||
Profiler.EndSample();
|
||||
|
||||
if (QualitySettings.activeColorSpace == ColorSpace.Linear)
|
||||
{
|
||||
Profiler.BeginSample("Modify color space to linear");
|
||||
Profiler.BeginSample("[UIParticle] Modify color space to linear");
|
||||
particle.bakedMesh.ModifyColorSpaceToLinear();
|
||||
Profiler.EndSample();
|
||||
}
|
||||
|
||||
Profiler.BeginSample("Set mesh to CanvasRenderer");
|
||||
Profiler.BeginSample("[UIParticle] Set mesh to CanvasRenderer");
|
||||
particle.canvasRenderer.SetMesh(particle.bakedMesh);
|
||||
Profiler.EndSample();
|
||||
|
||||
Profiler.BeginSample("Update Animatable Material Properties");
|
||||
Profiler.BeginSample("[UIParticle] Update Animatable Material Properties");
|
||||
// UpdateAnimatableMaterialProperties(particle);
|
||||
Profiler.EndSample();
|
||||
}
|
||||
@@ -170,12 +168,12 @@ namespace Coffee.UIExtensions
|
||||
matrix = GetScaledMatrix(currentPs);
|
||||
}
|
||||
|
||||
// Set transform
|
||||
MeshHelper.SetTransform(scaleMatrix * matrix);
|
||||
matrix = scaleMatrix * matrix;
|
||||
|
||||
// Extra world simulation.
|
||||
if (currentPs.main.simulationSpace == ParticleSystemSimulationSpace.World && 0 < diff.sqrMagnitude)
|
||||
{
|
||||
Profiler.BeginSample("[UIParticle] Bake Mesh > Extra world simulation");
|
||||
var count = currentPs.particleCount;
|
||||
if (s_Particles.Length < count)
|
||||
{
|
||||
@@ -192,48 +190,55 @@ namespace Coffee.UIExtensions
|
||||
}
|
||||
|
||||
currentPs.SetParticles(s_Particles, count);
|
||||
Profiler.EndSample();
|
||||
}
|
||||
|
||||
// Bake main particles.
|
||||
var r = currentPs.GetComponent<ParticleSystemRenderer>();
|
||||
if (CanBakeMesh(r))
|
||||
{
|
||||
var m = MeshHelper.GetTemporaryMesh(i * 2);
|
||||
r.BakeMesh(m, camera, true);
|
||||
|
||||
if (m.vertexCount == 0)
|
||||
MeshHelper.DiscardTemporaryMesh();
|
||||
else
|
||||
Profiler.BeginSample("[UIParticle] Bake Mesh > Bake Main Particles");
|
||||
var hash = currentPs.GetMaterialHash(false);
|
||||
if (hash != 0)
|
||||
{
|
||||
var index = MeshHelper.activeMeshIndices.BitCount() - 1;
|
||||
particle.UpdateMaterialProperties(r, index);
|
||||
var m = MeshHelper.GetTemporaryMesh();
|
||||
r.BakeMesh(m, camera, true);
|
||||
MeshHelper.Push(i * 2, hash, m, matrix);
|
||||
}
|
||||
|
||||
Profiler.EndSample();
|
||||
}
|
||||
|
||||
// Bake trails particles.
|
||||
if (currentPs.trails.enabled)
|
||||
{
|
||||
var m = MeshHelper.GetTemporaryMesh(i * 2 + 1);
|
||||
try
|
||||
Profiler.BeginSample("[UIParticle] Bake Mesh > Bake Trails Particles");
|
||||
var hash = currentPs.GetMaterialHash(true);
|
||||
if (hash != 0)
|
||||
{
|
||||
r.BakeTrailsMesh(m, camera, true);
|
||||
var m = MeshHelper.GetTemporaryMesh();
|
||||
try
|
||||
{
|
||||
r.BakeTrailsMesh(m, camera, true);
|
||||
MeshHelper.Push(i * 2 + 1, hash, m, matrix);
|
||||
}
|
||||
catch
|
||||
{
|
||||
MeshHelper.DiscardTemporaryMesh(m);
|
||||
}
|
||||
}
|
||||
|
||||
if (m.vertexCount == 0)
|
||||
MeshHelper.DiscardTemporaryMesh();
|
||||
}
|
||||
catch
|
||||
{
|
||||
MeshHelper.DiscardTemporaryMesh();
|
||||
}
|
||||
Profiler.EndSample();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Set active indices.
|
||||
particle.activeMeshIndices = MeshHelper.activeMeshIndices;
|
||||
|
||||
// Combine
|
||||
Profiler.BeginSample("[UIParticle] Bake Mesh > CombineMesh");
|
||||
MeshHelper.CombineMesh(particle.bakedMesh);
|
||||
Profiler.EndSample();
|
||||
}
|
||||
|
||||
private static bool CanBakeMesh(ParticleSystemRenderer renderer)
|
||||
@@ -246,31 +251,5 @@ namespace Coffee.UIExtensions
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Copy the value from MaterialPropertyBlock to CanvasRenderer
|
||||
/// </summary>
|
||||
private static void UpdateAnimatableMaterialProperties(UIParticle particle, ParticleSystemRenderer renderer)
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
if (!Application.isPlaying) return;
|
||||
#endif
|
||||
if (0 == particle.m_AnimatableProperties.Length) return;
|
||||
if (0 == particle.canvasRenderer.materialCount) return;
|
||||
|
||||
var mat = particle.canvasRenderer.GetMaterial(0);
|
||||
if (!mat) return;
|
||||
|
||||
// #41: Copy the value from MaterialPropertyBlock to CanvasRenderer
|
||||
if (s_Mpb == null)
|
||||
s_Mpb = new MaterialPropertyBlock();
|
||||
renderer.GetPropertyBlock(s_Mpb);
|
||||
foreach (var ap in particle.m_AnimatableProperties)
|
||||
{
|
||||
ap.UpdateMaterialProperties(mat, s_Mpb);
|
||||
}
|
||||
|
||||
s_Mpb.Clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user