From 410304125f3f25f3f543c7bc01dcc661eab00609 Mon Sep 17 00:00:00 2001 From: mob-sakai Date: Fri, 18 Aug 2023 11:42:56 +0900 Subject: [PATCH] feat: 'AutoScaling' option will be imported from 'IgnoreCanvasScale' (for v3.x) --- Scripts/Editor/UIParticleEditor.cs | 57 +++++++++--------------------- Scripts/UIParticle.cs | 28 +++++++++------ 2 files changed, 35 insertions(+), 50 deletions(-) diff --git a/Scripts/Editor/UIParticleEditor.cs b/Scripts/Editor/UIParticleEditor.cs index 93c47e6..a37656d 100644 --- a/Scripts/Editor/UIParticleEditor.cs +++ b/Scripts/Editor/UIParticleEditor.cs @@ -60,11 +60,6 @@ namespace Coffee.UIExtensions private static readonly GUIContent s_Content3D = new GUIContent("3D"); private static readonly GUIContent s_ContentRandom = new GUIContent("Random"); private static readonly GUIContent s_ContentScale = new GUIContent("Scale"); - - private static readonly GUIContent s_ContentAutoScaling = new GUIContent("Auto Scaling", - "Transform.lossyScale (=world scale) is automatically set to (1, 1, 1)," + - " to prevent the root-Canvas scale from affecting the hierarchy-scaled ParticleSystem."); - private static SerializedObject s_SerializedObject; private static bool s_XYZMode; @@ -74,8 +69,8 @@ namespace Coffee.UIExtensions private SerializedProperty _meshSharing; private SerializedProperty _groupId; private SerializedProperty _groupMaxId; - private SerializedProperty _ignoreCanvasScaler; private SerializedProperty _positionMode; + private SerializedProperty _autoScaling; private ReorderableList _ro; private bool _showMax; @@ -157,8 +152,8 @@ namespace Coffee.UIExtensions _meshSharing = serializedObject.FindProperty("m_MeshSharing"); _groupId = serializedObject.FindProperty("m_GroupId"); _groupMaxId = serializedObject.FindProperty("m_GroupMaxId"); - _ignoreCanvasScaler = serializedObject.FindProperty("m_IgnoreCanvasScaler"); _positionMode = serializedObject.FindProperty("m_PositionMode"); + _autoScaling = serializedObject.FindProperty("m_AutoScaling"); var sp = serializedObject.FindProperty("m_Particles"); _ro = new ReorderableList(sp.serializedObject, sp, true, true, true, true) @@ -276,16 +271,7 @@ namespace Coffee.UIExtensions EditorGUILayout.PropertyField(_positionMode); // Auto Scaling - DrawInversedToggle(_ignoreCanvasScaler, s_ContentAutoScaling, () => - { - foreach (var uip in targets.OfType()) - { - if (uip && !uip.autoScaling) - { - uip.transform.localScale = Vector3.one; - } - } - }); + DrawAutoScaling(_autoScaling, targets.OfType()); // Target ParticleSystems. EditorGUI.BeginChangeCheck(); @@ -490,22 +476,21 @@ namespace Coffee.UIExtensions return showMax; } - private static void DrawInversedToggle(SerializedProperty sp, GUIContent label, Action onChanged) + private static void DrawAutoScaling(SerializedProperty prop, IEnumerable uiParticles) { - EditorGUI.showMixedValue = sp.hasMultipleDifferentValues; - var autoScaling = !sp.boolValue; EditorGUI.BeginChangeCheck(); - if (autoScaling != EditorGUILayout.Toggle(label, autoScaling)) - { - sp.boolValue = autoScaling; - } + EditorGUILayout.PropertyField(prop); + if (!EditorGUI.EndChangeCheck()) return; - if (EditorGUI.EndChangeCheck()) + // on changed true->false, reset scale. + EditorApplication.delayCall += () => { - EditorApplication.delayCall += onChanged.Invoke; - } - - EditorGUI.showMixedValue = false; + foreach (var uip in uiParticles) + { + if (!uip || uip.autoScaling) continue; + uip.transform.localScale = Vector3.one; + } + }; } private static void WindowFunction(Object target, SceneView sceneView) @@ -513,7 +498,8 @@ namespace Coffee.UIExtensions try { if (s_SerializedObject == null || !s_SerializedObject.targetObject) return; - if (s_SerializedObject.targetObjects.OfType().Any(x => !x || !x.canvas)) return; + var uiParticles = s_SerializedObject.targetObjects.OfType(); + if (uiParticles.Any(x => !x || !x.canvas)) return; s_SerializedObject.Update(); using (new EditorGUILayout.VerticalScope(GUILayout.Width(220f))) @@ -522,17 +508,8 @@ namespace Coffee.UIExtensions EditorGUIUtility.labelWidth = 100; EditorGUILayout.PropertyField(s_SerializedObject.FindProperty("m_Enabled")); s_XYZMode = DrawFloatOrVector3Field(s_SerializedObject.FindProperty("m_Scale3D"), s_XYZMode); - DrawInversedToggle(s_SerializedObject.FindProperty("m_IgnoreCanvasScaler"), - s_ContentAutoScaling, - () => - { - s_SerializedObject.targetObjects - .OfType() - .Where(x => x && !x.autoScaling) - .ToList() - .ForEach(x => x.transform.localScale = Vector3.one); - }); EditorGUILayout.PropertyField(s_SerializedObject.FindProperty("m_PositionMode")); + DrawAutoScaling(s_SerializedObject.FindProperty("m_AutoScaling"), uiParticles); EditorGUIUtility.labelWidth = labelWidth; } diff --git a/Scripts/UIParticle.cs b/Scripts/UIParticle.cs index bfe6ca5..1f4a543 100644 --- a/Scripts/UIParticle.cs +++ b/Scripts/UIParticle.cs @@ -40,6 +40,11 @@ namespace Coffee.UIExtensions [SerializeField] internal bool m_IsTrail; + [HideInInspector] + [FormerlySerializedAs("m_IgnoreParent")] + [SerializeField] + private bool m_IgnoreCanvasScaler; + [HideInInspector] [SerializeField] private bool m_AbsoluteMode; @@ -79,12 +84,10 @@ namespace Coffee.UIExtensions [SerializeField] private PositionMode m_PositionMode = PositionMode.Relative; - /// - /// This field uses the inverted value as "AutoScaling". - /// - [FormerlySerializedAs("m_IgnoreParent")] [SerializeField] - private bool m_IgnoreCanvasScaler; + [Tooltip("Transform.lossyScale (=world scale) is automatically set to (1, 1, 1), " + + "to prevent the root-Canvas scale from affecting the hierarchy-scaled ParticleSystem.")] + private bool m_AutoScaling = true; #if !SERIALIZE_FIELD_MASKABLE [SerializeField] @@ -170,17 +173,16 @@ namespace Coffee.UIExtensions } /// - /// Transform.lossyScale (=world scale) is automatically set to (1, 1, 1). + /// Transform.lossyScale (=world scale) will be set to (1, 1, 1) on update. /// It prevents the root-Canvas scale from affecting the hierarchy-scaled ParticleSystem. - /// Note: This option works in reverse of ’IgnoreCanvasScaler’ option in v3.x. /// public bool autoScaling { - get { return !m_IgnoreCanvasScaler; } + get { return m_AutoScaling; } set { - if (m_IgnoreCanvasScaler != value) return; - m_IgnoreCanvasScaler = !value; + if (m_AutoScaling == value) return; + m_AutoScaling = value; UpdateTracker(); } } @@ -324,11 +326,17 @@ namespace Coffee.UIExtensions void ISerializationCallbackReceiver.OnBeforeSerialize() { + m_IgnoreCanvasScaler = !m_AutoScaling; m_AbsoluteMode = m_PositionMode == PositionMode.Absolute; } void ISerializationCallbackReceiver.OnAfterDeserialize() { + if (m_IgnoreCanvasScaler) + { + m_AutoScaling = false; + } + if (m_AbsoluteMode) { m_PositionMode = PositionMode.Absolute;