From 67eff610736344ba0122163ff5ee63b25c43f555 Mon Sep 17 00:00:00 2001 From: mob-sakai Date: Fri, 18 Aug 2023 11:42:22 +0900 Subject: [PATCH] feat: 'AbsoluteMode' option is renamed to 'PositionMode' AbsoluteMode property is obsolete --- Scripts/Editor/UIParticleEditor.cs | 10 +++--- Scripts/UIParticle.cs | 55 +++++++++++++++++++++++------- Scripts/UIParticleAttractor.cs | 2 +- Scripts/UIParticleRenderer.cs | 2 +- 4 files changed, 49 insertions(+), 20 deletions(-) diff --git a/Scripts/Editor/UIParticleEditor.cs b/Scripts/Editor/UIParticleEditor.cs index 8c00b6d..93c47e6 100644 --- a/Scripts/Editor/UIParticleEditor.cs +++ b/Scripts/Editor/UIParticleEditor.cs @@ -74,8 +74,8 @@ namespace Coffee.UIExtensions private SerializedProperty _meshSharing; private SerializedProperty _groupId; private SerializedProperty _groupMaxId; - private SerializedProperty _absoluteMode; private SerializedProperty _ignoreCanvasScaler; + private SerializedProperty _positionMode; private ReorderableList _ro; private bool _showMax; @@ -157,8 +157,8 @@ namespace Coffee.UIExtensions _meshSharing = serializedObject.FindProperty("m_MeshSharing"); _groupId = serializedObject.FindProperty("m_GroupId"); _groupMaxId = serializedObject.FindProperty("m_GroupMaxId"); - _absoluteMode = serializedObject.FindProperty("m_AbsoluteMode"); _ignoreCanvasScaler = serializedObject.FindProperty("m_IgnoreCanvasScaler"); + _positionMode = serializedObject.FindProperty("m_PositionMode"); var sp = serializedObject.FindProperty("m_Particles"); _ro = new ReorderableList(sp.serializedObject, sp, true, true, true, true) @@ -272,8 +272,8 @@ namespace Coffee.UIExtensions } } - // Absolute Mode - EditorGUILayout.PropertyField(_absoluteMode); + // Position Mode + EditorGUILayout.PropertyField(_positionMode); // Auto Scaling DrawInversedToggle(_ignoreCanvasScaler, s_ContentAutoScaling, () => @@ -522,7 +522,6 @@ namespace Coffee.UIExtensions EditorGUIUtility.labelWidth = 100; EditorGUILayout.PropertyField(s_SerializedObject.FindProperty("m_Enabled")); s_XYZMode = DrawFloatOrVector3Field(s_SerializedObject.FindProperty("m_Scale3D"), s_XYZMode); - EditorGUILayout.PropertyField(s_SerializedObject.FindProperty("m_AbsoluteMode")); DrawInversedToggle(s_SerializedObject.FindProperty("m_IgnoreCanvasScaler"), s_ContentAutoScaling, () => @@ -533,6 +532,7 @@ namespace Coffee.UIExtensions .ToList() .ForEach(x => x.transform.localScale = Vector3.one); }); + EditorGUILayout.PropertyField(s_SerializedObject.FindProperty("m_PositionMode")); EditorGUIUtility.labelWidth = labelWidth; } diff --git a/Scripts/UIParticle.cs b/Scripts/UIParticle.cs index 796cbd0..bfe6ca5 100644 --- a/Scripts/UIParticle.cs +++ b/Scripts/UIParticle.cs @@ -19,7 +19,7 @@ namespace Coffee.UIExtensions [ExecuteAlways] [RequireComponent(typeof(RectTransform))] [RequireComponent(typeof(CanvasRenderer))] - public class UIParticle : MaskableGraphic + public class UIParticle : MaskableGraphic, ISerializationCallbackReceiver { public enum MeshSharing { @@ -30,10 +30,20 @@ namespace Coffee.UIExtensions Replica } + public enum PositionMode + { + Relative, + Absolute + } + [HideInInspector] [SerializeField] internal bool m_IsTrail; + [HideInInspector] + [SerializeField] + private bool m_AbsoluteMode; + [Tooltip("Particle effect scale")] [SerializeField] private Vector3 m_Scale3D = new Vector3(10, 10, 10); @@ -64,13 +74,10 @@ namespace Coffee.UIExtensions [SerializeField] private int m_GroupMaxId; + [Tooltip("Relative: The particles will be emitted from the scaled position of ParticleSystem.\n" + + "Absolute: The particles will be emitted from the world position of ParticleSystem.")] [SerializeField] - [Tooltip("Particle position mode.\n" + - "Absolute Mode: The particles will be emitted from the ParticleSystem position.\n" + - " Move the UIParticle or ParticleSystem to move the particle.\n" + - "Relative Mode: The particles will be emitted from the scaled ParticleSystem position.\n" + - " Move the UIParticle to move the particle.")] - private bool m_AbsoluteMode = false; + private PositionMode m_PositionMode = PositionMode.Relative; /// /// This field uses the inverted value as "AutoScaling". @@ -142,15 +149,24 @@ namespace Coffee.UIExtensions /// /// Particle position mode. - /// Absolute Mode: The particles will be emitted from the ParticleSystem position. - /// Move the UIParticle or ParticleSystem to move the particle. - /// Relative Mode: The particles will be emitted from the scaled ParticleSystem position. - /// Move the UIParticle to move the particle. + /// Relative: The particles will be emitted from the scaled position of the ParticleSystem. + /// Absolute: The particles will be emitted from the world position of the ParticleSystem. + /// + public PositionMode positionMode + { + get { return m_PositionMode; } + set { m_PositionMode = value; } + } + + /// + /// Particle position mode. + /// Relative: The particles will be emitted from the scaled position of the ParticleSystem. + /// Absolute: The particles will be emitted from the world position of the ParticleSystem. /// public bool absoluteMode { - get { return m_AbsoluteMode; } - set { m_AbsoluteMode = value; } + get { return m_PositionMode == PositionMode.Absolute; } + set { positionMode = value ? PositionMode.Absolute : PositionMode.Relative; } } /// @@ -306,6 +322,19 @@ namespace Coffee.UIExtensions } #endif + void ISerializationCallbackReceiver.OnBeforeSerialize() + { + m_AbsoluteMode = m_PositionMode == PositionMode.Absolute; + } + + void ISerializationCallbackReceiver.OnAfterDeserialize() + { + if (m_AbsoluteMode) + { + m_PositionMode = PositionMode.Absolute; + } + } + public void Play() { particles.Exec(p => p.Simulate(0, false, true)); diff --git a/Scripts/UIParticleAttractor.cs b/Scripts/UIParticleAttractor.cs index 60d6aab..76460f0 100644 --- a/Scripts/UIParticleAttractor.cs +++ b/Scripts/UIParticleAttractor.cs @@ -185,7 +185,7 @@ namespace Coffee.UIExtensions dstPos = dstPos.GetScaled(inverseScale, _uiParticle.scale3D.Inverse()); // Relative mode - if (!_uiParticle.absoluteMode) + if (_uiParticle.positionMode == UIParticle.PositionMode.Relative) { var diff = _uiParticle.transform.position - psPos; diff.Scale(_uiParticle.scale3D - inverseScale); diff --git a/Scripts/UIParticleRenderer.cs b/Scripts/UIParticleRenderer.cs index 043cee5..bb900ad 100644 --- a/Scripts/UIParticleRenderer.cs +++ b/Scripts/UIParticleRenderer.cs @@ -353,7 +353,7 @@ namespace Coffee.UIExtensions Profiler.BeginSample("[UIParticleRenderer] Combine Mesh"); if (_parent.canSimulate) { - if (_parent.absoluteMode) + if (_parent.positionMode == UIParticle.PositionMode.Absolute) { s_CombineInstances[0].transform = canvasRenderer.transform.worldToLocalMatrix