You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
HighGroundRoyaleNetcode/Assets/Scripts/Infrastructure/PubSub/BufferedMessageChannel.cs

30 lines
760 B
C#

using System;
namespace Unity.BossRoom.Infrastructure
{
public class BufferedMessageChannel<T> : MessageChannel<T>, IBufferedMessageChannel<T>
{
public override void Publish(T message)
{
HasBufferedMessage = true;
BufferedMessage = message;
base.Publish(message);
}
public override IDisposable Subscribe(Action<T> handler)
{
var subscription = base.Subscribe(handler);
if (HasBufferedMessage)
{
handler?.Invoke(BufferedMessage);
}
return subscription;
}
public bool HasBufferedMessage { get; private set; } = false;
public T BufferedMessage { get; private set; }
}
}