From 8cdd032540ddffd4f6cf391d50ece3437c1893e9 Mon Sep 17 00:00:00 2001 From: mob-sakai Date: Fri, 13 Jul 2018 14:47:30 +0900 Subject: [PATCH] Add try-catch --- .../UIExtensions/UIParticle/UIParticle.cs | 115 ++++++++++-------- 1 file changed, 61 insertions(+), 54 deletions(-) diff --git a/Assets/Coffee/UIExtensions/UIParticle/UIParticle.cs b/Assets/Coffee/UIExtensions/UIParticle/UIParticle.cs index 33b7d0c..0bee710 100644 --- a/Assets/Coffee/UIExtensions/UIParticle/UIParticle.cs +++ b/Assets/Coffee/UIExtensions/UIParticle/UIParticle.cs @@ -105,72 +105,79 @@ namespace Coffee.UIExtensions void UpdateMesh() { - Profiler.BeginSample("CheckTrail"); - CheckTrail(); - Profiler.EndSample(); - - if (m_ParticleSystem) + try { - Profiler.BeginSample("Disable ParticleSystemRenderer"); - if (Application.isPlaying) - { - _renderer.enabled = false; - } + Profiler.BeginSample("CheckTrail"); + CheckTrail(); Profiler.EndSample(); - Profiler.BeginSample("Make Matrix"); - var cam = canvas.worldCamera ?? Camera.main; - bool useTransform = false; - Matrix4x4 matrix = default(Matrix4x4); - switch (m_ParticleSystem.main.simulationSpace) + if (m_ParticleSystem) { - case ParticleSystemSimulationSpace.Local: - matrix = - Matrix4x4.Rotate(m_ParticleSystem.transform.rotation).inverse - * Matrix4x4.Scale(m_ParticleSystem.transform.lossyScale).inverse; - useTransform = true; - break; - case ParticleSystemSimulationSpace.World: - matrix = m_ParticleSystem.transform.worldToLocalMatrix; - break; - case ParticleSystemSimulationSpace.Custom: - break; - } - Profiler.EndSample(); - - _mesh.Clear(); - if (0 < m_ParticleSystem.particleCount) - { - Profiler.BeginSample("Bake Mesh"); - if (m_IsTrail) + Profiler.BeginSample("Disable ParticleSystemRenderer"); + if (Application.isPlaying) { - _renderer.BakeTrailsMesh(_mesh, cam, useTransform); - } - else - { - _renderer.BakeMesh(_mesh, cam, useTransform); + _renderer.enabled = false; } Profiler.EndSample(); - // Apply matrix. - Profiler.BeginSample("Apply matrix to position"); - _mesh.GetVertices(s_Vertices); - var count = s_Vertices.Count; - for (int i = 0; i < count; i++) + Profiler.BeginSample("Make Matrix"); + var cam = canvas.worldCamera ?? Camera.main; + bool useTransform = false; + Matrix4x4 matrix = default(Matrix4x4); + switch (m_ParticleSystem.main.simulationSpace) { - s_Vertices[i] = matrix.MultiplyPoint3x4(s_Vertices[i]); + case ParticleSystemSimulationSpace.Local: + matrix = + Matrix4x4.Rotate(m_ParticleSystem.transform.rotation).inverse + * Matrix4x4.Scale(m_ParticleSystem.transform.lossyScale).inverse; + useTransform = true; + break; + case ParticleSystemSimulationSpace.World: + matrix = m_ParticleSystem.transform.worldToLocalMatrix; + break; + case ParticleSystemSimulationSpace.Custom: + break; } - _mesh.SetVertices(s_Vertices); - s_Vertices.Clear(); + Profiler.EndSample(); + + _mesh.Clear(); + if (0 < m_ParticleSystem.particleCount) + { + Profiler.BeginSample("Bake Mesh"); + if (m_IsTrail) + { + _renderer.BakeTrailsMesh(_mesh, cam, useTransform); + } + else + { + _renderer.BakeMesh(_mesh, cam, useTransform); + } + Profiler.EndSample(); + + // Apply matrix. + Profiler.BeginSample("Apply matrix to position"); + _mesh.GetVertices(s_Vertices); + var count = s_Vertices.Count; + for (int i = 0; i < count; i++) + { + s_Vertices[i] = matrix.MultiplyPoint3x4(s_Vertices[i]); + } + _mesh.SetVertices(s_Vertices); + s_Vertices.Clear(); + Profiler.EndSample(); + } + + + // Set mesh to CanvasRenderer. + Profiler.BeginSample("Set mesh and texture to CanvasRenderer"); + canvasRenderer.SetMesh(_mesh); + canvasRenderer.SetTexture(mainTexture); Profiler.EndSample(); } - - - // Set mesh to CanvasRenderer. - Profiler.BeginSample("Set mesh and texture to CanvasRenderer"); - canvasRenderer.SetMesh(_mesh); - canvasRenderer.SetTexture(mainTexture); - Profiler.EndSample(); + } + catch(System.Exception e) + { + Debug.LogException(e); } }