/// <summary> /// Adds an MBCEventHandler delegate to the events to invoke. /// </summary> /// <param name="del"></param> protected virtual void AddEventHandler(MBCEventHandler del) { MethodInfo method = del.Method; object[] attributes = method.GetCustomAttributes(typeof(EventFilterAttribute), false); if (attributes.Length > 0) { foreach (object o in attributes) { EventFilterAttribute attribute = (EventFilterAttribute)o; if (attribute.Event == typeof(MatchAddPlayerEvent)) { Console.WriteLine("Hello"); } if (!filters.ContainsKey(attribute.Event)) { filters.Add(attribute.Event, new List <MBCEventHandler>()); } filters[attribute.Event].Add(del); } } else { noFilters.Add(del); } }
/// <summary> /// Removes an event handler from being invoked. /// </summary> /// <param name="del"></param> protected virtual void RemoveEventHandler(MBCEventHandler del) { MethodInfo method = del.Method; object[] attributes = method.GetCustomAttributes(typeof(EventFilterAttribute), false); if (attributes.Length == 0) { foreach (object o in attributes) { EventFilterAttribute attribute = (EventFilterAttribute)o; if (filters.ContainsKey(attribute.Event)) { filters[attribute.Event].Remove(del); } } } else { noFilters.Remove(del); } }
public InspectorData(SerializedProperty property, GUIContent label, Rect position, int indentLevel, GenericMenu.MenuFunction2 menuSelectionHandler, GenericMenu.MenuFunction2 noFunctionHandler, FieldInfo fieldInfo) { this.property = property; this.listProperty = property.FindPropertyRelative("persistentCalls").FindPropertyRelative("calls"); this.position = position; this.indentLevel = indentLevel; this.label = label; this.menuSelectionHandler = menuSelectionHandler; this.noFunctionHandler = noFunctionHandler; object[] customAttributes = fieldInfo.GetCustomAttributes(typeof(EventFilterAttribute), false); if (customAttributes.Length == 1) { filterAttribute = customAttributes[0] as EventFilterAttribute; } Type[] genericArguments = fieldInfo.FieldType.BaseType.GetGenericArguments(); if (genericArguments.Length == 1) { eventType = genericArguments[0]; } eventHeaderText = label.text + " ("; for (int i = 0; i < genericArguments.Length; i++) { eventHeaderText += GetCleanTypeName(genericArguments[i]); if (i < genericArguments.Length - 1) { eventHeaderText += ", "; } } eventHeaderText += ")"; persistentCallData = new PersistentCallData[listProperty.arraySize]; for (int i = 0; i < listProperty.arraySize; i++) { persistentCallData[i] = new PersistentCallData(this, i, indentLevel, position, property, listProperty, menuSelectionHandler, noFunctionHandler); } }