39 lines
1.1 KiB
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;
namespace QSB.Animation.Player.Messages
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 bool RequireWorldObjectsReady => true;
2021-04-24 00:10:29 +01:00
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));
2021-11-20 19:49:50 +00:00
private AnimationTriggerMessage CreateMessage(uint attachedNetId, string name) => new()
2021-04-24 00:10:29 +01:00
{
AboutId = LocalPlayerId,
AttachedNetId = attachedNetId,
Name = name
};
public override void OnReceiveRemote(bool server, AnimationTriggerMessage message)
{
2021-05-19 11:17:19 +01:00
var animationSync = QSBPlayerManager.GetSyncObject<AnimationSync>(message.AttachedNetId);
if (animationSync == null)
{
return;
}
2021-06-18 22:38:32 +01:00
2021-12-10 22:13:39 +00:00
if (animationSync.VisibleAnimator == null)
{
return;
}
2021-04-24 00:10:29 +01:00
animationSync.VisibleAnimator.SetTrigger(message.Name);
}
}
}