diff --git a/EgoEvents.cs b/EgoEvents.cs index b418607..93eaa51 100644 --- a/EgoEvents.cs +++ b/EgoEvents.cs @@ -5,26 +5,26 @@ public static class EgoEvents { - static List _firstEvents = new List(); - static List _lastEvents = new List(); - - static List _userOrderedFirstEvents = new List(); - static List _userOrderedLastEvents = new List(); - - static HashSet _unorderedEvents = new HashSet(); - public static HashSet unorderedEvents - { - get { return _unorderedEvents; } - } - - static Dictionary _invokeLookup = new Dictionary(); - public static Dictionary invokeLookup - { - get { return _invokeLookup; } - } - - public static void Start() - { + static List _firstEvents = new List(); + static List _lastEvents = new List(); + + static List _userOrderedFirstEvents = new List(); + static List _userOrderedLastEvents = new List(); + + static HashSet _unorderedEvents = new HashSet(); + public static HashSet unorderedEvents + { + get { return _unorderedEvents; } + } + + static Dictionary _invokeLookup = new Dictionary(); + public static Dictionary invokeLookup + { + get { return _invokeLookup; } + } + + public static void Start() + { foreach( var assembly in AppDomain.CurrentDomain.GetAssemblies() ) { foreach( var type in assembly.GetTypes() ) @@ -39,28 +39,28 @@ public static void Start() _firstEvents.Add( typeof( AddedGameObject ) ); _unorderedEvents.Remove( typeof( AddedGameObject ) ); - _lastEvents.Add( typeof( DestroyedGameObject ) ); + _lastEvents.Add( typeof( DestroyedGameObject ) ); _unorderedEvents.Remove( typeof( DestroyedGameObject ) ); - - ComponentIDs.componentTypes.ForEach( componentType => - { - MakeComponentEventInvoke( componentType, typeof( AddedComponent<> ), ref _firstEvents ); - MakeComponentEventInvoke( componentType, typeof( DestroyedComponent<> ), ref _lastEvents ); - } ); + + ComponentIDs.componentTypes.ForEach( componentType => + { + MakeComponentEventInvoke( componentType, typeof( AddedComponent<> ), ref _firstEvents ); + MakeComponentEventInvoke( componentType, typeof( DestroyedComponent<> ), ref _lastEvents ); + } ); _unorderedEvents.ExceptWith( _firstEvents ); _unorderedEvents.ExceptWith( _userOrderedFirstEvents ); _unorderedEvents.ExceptWith( _userOrderedLastEvents ); _unorderedEvents.ExceptWith( _lastEvents ); - } + } - public static void AddToFirstEvents() where E : EgoEvent + public static void AddFront() where E : EgoEvent { var e = typeof( E ); _userOrderedFirstEvents.Add( e ); } - public static void AddToLastEvents() where E : EgoEvent + public static void AddEnd() where E : EgoEvent { var e = typeof( E ); _userOrderedLastEvents.Add( e ); @@ -76,7 +76,7 @@ static void MakeComponentEventInvoke( Type eventType, Type genericComponentEvent { var componentEventType = genericComponentEventType.MakeGenericType( eventType ); var fullEventType = typeof( EgoEvents<> ).MakeGenericType( componentEventType ); - fullEventType.GetMethod("Init", System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.NonPublic ).Invoke( null, null ); + fullEventType.GetMethod( "Init", System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.NonPublic ).Invoke( null, null ); eventList.Add( componentEventType ); } @@ -91,10 +91,10 @@ public static void Invoke() } public static class EgoEvents - where E : EgoEvent + where E : EgoEvent { - static List _events = new List(); - static List> _handlers = new List>(); + static List _events = new List(); + static List> _handlers = new List>(); static EgoEvents() { @@ -109,43 +109,43 @@ static void Init() EgoEvents.unorderedEvents.Add( e ); } - static void Invoke() - { - var length = _events.Count; - for( int i = 0; i < length; i++ ) - { - foreach( var handler in _handlers ) - { + static void Invoke() + { + var length = _events.Count; + for( int i = 0; i < length; i++ ) + { + foreach( var handler in _handlers ) + { #if UNITY_EDITOR - EgoSystem system = null; - if( handler.Target is EgoSystem ) - { - system = handler.Target as EgoSystem; - } - else if( handler.Target is EgoConstraint ) - { - system = ( handler.Target as EgoConstraint ).system; - } - - if( system != null && system.enabled ) - { - handler( _events[i] ); - } + EgoSystem system = null; + if( handler.Target is EgoSystem ) + { + system = handler.Target as EgoSystem; + } + else if( handler.Target is EgoConstraint ) + { + system = ( handler.Target as EgoConstraint ).system; + } + + if( system != null && system.enabled ) + { + handler( _events[ i ] ); + } #else handler( _events[i] ); #endif - } - } - _events.RemoveRange( 0, length ); - } - - public static void AddHandler( Action handler ) - { - _handlers.Add( handler ); - } - - public static void AddEvent( E e ) - { - _events.Add( e ); - } + } + } + _events.RemoveRange( 0, length ); + } + + public static void AddHandler( Action handler ) + { + _handlers.Add( handler ); + } + + public static void AddEvent( E e ) + { + _events.Add( e ); + } } \ No newline at end of file