quantum-space-buddies/QSB/Animation/Player/Events/AnimationTriggerEvent.cs

29 lines
1019 B
C#
Raw Normal View History

2021-04-27 22:49:12 +01:00
using QSB.Events;
2021-04-24 00:10:29 +01:00
using QSB.Player;
2021-04-26 14:30:21 +01:00
namespace QSB.Animation.Player.Events
2021-04-24 00:10:29 +01:00
{
2021-04-27 22:49:12 +01:00
internal class AnimationTriggerEvent : QSBEvent<AnimationTriggerMessage>
2021-04-24 00:10:29 +01:00
{
public override EventType Type => EventType.AnimTrigger;
public override void SetupListener() => GlobalMessenger<uint, string>.AddListener(EventNames.QSBAnimTrigger, Handler);
public override void CloseListener() => GlobalMessenger<uint, string>.RemoveListener(EventNames.QSBAnimTrigger, Handler);
private void Handler(uint attachedNetId, string name) => SendEvent(CreateMessage(attachedNetId, name));
private AnimationTriggerMessage CreateMessage(uint attachedNetId, string name) => new AnimationTriggerMessage
{
AboutId = LocalPlayerId,
AttachedNetId = attachedNetId,
Name = name
};
public override void OnReceiveRemote(bool server, AnimationTriggerMessage message)
{
var animationSync = QSBPlayerManager.GetSyncObject<AnimationSync>(message.AttachedNetId);
animationSync.VisibleAnimator.SetTrigger(message.Name);
}
}
}