Last active
February 10, 2017 11:22
-
-
Save kdrzymala/c2a96df48bb3dcbc06f8f27c246b8b1d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class BetterEvent | |
{ | |
private List<System.Action> _list; | |
public BetterEvent( int prealocate = 10 ) | |
{ | |
_list = new List<System.Action>( prealocate ); | |
} | |
public void Add( System.Action callback ) | |
{ | |
_list.Add( callback ); | |
} | |
public void Remove( System.Action callback ) | |
{ | |
_list.Remove( callback ); | |
} | |
public void Invoke() | |
{ | |
for ( int i = 0; i < _list.Count; i++ ) { | |
_list[i].Invoke(); | |
} | |
} | |
public void Clear() | |
{ | |
_list.Clear(); | |
} | |
} | |
public class BetterEvent<T> | |
{ | |
private List<System.Action<T>> _list; | |
public BetterEvent( int prealocate = 10 ) | |
{ | |
_list = new List<System.Action<T>>( prealocate ); | |
} | |
public void Add( System.Action<T> callback ) | |
{ | |
_list.Add( callback ); | |
} | |
public void Remove( System.Action<T> callback ) | |
{ | |
_list.Remove( callback ); | |
} | |
public void Invoke( T args ) | |
{ | |
for ( int i = 0; i < _list.Count; i++ ) { | |
_list[i].Invoke( args ); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment