using System; using System.Collections.Generic; namespace UnityAtoms { public class ObservableVoidEvent : IObservable { private Action _unregister = default(Action); private List> _observers = new List>(); public ObservableVoidEvent(Action register, Action unregister) { register(NotifyObservers); } ~ObservableVoidEvent() { if (_unregister != null) { _unregister(NotifyObservers); } } public IDisposable Subscribe(IObserver observer) { if (!_observers.Contains(observer)) _observers.Add(observer); return new ObservableUnsubscriber(_observers, observer); } private void NotifyObservers() { for (int i = 0; _observers != null && i < _observers.Count; ++i) { _observers[i].OnNext(new Void()); } } } }