Ejemplo n.º 1
0
    /// <summary>
    /// Gets a list of all types of EventResponders that could be used for the given event.
    /// </summary>
    /// <param name="eventName">The event to retrieve the types for.</param>
    /// <returns></returns>
    private List <Type> GetApplicableResponderTypesForEvent(EventInfo eventInfo)
    {
        List <Type> applicableTypes = new List <Type>();

        //Since all events are checked to be of type EventHandler<T>, [0] will always be the argument type
        Type eventArgumentsType = eventInfo.EventHandlerType.GetGenericArguments()[0];

        foreach (Type type in Assembly.GetAssembly(typeof(EventResponder)).GetTypes())
        {
            if (!type.IsAbstract && type.IsSubclassOf(typeof(EventResponder)))
            {
                EventResponder tempInstance = (EventResponder)ScriptableObject.CreateInstance(type);

                if (tempInstance.GetHandledType().IsAssignableFrom(eventArgumentsType))
                {
                    applicableTypes.Add(type);
                }

                ScriptableObject.DestroyImmediate(tempInstance);
            }
        }

        return(applicableTypes);
    }