using System.Collections; using System.Collections.Generic; using System.Text; using System; using System.Linq; namespace Rokojori { public class EventSlot { protected List> _actions = new List>(); List> _once = new List>(); public bool hasListeners => _once.Count > 0 || _actions.Count > 0; public void AddAction( Action action ) { _actions.Add( action ); } public void RemoveAction( Action action ) { _actions.Remove( action ); } public void Once( Action action ) { _actions.Add( action ); _once.Add( action ); } protected void _ClearOnceActions() { _once.ForEach( a => { _actions.Remove( a ); } ); _once.Clear(); } public void DispatchEvent( T t ) { _actions.ForEach( a => { if ( a != null ){ a( t ); } } ); _ClearOnceActions(); } } }