private List <EventCallBackClass> DrawOnFinish(List <EventCallBackClass> eventCallBackClassList) { for (int i = 0; i < eventCallBackClassList.Count; i++) { if (eventCallBackClassList[i] == null) { eventCallBackClassList.RemoveAt(i); return(eventCallBackClassList); } EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("Notify", GUILayout.Width(60)); GUI.contentColor = Color.red; if (GUILayout.Button("\u2014", GUILayout.Width(30))) { eventCallBackClassList.RemoveAt(i); return(eventCallBackClassList); } GUI.contentColor = Color.white; eventCallBackClassList[i]._monoBehaviour = (MonoBehaviour)EditorGUILayout.ObjectField(eventCallBackClassList[i]._monoBehaviour, typeof(MonoBehaviour), true, GUILayout.ExpandWidth(true)); EditorGUILayout.EndHorizontal(); if (eventCallBackClassList[i]._monoBehaviour != null) { List <EventCallBackClass> mothedList = DelegateEventEditor.GetMehtods(eventCallBackClassList[i]._monoBehaviour.gameObject); List <string> nameList = new List <string>(); nameList.Clear(); for (int j = 0; j < mothedList.Count; j++) { string name = mothedList[j]._monoBehaviour.GetType() + "/" + mothedList[j].eventName; nameList.Add(name); } EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("Method", GUILayout.Width(95)); int isSelect = -1; string[] eventNameArr = nameList.ToArray(); for (int k = 0; k < eventNameArr.Length; k++) { if (eventNameArr[k].CompareTo(eventCallBackClassList[i].eventName) == 0) { isSelect = k; } } isSelect = EditorGUILayout.Popup(isSelect, nameList.ToArray()); if (isSelect >= 0) { if (eventNameArr.Length > isSelect) { eventCallBackClassList[i]._monoBehaviour = (MonoBehaviour)mothedList[isSelect]._monoBehaviour; eventCallBackClassList[i].eventName = eventNameArr[isSelect]; } } EditorGUILayout.LabelField("", GUILayout.Width(15)); EditorGUILayout.EndHorizontal(); } } EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("Notify", GUILayout.Width(95)); MonoBehaviour mono = (MonoBehaviour)EditorGUILayout.ObjectField(null, typeof(MonoBehaviour), true, GUILayout.ExpandWidth(true)); EditorGUILayout.EndHorizontal(); if (mono != null) { EventCallBackClass eventCallBackCla = new EventCallBackClass(); eventCallBackCla._monoBehaviour = mono; eventCallBackClassList.Add(eventCallBackCla); } if (GUI.changed) { EditorUtility.SetDirty(target); } return(eventCallBackClassList); }
public static List <EventCallBackClass> GetMehtods(GameObject target) { List <EventCallBackClass> methodList = new List <EventCallBackClass>(); MonoBehaviour[] comps = target.GetComponents <MonoBehaviour>();//获取该对象上挂载的所有脚本 for (int i = 0; i < comps.Length; i++) { MonoBehaviour mb = comps[i]; if (mb == null) { continue; } Type tt = mb.GetType(); //获取脚本类型 MethodInfo[] methods = tt.GetMethods(BindingFlags.Instance | BindingFlags.Public); //获取脚本中的方法 for (int j = 0; j < methods.Length; j++) { MethodInfo mi = methods[j]; //获取方法实体 ParameterInfo[] pi = mi.GetParameters(); //获取方法中的参数 if (pi.Length > 0) { continue; } if (mi.ReturnType == typeof(void)) { string name = mi.Name; if (name == "Invoke") { continue; } if (name == "InvokeRepeating") { continue; } if (name == "CancelInvoke") { continue; } if (name == "StopCoroutine") { continue; } if (name == "StopAllCoroutines") { continue; } if (name == "BroadcastMessage") { continue; } if (name.StartsWith("SendMessage")) { continue; } if (name.StartsWith("set_")) { continue; } if (name.StartsWith("Get")) { continue; } EventCallBackClass delegateEntry = new EventCallBackClass(); delegateEntry._monoBehaviour = mb; delegateEntry.eventName = name; methodList.Add(delegateEntry); //将需要的类型添加进列表 } } } return(methodList); }