Skip to content

Instantly share code, notes, and snippets.

@kdrzymala
Last active February 10, 2017 11:22
Show Gist options
  • Save kdrzymala/c2a96df48bb3dcbc06f8f27c246b8b1d to your computer and use it in GitHub Desktop.
Save kdrzymala/c2a96df48bb3dcbc06f8f27c246b8b1d to your computer and use it in GitHub Desktop.
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