From be901724e064befacf617f4940b0331e1d31e1ca Mon Sep 17 00:00:00 2001 From: mob-sakai <12690315+mob-sakai@users.noreply.github.com> Date: Thu, 27 Jun 2024 01:52:00 +0900 Subject: [PATCH] feat: the rendering order list in inspector is now more compact --- Packages/src/Editor/UIParticleEditor.cs | 65 +++++++++++++------------ 1 file changed, 33 insertions(+), 32 deletions(-) diff --git a/Packages/src/Editor/UIParticleEditor.cs b/Packages/src/Editor/UIParticleEditor.cs index 0355047..f64c3e9 100644 --- a/Packages/src/Editor/UIParticleEditor.cs +++ b/Packages/src/Editor/UIParticleEditor.cs @@ -29,14 +29,19 @@ internal class UIParticleEditor : GraphicEditor //################################ // Constant or Static Members. //################################ + private static readonly GUIContent[] s_ContentMaterials = new[] + { + new GUIContent("Material"), + new GUIContent("Trail Material") + }; + private static readonly GUIContent s_ContentRenderingOrder = new GUIContent("Rendering Order"); private static readonly GUIContent s_ContentRefresh = new GUIContent("Refresh"); private static readonly GUIContent s_ContentFix = new GUIContent("Fix"); - private static readonly GUIContent s_ContentMaterial = new GUIContent("Material"); - private static readonly GUIContent s_ContentTrailMaterial = new GUIContent("Trail Material"); 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_ContentPrimary = new GUIContent("Primary"); private static bool s_XYZMode; private SerializedProperty _maskable; @@ -90,27 +95,37 @@ protected override void OnEnable() var sp = serializedObject.FindProperty("m_Particles"); _ro = new ReorderableList(sp.serializedObject, sp, true, true, true, true) { - elementHeight = EditorGUIUtility.singleLineHeight * 3 + 4, - elementHeightCallback = _ => 3 * (EditorGUIUtility.singleLineHeight + 2), + elementHeightCallback = index => + { + var ps = sp.GetArrayElementAtIndex(index).objectReferenceValue as ParticleSystem; + var materialCount = 0; + if (ps && ps.TryGetComponent(out var psr)) + { + materialCount = psr.sharedMaterials.Length; + } + + return (materialCount + 1) * (EditorGUIUtility.singleLineHeight + 2); + }, drawElementCallback = (rect, index, _, __) => { - EditorGUI.BeginDisabledGroup(sp.hasMultipleDifferentValues); - rect.y += 1; + rect.y += 2; rect.height = EditorGUIUtility.singleLineHeight; var p = sp.GetArrayElementAtIndex(index); EditorGUI.ObjectField(rect, p, GUIContent.none); + var ps = p.objectReferenceValue as ParticleSystem; + if (!ps || !ps.TryGetComponent(out var psr)) return; + rect.x += 15; rect.width -= 15; - var ps = p.objectReferenceValue as ParticleSystem; - var materials = ps - ? new SerializedObject(ps.GetComponent()).FindProperty("m_Materials") - : null; - rect.y += rect.height + 1; - MaterialField(rect, s_ContentMaterial, materials, 0); - rect.y += rect.height + 1; - MaterialField(rect, s_ContentTrailMaterial, materials, 1); - EditorGUI.EndDisabledGroup(); - if (materials != null && materials.serializedObject.hasModifiedProperties) + var materials = new SerializedObject(psr).FindProperty("m_Materials"); + var count = Mathf.Min(materials.arraySize, 2); + for (var i = 0; i < count; i++) + { + rect.y += rect.height + 2; + EditorGUI.PropertyField(rect, materials.GetArrayElementAtIndex(i), s_ContentMaterials[i]); + } + + if (materials.serializedObject.hasModifiedProperties) { materials.serializedObject.ApplyModifiedProperties(); } @@ -146,20 +161,6 @@ protected override void OnEnable() } } - private static void MaterialField(Rect rect, GUIContent label, SerializedProperty sp, int index) - { - if (sp == null || sp.arraySize <= index) - { - EditorGUI.BeginDisabledGroup(true); - EditorGUI.ObjectField(rect, label, null, typeof(Material), true); - EditorGUI.EndDisabledGroup(); - } - else - { - EditorGUI.PropertyField(rect, sp.GetArrayElementAtIndex(index), label); - } - } - /// /// Implement this function to make a custom inspector. /// @@ -311,7 +312,7 @@ public override void OnInspectorGUI() #endif } - private bool IsBuiltInObject(Object obj) + private static bool IsBuiltInObject(Object obj) { return AssetDatabase.TryGetGUIDAndLocalFileIdentifier(obj, out var guid, out long _) && Regex.IsMatch(guid, "^0{16}.0{15}$", RegexOptions.Compiled); @@ -408,7 +409,7 @@ private static bool DrawMeshSharing(SerializedProperty spMeshSharing, Serialized { EditorGUI.BeginDisabledGroup(true); var obj = UIParticleUpdater.GetPrimary(spGroupId.intValue); - EditorGUILayout.ObjectField("Primary", obj, typeof(UIParticle), false); + EditorGUILayout.ObjectField(s_ContentPrimary, obj, typeof(UIParticle), false); EditorGUI.EndDisabledGroup(); }