Unity – Draw Better UnityEvents

Draw smaller UnityEvents when they’re empty:

//
public void DrawBetterUnityEventLayout (SerializedProperty event_, string label) {
	if (GetPersistentCallCount(event_) == 0) {
		Rect r = GUILayoutUtility.GetRect (0, Mathf.Infinity, 18, 18);
		GUI.BeginGroup (r);
		EditorGUI.PropertyField (new Rect(0,0, r.width, r.height), event_, new GUIContent (label));
		GUI.EndGroup ();
		r = GUILayoutUtility.GetRect (0, Mathf.Infinity, 15, 15);
		GUI.BeginGroup (new Rect(r.x, r.y, r.width,r.height+3));
		EditorGUI.PropertyField (new Rect(0,-67, r.width, r.height), event_, new GUIContent (label));
		GUI.EndGroup ();
	} else {
		EditorGUILayout.PropertyField (event_, new GUIContent (label));
	}
}

public void DrawBetterUnityEvent (Rect r, SerializedProperty event_, string label) {
	if (GetPersistentCallCount(event_) == 0) {
		GUI.BeginGroup (r);
		EditorGUI.PropertyField (new Rect(0,0, r.width, r.height), event_, new GUIContent (label));
		GUI.EndGroup ();
		r.y += 18;
		r.height = 15;
		GUI.BeginGroup (new Rect(r.x, r.y, r.width,r.height+3));
		EditorGUI.PropertyField (new Rect(0,-67, r.width, r.height), event_, new GUIContent (label));
		GUI.EndGroup ();
	} else {
		EditorGUI.PropertyField (r, event_, new GUIContent (label));
	}
}

public int GetPersistentCallCount(SerializedProperty event_){
	return event_.FindPropertyRelative ("m_PersistentCalls").FindPropertyRelative ("m_Calls").arraySize;
}
//