您最多选择25个主题 主题必须以中文或者字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

37 行
1.0 KiB

using System;
namespace Unity.Multiplayer.Samples.BossRoom.Shared.Infrastructure
{
/// <summary>
/// This class is a handle to an active Message Channel subscription and when disposed it unsubscribes from said channel.
/// </summary>
/// <typeparam name="T"></typeparam>
public class DisposableSubscription<T> : IDisposable
{
Action<T> m_Handler;
bool m_IsDisposed;
IMessageChannel<T> m_MessageChannel;
public DisposableSubscription(IMessageChannel<T> messageChannel, Action<T> 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;
}
}
}
}