@@ -15,9 +15,11 @@ public static class EventAggregator
1515 /// </summary>
1616 /// <typeparam name="T">The type of event being listened for.</typeparam>
1717 /// <param name="obj"></param>
18- public static void Register < T > ( this object obj )
18+ public static void Register < T > ( this T obj ) where T : struct
1919 {
20- if ( ! _cache . ContainsKey ( typeof ( T ) ) ) _cache [ typeof ( T ) ] = new List < object > ( ) ;
20+ if ( ! _cache . ContainsKey ( typeof ( T ) ) )
21+ _cache [ typeof ( T ) ] = new List < object > ( ) ;
22+
2123 _cache [ typeof ( T ) ] . Add ( obj ) ;
2224 }
2325
@@ -26,7 +28,7 @@ public static void Register<T>(this object obj)
2628 /// </summary>
2729 /// <typeparam name="T">The type of event to no longer listen for.</typeparam>
2830 /// <param name="obj"></param>
29- public static void UnRegister < T > ( this object obj )
31+ public static void UnRegister < T > ( this T obj ) where T : struct
3032 {
3133 if ( ! _cache . ContainsKey ( typeof ( T ) ) ) return ;
3234 _cache [ typeof ( T ) ] . Remove ( obj ) ;
@@ -37,7 +39,7 @@ public static void UnRegister<T>(this object obj)
3739 /// </summary>
3840 /// <typeparam name="T">The type of event being notified.</typeparam>
3941 /// <param name="message"></param>
40- public static void SendMessage < T > ( T message )
42+ public static void SendMessage < T > ( T message ) where T : struct
4143 {
4244 _cache [ message . GetType ( ) ] . Each ( x => ( ( IListener < T > ) x ) . Handle ( message ) ) ;
4345 }
@@ -46,7 +48,7 @@ public static void SendMessage<T>(T message)
4648 /// Creates the cache for objects that listen to each event
4749 /// </summary>
4850 /// <typeparam name="T">Searches through all active GameObjects for those listening for event T and auto registers them.</typeparam>
49- public static void UpdateCache < T > ( )
51+ public static void UpdateCache < T > ( ) where T : struct
5052 {
5153 var type = typeof ( IListener < T > ) ;
5254 var list = new List < object > ( ) ;
0 commit comments