mirror of
https://github.com/misternebula/quantum-space-buddies.git
synced 2025-01-09 03:40:46 +00:00
40 lines
1.2 KiB
C#
40 lines
1.2 KiB
C#
using QSB.Events;
|
|
using QSB.Messaging;
|
|
|
|
namespace QSB.Animation
|
|
{
|
|
public class AnimTriggerEvent : QSBEvent<AnimTriggerMessage>
|
|
{
|
|
public override EventType Type => EventType.AnimTrigger;
|
|
|
|
public override void SetupListener()
|
|
{
|
|
GlobalMessenger<short, float>.AddListener(EventNames.QSBAnimTrigger, Handler);
|
|
}
|
|
|
|
public override void CloseListener()
|
|
{
|
|
GlobalMessenger<short, float>.RemoveListener(EventNames.QSBAnimTrigger, Handler);
|
|
}
|
|
|
|
private void Handler(short triggerId, float value) => SendEvent(CreateMessage(triggerId, value));
|
|
|
|
private AnimTriggerMessage CreateMessage(short triggerId, float value) => new AnimTriggerMessage
|
|
{
|
|
AboutId = LocalPlayerId,
|
|
TriggerId = triggerId,
|
|
Value = value
|
|
};
|
|
|
|
public override void OnReceiveRemote(AnimTriggerMessage message)
|
|
{
|
|
var animationSync = PlayerRegistry.GetSyncObject<AnimationSync>(message.AboutId);
|
|
if (animationSync == null)
|
|
{
|
|
return;
|
|
}
|
|
animationSync.HandleTrigger((AnimTrigger)message.TriggerId, message.Value);
|
|
}
|
|
}
|
|
}
|