feat: always display materials in inspector

pull/197/head
mob-sakai 2021-09-21 16:26:12 +09:00
parent 4e651fac97
commit b743dfb8b4
1 changed files with 37 additions and 43 deletions

View File

@ -30,7 +30,6 @@ namespace Coffee.UIExtensions
private ReorderableList _ro; private ReorderableList _ro;
private bool _xyzMode; private bool _xyzMode;
private bool _showMaterials;
private static readonly List<string> s_MaskablePropertyNames = new List<string> private static readonly List<string> s_MaskablePropertyNames = new List<string>
{ {
@ -59,20 +58,17 @@ namespace Coffee.UIExtensions
_showMaterials = EditorPrefs.GetBool("Coffee.UIExtensions.UIParticleEditor._showMaterials", true); _showMaterials = EditorPrefs.GetBool("Coffee.UIExtensions.UIParticleEditor._showMaterials", true);
var sp = serializedObject.FindProperty("m_Particles"); var sp = serializedObject.FindProperty("m_Particles");
_ro = new ReorderableList(sp.serializedObject, sp, true, true, true, true); _ro = new ReorderableList(sp.serializedObject, sp, true, true, true, true)
_ro.elementHeight = EditorGUIUtility.singleLineHeight * 3 + 4; {
_ro.elementHeightCallback = _ => _showMaterials elementHeight = EditorGUIUtility.singleLineHeight * 3 + 4,
? 3 * (EditorGUIUtility.singleLineHeight + 2) elementHeightCallback = _ => 3 * (EditorGUIUtility.singleLineHeight + 2),
: EditorGUIUtility.singleLineHeight + 2; drawElementCallback = (rect, index, active, focused) =>
_ro.drawElementCallback = (rect, index, active, focused) =>
{ {
EditorGUI.BeginDisabledGroup(sp.hasMultipleDifferentValues); EditorGUI.BeginDisabledGroup(sp.hasMultipleDifferentValues);
rect.y += 1; rect.y += 1;
rect.height = EditorGUIUtility.singleLineHeight; rect.height = EditorGUIUtility.singleLineHeight;
var p = sp.GetArrayElementAtIndex(index); var p = sp.GetArrayElementAtIndex(index);
EditorGUI.ObjectField(rect, p, GUIContent.none); EditorGUI.ObjectField(rect, p, GUIContent.none);
if (!_showMaterials) return;
rect.x += 15; rect.x += 15;
rect.width -= 15; rect.width -= 15;
var ps = p.objectReferenceValue as ParticleSystem; var ps = p.objectReferenceValue as ParticleSystem;
@ -88,17 +84,14 @@ namespace Coffee.UIExtensions
{ {
materials.serializedObject.ApplyModifiedProperties(); materials.serializedObject.ApplyModifiedProperties();
} }
}; },
_ro.drawHeaderCallback += rect => drawHeaderCallback = rect =>
{ {
#if !UNITY_2019_3_OR_NEWER #if !UNITY_2019_3_OR_NEWER
rect.y -= 1; rect.y -= 1;
#endif #endif
EditorGUI.LabelField(new Rect(rect.x, rect.y, 150, rect.height), s_ContentRenderingOrder); EditorGUI.LabelField(new Rect(rect.x, rect.y, 150, rect.height), s_ContentRenderingOrder);
var content = EditorGUIUtility.IconContent(_showMaterials ? "VisibilityOn" : "VisibilityOff");
_showMaterials = GUI.Toggle(new Rect(rect.width - 55, rect.y, 24, 20), _showMaterials, content, EditorStyles.label);
if (GUI.Button(new Rect(rect.width - 35, rect.y, 60, rect.height), s_ContentRefresh, EditorStyles.miniButton)) if (GUI.Button(new Rect(rect.width - 35, rect.y, 60, rect.height), s_ContentRefresh, EditorStyles.miniButton))
{ {
foreach (UIParticle t in targets) foreach (UIParticle t in targets)
@ -106,6 +99,7 @@ namespace Coffee.UIExtensions
t.RefreshParticles(); t.RefreshParticles();
} }
} }
}
}; };
} }