public void DrawEventInspector() { EditorGUILayout.BeginHorizontal(); GUILayout.Space(16); EditorGUILayout.BeginVertical(); EditorDelegateGUI.EventFields(target as Component); EditorGUILayout.EndVertical(); EditorGUILayout.EndHorizontal(); if (GUI.changed) { EditorUtility.SetDirty(target); } }
public static void EventFields(Component targetBehavior) { if (targetBehavior == null) { return; } foreach (FieldInfo field in targetBehavior.GetType().GetFields()) { // // GET/SET FIELD if (field.FieldType == typeof(DelegateMessage[]) || field.FieldType == typeof(Delegate)) { // // ARRAY FIELDS DelegateMessage[] oldEvents = field.GetValue(targetBehavior) as DelegateMessage[]; if (field.FieldType == typeof(Delegate)) { Delegate list = (Delegate)field.GetValue(targetBehavior); oldEvents = list != null ? list.events:null; } else { oldEvents = field.GetValue(targetBehavior) as DelegateMessage[]; } DelegateMessage[] newEvents; newEvents = EditorDelegateGUI.EventArrayField(field.Name, oldEvents, targetBehavior.gameObject); if (field.FieldType == typeof(Delegate)) { Delegate list = (Delegate)field.GetValue(targetBehavior); list.events = newEvents; } else { field.SetValue(targetBehavior, newEvents); } } } }