2021-04-27 22:49:12 +01:00
|
|
|
|
using QSB.Events;
|
2021-04-24 00:10:29 +01:00
|
|
|
|
using QSB.Player;
|
|
|
|
|
|
2021-12-23 16:26:31 -08:00
|
|
|
|
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
|
|
|
|
{
|
2021-12-05 11:03:09 +00:00
|
|
|
|
public override bool RequireWorldObjectsReady => true;
|
2021-12-04 16:39:37 +00:00
|
|
|
|
|
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);
|
2021-12-04 16:39:37 +00:00
|
|
|
|
if (animationSync == null)
|
2021-05-07 22:00:56 +01:00
|
|
|
|
{
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|