using System; namespace Svelto.Observer { public abstract class Observer: IObserver { public Observer(Observable observable) { observable.Notify += OnObservableDispatched; _unsubscribe = () => observable.Notify -= OnObservableDispatched; } public void AddAction(Action action) { _actions += action; } public void RemoveAction(Action action) { _actions += action; } public void Unsubscribe() { _unsubscribe(); } private void OnObservableDispatched(DispatchType dispatchNotification) { _actions(TypeMap(dispatchNotification)); } abstract protected ActionType TypeMap(DispatchType dispatchNotification); Action _actions; Action _unsubscribe; } public class Observer: Observer { public Observer(Observable observable):base(observable) {} protected override DispatchType TypeMap(DispatchType dispatchNotification) { return dispatchNotification; } } public interface IObserver { void AddAction(Action action); void RemoveAction(Action action); void Unsubscribe(); } }