32 lines
898 B
C#
Raw Normal View History

2020-12-14 16:24:52 +00:00
using QSB.Events;
2020-12-14 16:28:03 +00:00
using QSB.Messaging;
2020-11-08 16:10:10 +00:00
using QSB.Player;
namespace QSB.Animation.Events
{
2020-12-02 21:23:01 +00:00
public class CrouchEvent : QSBEvent<FloatMessage>
{
public override EventType Type => EventType.AnimTrigger;
2020-11-08 16:10:10 +00:00
2020-12-02 21:23:01 +00:00
public override void SetupListener() => GlobalMessenger<float>.AddListener(EventNames.QSBCrouch, Handler);
public override void CloseListener() => GlobalMessenger<float>.RemoveListener(EventNames.QSBCrouch, Handler);
2020-11-08 16:10:10 +00:00
2020-12-02 21:23:01 +00:00
private void Handler(float value) => SendEvent(CreateMessage(value));
2020-11-08 16:10:10 +00:00
2020-12-02 21:23:01 +00:00
private FloatMessage CreateMessage(float value) => new FloatMessage
{
AboutId = LocalPlayerId,
Value = value
};
2020-11-08 16:10:10 +00:00
2020-12-11 22:42:21 +00:00
public override void OnReceiveRemote(bool server, FloatMessage message)
2020-12-02 21:23:01 +00:00
{
2020-12-19 10:56:25 +00:00
if (!QSBCore.HasWokenUp)
{
return;
}
2020-12-02 21:23:01 +00:00
var animationSync = QSBPlayerManager.GetSyncObject<AnimationSync>(message.AboutId);
2020-12-11 23:13:13 +00:00
animationSync?.HandleCrouch(message.Value);
2020-12-02 21:23:01 +00:00
}
}
2020-11-08 16:13:10 +00:00
}