Skip to content

Commit

Permalink
feat: display material properties in inspector
Browse files Browse the repository at this point in the history
close #104

mat
  • Loading branch information
mob-sakai committed Oct 4, 2020
1 parent 35f6670 commit 313c1fc
Showing 1 changed file with 44 additions and 4 deletions.
48 changes: 44 additions & 4 deletions Packages/UIParticle/Scripts/Editor/UIParticleEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ internal class UIParticleEditor : GraphicEditor
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 List<UIParticle> s_TempParents = new List<UIParticle>();
private static readonly List<UIParticle> s_TempChildren = new List<UIParticle>();

Expand Down Expand Up @@ -52,19 +54,43 @@ protected override void OnEnable()
_spAnimatableProperties = serializedObject.FindProperty("m_AnimatableProperties");

var sp = serializedObject.FindProperty("m_Particles");
_ro = new ReorderableList(sp.serializedObject, sp, true, true, false, false);
_ro.elementHeight = EditorGUIUtility.singleLineHeight + 4;
_ro = new ReorderableList(sp.serializedObject, sp, true, true, true, true);
_ro.elementHeight = EditorGUIUtility.singleLineHeight * 3 + 4;
_ro.drawElementCallback = (rect, index, active, focused) =>
{
EditorGUI.BeginDisabledGroup(sp.hasMultipleDifferentValues);
rect.y += 1;
rect.height = EditorGUIUtility.singleLineHeight;
EditorGUI.ObjectField(rect, sp.GetArrayElementAtIndex(index), GUIContent.none);
var p = sp.GetArrayElementAtIndex(index);
EditorGUI.ObjectField(rect, p, GUIContent.none);

rect.x += 15;
rect.width -= 15;
var ps = p.objectReferenceValue as ParticleSystem;
var materials = ps
? new SerializedObject(ps.GetComponent<ParticleSystemRenderer>()).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.ApplyModifiedProperties();
}
};
_ro.drawHeaderCallback += rect =>
{
EditorGUI.LabelField(new Rect(rect.x, rect.y, 150, rect.height), s_ContentRenderingOrder);

if (GUI.Button(new Rect(rect.width - 80, rect.y - 1, 80, rect.height), s_ContentRefresh, EditorStyles.miniButton))
#if UNITY_2019_3_OR_NEWER
rect = new Rect(rect.width - 55, rect.y, 80, rect.height);
#else
rect = new Rect(rect.width - 55, rect.y - 1, 80, rect.height);
#endif

if (GUI.Button(rect, s_ContentRefresh, EditorStyles.miniButton))
{
foreach (UIParticle t in targets)
{
Expand All @@ -74,6 +100,20 @@ 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);
}
}

/// <summary>
/// Implement this function to make a custom inspector.
/// </summary>
Expand Down

0 comments on commit 313c1fc

Please sign in to comment.