quantum-space-buddies/QSB/EyeOfTheUniverse/EyeStateSync/Messages/EyeStateMessage.cs

35 lines
832 B
C#
Raw Normal View History

using QSB.Messaging;
2021-12-23 20:33:30 +00:00
using QSB.Player;
using QSB.Player.TransformSync;
2021-12-23 20:33:30 +00:00
using QSB.WorldSync;
2021-12-23 23:44:32 +00:00
namespace QSB.EyeOfTheUniverse.EyeStateSync.Messages
2021-12-23 20:33:30 +00:00
{
internal class EyeStateMessage : QSBEnumMessage<EyeState>
{
static EyeStateMessage() => GlobalMessenger<EyeState>.AddListener(OWEvents.EyeStateChanged, Handler);
private static void Handler(EyeState state)
{
2021-12-24 06:40:37 +00:00
if (PlayerTransformSync.LocalInstance)
{
new EyeStateMessage(state).Send();
}
}
2021-12-23 20:33:30 +00:00
2021-12-23 22:27:41 +00:00
private EyeStateMessage(EyeState state) => Value = state;
2021-12-23 20:33:30 +00:00
public override bool ShouldReceive => WorldObjectManager.AllObjectsReady;
public override void OnReceiveLocal()
{
QSBPlayerManager.LocalPlayer.EyeState = Value;
}
public override void OnReceiveRemote()
{
var player = QSBPlayerManager.GetPlayer(From);
player.EyeState = Value;
}
}
}