Skip to content
This repository has been archived by the owner on Dec 20, 2022. It is now read-only.

Commit

Permalink
Renamed "AddToFirstEvents" and "AddToLastEvents" to "AddFront" and "A…
Browse files Browse the repository at this point in the history
…ddEnd", respectively.
  • Loading branch information
andoowhy committed Feb 25, 2017
1 parent 17748c6 commit 2892245
Showing 1 changed file with 69 additions and 69 deletions.
138 changes: 69 additions & 69 deletions EgoEvents.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,26 @@

public static class EgoEvents
{
static List<Type> _firstEvents = new List<Type>();
static List<Type> _lastEvents = new List<Type>();

static List<Type> _userOrderedFirstEvents = new List<Type>();
static List<Type> _userOrderedLastEvents = new List<Type>();

static HashSet<Type> _unorderedEvents = new HashSet<Type>();
public static HashSet<Type> unorderedEvents
{
get { return _unorderedEvents; }
}

static Dictionary<Type, Action> _invokeLookup = new Dictionary<Type, Action>();
public static Dictionary<Type, Action> invokeLookup
{
get { return _invokeLookup; }
}

public static void Start()
{
static List<Type> _firstEvents = new List<Type>();
static List<Type> _lastEvents = new List<Type>();

static List<Type> _userOrderedFirstEvents = new List<Type>();
static List<Type> _userOrderedLastEvents = new List<Type>();

static HashSet<Type> _unorderedEvents = new HashSet<Type>();
public static HashSet<Type> unorderedEvents
{
get { return _unorderedEvents; }
}

static Dictionary<Type, Action> _invokeLookup = new Dictionary<Type, Action>();
public static Dictionary<Type, Action> invokeLookup
{
get { return _invokeLookup; }
}

public static void Start()
{
foreach( var assembly in AppDomain.CurrentDomain.GetAssemblies() )
{
foreach( var type in assembly.GetTypes() )
Expand All @@ -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<E>() where E : EgoEvent
public static void AddFront<E>() where E : EgoEvent
{
var e = typeof( E );
_userOrderedFirstEvents.Add( e );
}

public static void AddToLastEvents<E>() where E : EgoEvent
public static void AddEnd<E>() where E : EgoEvent
{
var e = typeof( E );
_userOrderedLastEvents.Add( e );
Expand All @@ -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 );
}

Expand All @@ -91,10 +91,10 @@ public static void Invoke()
}

public static class EgoEvents<E>
where E : EgoEvent
where E : EgoEvent
{
static List<E> _events = new List<E>();
static List<Action<E>> _handlers = new List<Action<E>>();
static List<E> _events = new List<E>();
static List<Action<E>> _handlers = new List<Action<E>>();

static EgoEvents()
{
Expand All @@ -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<E> handler )
{
_handlers.Add( handler );
}

public static void AddEvent( E e )
{
_events.Add( e );
}
}
}
_events.RemoveRange( 0, length );
}

public static void AddHandler( Action<E> handler )
{
_handlers.Add( handler );
}

public static void AddEvent( E e )
{
_events.Add( e );
}
}

0 comments on commit 2892245

Please sign in to comment.