From 1879ac8c538778e386e68cfc989a6f4f974043ca Mon Sep 17 00:00:00 2001 From: mob-sakai Date: Sat, 25 Jun 2022 02:04:23 +0900 Subject: [PATCH] feat: add relative/absolute particle position mode close #205 --- Scripts/Editor/UIParticleEditor.cs | 5 +++++ Scripts/UIParticle.cs | 15 +++++++++++++++ Scripts/UIParticleRenderer.cs | 10 +++++++++- 3 files changed, 29 insertions(+), 1 deletion(-) diff --git a/Scripts/Editor/UIParticleEditor.cs b/Scripts/Editor/UIParticleEditor.cs index 29f99d8..9a43772 100644 --- a/Scripts/Editor/UIParticleEditor.cs +++ b/Scripts/Editor/UIParticleEditor.cs @@ -62,6 +62,7 @@ namespace Coffee.UIExtensions private SerializedProperty m_MeshSharing; private SerializedProperty m_GroupId; private SerializedProperty m_GroupMaxId; + private SerializedProperty m_AbsoluteMode; private ReorderableList _ro; @@ -150,6 +151,7 @@ namespace Coffee.UIExtensions m_MeshSharing = serializedObject.FindProperty("m_MeshSharing"); m_GroupId = serializedObject.FindProperty("m_GroupId"); m_GroupMaxId = serializedObject.FindProperty("m_GroupMaxId"); + m_AbsoluteMode = serializedObject.FindProperty("m_AbsoluteMode"); var sp = serializedObject.FindProperty("m_Particles"); _ro = new ReorderableList(sp.serializedObject, sp, true, true, true, true); @@ -265,6 +267,9 @@ namespace Coffee.UIExtensions } } + // Absolute Mode + EditorGUILayout.PropertyField(m_AbsoluteMode); + // Target ParticleSystems. _ro.DoLayoutList(); diff --git a/Scripts/UIParticle.cs b/Scripts/UIParticle.cs index d5a7442..fa53467 100644 --- a/Scripts/UIParticle.cs +++ b/Scripts/UIParticle.cs @@ -54,6 +54,10 @@ namespace Coffee.UIExtensions [SerializeField] private int m_GroupMaxId = 0; + [SerializeField] + [Tooltip("The particles will be emitted at the ParticleSystem position.\nMove the UIParticle/ParticleSystem to move the particle.")] + private bool m_AbsoluteMode = false; + private List m_Renderers = new List(); #if !SERIALIZE_FIELD_MASKABLE @@ -112,6 +116,17 @@ namespace Coffee.UIExtensions } } + /// + /// Absolute particle position mode. + /// The particles will be emitted at the ParticleSystem position. + /// Move the UIParticle/ParticleSystem to move the particle. + /// + public bool absoluteMode + { + get { return m_AbsoluteMode; } + set { m_AbsoluteMode = value; } + } + internal bool useMeshSharing { get { return m_MeshSharing != MeshSharing.None; } diff --git a/Scripts/UIParticleRenderer.cs b/Scripts/UIParticleRenderer.cs index af47562..95f39d7 100644 --- a/Scripts/UIParticleRenderer.cs +++ b/Scripts/UIParticleRenderer.cs @@ -249,7 +249,15 @@ namespace Coffee.UIExtensions Profiler.BeginSample("[UIParticleRenderer] Combine Mesh"); if (_parent.canSimulate) { - s_CombineInstances[0].transform = canvasRenderer.transform.worldToLocalMatrix * GetWorldMatrix(psPos, scale); + if (_parent.absoluteMode) + { + s_CombineInstances[0].transform = canvasRenderer.transform.worldToLocalMatrix * GetWorldMatrix(psPos, scale); + } + else + { + var diff = _particleSystem.transform.position - _parent.transform.position; + s_CombineInstances[0].transform = canvasRenderer.transform.worldToLocalMatrix * Matrix4x4.Translate(diff.GetScaled(scale - Vector3.one)) * GetWorldMatrix(psPos, scale); + } workerMesh.CombineMeshes(s_CombineInstances, true, true); workerMesh.RecalculateBounds();