public void LateDispose() { if (_settings.RequireStrictUnsubscribe) { if (!_subscriptionMap.IsEmpty()) { throw Assert.CreateException( "Found subscriptions for signals '{0}' in SignalBus.LateDispose! Either add the explicit Unsubscribe or set SignalSettings.AutoUnsubscribeInDispose to true", _subscriptionMap.Values.Select(x => x.SignalId.ToString()).Join(", ")); } } else { foreach (var subscription in _subscriptionMap.Values) { subscription.Dispose(); } } foreach (var declaration in _localDeclarationMap.Values) { declaration.Dispose(); } #if UNITY_EDITOR StaticSignalBusRegistry.Remove(this); #endif }
public SignalBus( [Inject(Source = InjectSources.Local)] List <SignalDeclaration> signalDeclarations, [Inject(Source = InjectSources.Parent, Optional = true)] SignalBus parentBus, [InjectOptional] ZenjectSettings zenjectSettings, SignalSubscription.Pool subscriptionPool, SignalDeclaration.Factory signalDeclarationFactory, DiContainer container) { _subscriptionPool = subscriptionPool; zenjectSettings = zenjectSettings ?? ZenjectSettings.Default; _settings = zenjectSettings.Signals ?? ZenjectSettings.SignalSettings.Default; _signalDeclarationFactory = signalDeclarationFactory; _container = container; signalDeclarations.ForEach(x => { if (!_localDeclarationMap.ContainsKey(x.BindingId)) { _localDeclarationMap.Add(x.BindingId, x); } else { _localDeclarationMap[x.BindingId].Subscriptions.AllocFreeAddRange(x.Subscriptions); } }); _parentBus = parentBus; #if UNITY_EDITOR StaticSignalBusRegistry.Add(this); #endif }