public void SetupSystem(ISystem system) { var processEntityFunction = CreateEntityProcessorFunction(system); var entityChangeSubscriptions = new CompositeDisposable(); SystemSubscriptions.Add(system, entityChangeSubscriptions); var entitySubscriptions = new Dictionary <int, IDisposable>(); EntitySubscriptions.Add(system, entitySubscriptions); var observableGroup = EntityCollectionManager.GetObservableGroup(system.Group); entityChangeSubscriptions.Add( observableGroup.EntityAdded.Subscribe(x => { var subscription = processEntityFunction(x); entitySubscriptions.Add(x.Id, subscription); }) ); entityChangeSubscriptions.Add( observableGroup.EntityRemoved.Subscribe(x => entitySubscriptions.RemoveAndDispose(x.Id)) ); foreach (var entity in observableGroup) { var subscription = processEntityFunction(entity); entitySubscriptions.Add(entity.Id, subscription); } }
public void SetupSystem(ISystem system) { var observableGroup = EntityCollectionManager.GetObservableGroup(system.Group); var entitySubscriptions = new Dictionary <int, IDisposable>(); var entityChangeSubscriptions = new CompositeDisposable(); SystemSubscriptions.Add(system, entityChangeSubscriptions); var castSystem = (IReactToEntitySystem)system; entityChangeSubscriptions.Add( observableGroup.EntityAdded .Subscribe(entity => { var entitySubscription = ProcessEntity(castSystem, entity); entitySubscriptions.Add(entity.Id, entitySubscription); }) ); entityChangeSubscriptions.Add( observableGroup.EntityRemoved .Subscribe(entity => { entitySubscriptions.RemoveAndDispose(entity.Id); }) ); foreach (var entity in observableGroup) { var entitySubscription = ProcessEntity(castSystem, entity); entitySubscriptions.Add(entity.Id, entitySubscription); } EntitySubscriptions.Add(system, entitySubscriptions); }
public void TeardownSystem(ISystem system) { SystemSubscriptions.RemoveAndDispose(system); var entitySubscriptions = EntitySubscriptions[system]; entitySubscriptions.Values.DisposeAll(); entitySubscriptions.Clear(); EntitySubscriptions.Remove(system); }
public void Dispose() { SystemSubscriptions.DisposeAll(); foreach (var entitySubscriptions in EntitySubscriptions.Values) { entitySubscriptions.Values.DisposeAll(); entitySubscriptions.Clear(); } EntitySubscriptions.Clear(); }