From abdf260352db517a2740aedf1c76d0ac162283d9 Mon Sep 17 00:00:00 2001 From: mob-sakai <12690315+mob-sakai@users.noreply.github.com> Date: Sun, 22 Dec 2024 11:38:32 +0900 Subject: [PATCH] fix: '3D' scale toggle in the inspector does not keep on reload close #346 --- Editor/UIParticleEditor.cs | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/Editor/UIParticleEditor.cs b/Editor/UIParticleEditor.cs index 16085db..c58924f 100644 --- a/Editor/UIParticleEditor.cs +++ b/Editor/UIParticleEditor.cs @@ -28,6 +28,11 @@ namespace Coffee.UIExtensions [CanEditMultipleObjects] internal class UIParticleEditor : GraphicEditor { + internal class State : ScriptableSingleton + { + public bool is3DScaleMode; + } + //################################ // Constant or Static Members. //################################ @@ -46,7 +51,6 @@ namespace Coffee.UIExtensions private static readonly GUIContent s_ContentPrimary = new GUIContent("Primary"); private static readonly Regex s_RegexBuiltInGuid = new Regex(@"^0{16}.0{15}$", RegexOptions.Compiled); private static readonly List s_TempMaterials = new List(); - private static bool s_XYZMode; private SerializedProperty _maskable; private SerializedProperty _scale3D; @@ -60,6 +64,7 @@ namespace Coffee.UIExtensions private SerializedProperty _customViewSize; private ReorderableList _ro; private bool _showMax; + private bool _is3DScaleMode; private static readonly HashSet s_Shaders = new HashSet(); #if UNITY_2018 || UNITY_2019 @@ -163,6 +168,19 @@ namespace Coffee.UIExtensions uip.RefreshParticles(uip.particles); } } + + // Initialize 3D scale mode. + _is3DScaleMode = State.instance.is3DScaleMode; + if (!_is3DScaleMode) + { + var x = _scale3D.FindPropertyRelative("x"); + var y = _scale3D.FindPropertyRelative("y"); + var z = _scale3D.FindPropertyRelative("z"); + _is3DScaleMode = !Mathf.Approximately(x.floatValue, y.floatValue) || + !Mathf.Approximately(y.floatValue, z.floatValue) || + y.hasMultipleDifferentValues || + z.hasMultipleDifferentValues; + } } /// @@ -181,7 +199,11 @@ namespace Coffee.UIExtensions // Scale EditorGUI.BeginDisabledGroup(!_meshSharing.hasMultipleDifferentValues && _meshSharing.intValue == 4); - s_XYZMode = DrawFloatOrVector3Field(_scale3D, s_XYZMode); + if (DrawFloatOrVector3Field(_scale3D, _is3DScaleMode) != _is3DScaleMode) + { + State.instance.is3DScaleMode = _is3DScaleMode = !_is3DScaleMode; + } + EditorGUI.EndDisabledGroup(); // AnimatableProperties