2020-08-22 16:05:09 +00:00
|
|
|
|
using QSB.Events;
|
|
|
|
|
using QSB.Messaging;
|
|
|
|
|
|
|
|
|
|
namespace QSB.Animation
|
|
|
|
|
{
|
|
|
|
|
public class AnimTriggerEvent : QSBEvent<AnimTriggerMessage>
|
|
|
|
|
{
|
2020-08-22 17:08:25 +00:00
|
|
|
|
public override EventType Type => EventType.AnimTrigger;
|
2020-08-22 16:05:09 +00:00
|
|
|
|
|
|
|
|
|
public override void SetupListener()
|
|
|
|
|
{
|
|
|
|
|
GlobalMessenger<short, float>.AddListener(EventNames.QSBAnimTrigger, Handler);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void CloseListener()
|
|
|
|
|
{
|
|
|
|
|
GlobalMessenger<short, float>.RemoveListener(EventNames.QSBAnimTrigger, Handler);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void Handler(short triggerId, float value) => SendEvent(CreateMessage(triggerId, value));
|
|
|
|
|
|
|
|
|
|
private AnimTriggerMessage CreateMessage(short triggerId, float value) => new AnimTriggerMessage
|
|
|
|
|
{
|
|
|
|
|
AboutId = LocalPlayerId,
|
|
|
|
|
TriggerId = triggerId,
|
|
|
|
|
Value = value
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
public override void OnReceiveRemote(AnimTriggerMessage message)
|
|
|
|
|
{
|
|
|
|
|
var animationSync = PlayerRegistry.GetSyncObject<AnimationSync>(message.AboutId);
|
|
|
|
|
if (animationSync == null)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
animationSync.HandleTrigger((AnimTrigger)message.TriggerId, message.Value);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|