/// <summary> /// Create the event and setup the values from the inspector /// </summary> /// <param name="iEvent"></param> /// <param name="lists"></param> /// <returns></returns> public static ReceiverBase GetReceiver(InteractableEvent iEvent, EventLists lists) { int index = InspectorField.ReverseLookup(iEvent.ClassName, lists.EventNames.ToArray()); Type eventType = lists.EventTypes[index]; // apply the settings? ReceiverBase newEvent = (ReceiverBase)Activator.CreateInstance(eventType, iEvent.Event); InspectorGenericFields <ReceiverBase> .LoadSettings(newEvent, iEvent.Settings); return(newEvent); }
/// <summary> /// Add new events/receivers to the list and grab all the InspectorFields so we can render them in the inspector /// </summary> /// <param name="type"></param> /// <returns></returns> public ReceiverData AddReceiver(Type type) { ReceiverBase receiver = (ReceiverBase)Activator.CreateInstance(type, Event); // get the settings for the inspector List <InspectorFieldData> fields = new List <InspectorFieldData>(); Type myType = receiver.GetType(); int index = 0; ReceiverData data = new ReceiverData(); foreach (PropertyInfo prop in myType.GetProperties()) { var attrs = (InspectorField[])prop.GetCustomAttributes(typeof(InspectorField), false); foreach (var attr in attrs) { fields.Add(new InspectorFieldData() { Name = prop.Name, Attributes = attr, Value = prop.GetValue(receiver, null) }); } index++; } index = 0; foreach (FieldInfo field in myType.GetFields()) { var attrs = (InspectorField[])field.GetCustomAttributes(typeof(InspectorField), false); foreach (var attr in attrs) { fields.Add(new InspectorFieldData() { Name = field.Name, Attributes = attr, Value = field.GetValue(receiver) }); } index++; } data.Fields = fields; data.Name = receiver.Name; data.HideUnityEvents = receiver.HideUnityEvents; return(data); }