/// <summary> /// Called when a PlayerManagerListener is being destroyed. Removes it from memory and removes this /// function from the destroyed manager's event handler. /// </summary> /// <param name="sender"></param> /// <param name="args"></param> private void OnDestroyingListener(object sender, EventArgs args) { PlayerManagerListener listener = sender as PlayerManagerListener; if (listener == null) { throw new Exception("Destroyed listener is not a PlayerManagerListener!"); } _listeners.Remove(listener.Manager); listener.OnDestroy -= OnDestroyingListener; }
/// <summary> /// Called whenever a new PlayerEntityManager is being created. Creates a PlayerManagerListener /// for the newly created manager. /// </summary> /// <param name="sender"></param> /// <param name="args"></param> private void OnCreated(object sender, PlayerEntityManagerCreatedEventArgs args) { if (args.CreatedManager == null) { throw new Exception("IPlayerEntityManagerStore created null PlayerEntityManager!"); } var listener = new PlayerManagerListener(args.CreatedManager, _battleListenerContainer, _hubContext); _listeners.Add(args.CreatedManager, listener); listener.OnDestroy += OnDestroyingListener; }