using System; namespace Unity.Multiplayer.Samples.BossRoom.Shared.Infrastructure { /// /// This class is a handle to an active Message Channel subscription and when disposed it unsubscribes from said channel. /// /// public class DisposableSubscription : IDisposable { Action m_Handler; bool m_IsDisposed; IMessageChannel m_MessageChannel; public DisposableSubscription(IMessageChannel messageChannel, Action handler) { m_MessageChannel = messageChannel; m_Handler = handler; } public void Dispose() { if (!m_IsDisposed) { m_IsDisposed = true; if (!m_MessageChannel.IsDisposed) { m_MessageChannel.Unsubscribe(m_Handler); } m_Handler = null; m_MessageChannel = null; } } } }