2020-11-08 16:10:10 +00:00
|
|
|
|
using QSB.EventsCore;
|
|
|
|
|
using QSB.MessagesCore;
|
|
|
|
|
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-02 21:23:01 +00:00
|
|
|
|
public override void OnReceiveRemote(FloatMessage message)
|
|
|
|
|
{
|
|
|
|
|
var animationSync = QSBPlayerManager.GetSyncObject<AnimationSync>(message.AboutId);
|
|
|
|
|
if (animationSync == null)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
animationSync.HandleCrouch(message.Value);
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-11-08 16:13:10 +00:00
|
|
|
|
}
|