quantum-space-buddies/QSB/Animation/Player/Messages/AnimationTriggerMessage.cs

52 lines
1.0 KiB
C#
Raw Normal View History

2021-04-24 00:10:29 +01:00
using QSB.Messaging;
2021-12-25 23:03:23 -08:00
using QSB.Player;
using QSB.WorldSync;
2021-04-24 00:10:29 +01:00
using QuantumUNET.Transport;
namespace QSB.Animation.Player.Messages
2021-04-24 00:10:29 +01:00
{
2021-12-25 23:03:23 -08:00
internal class AnimationTriggerMessage : QSBMessage
2021-04-24 00:10:29 +01:00
{
2021-12-25 23:03:23 -08:00
private uint AttachedNetId;
private string Name;
2021-04-24 00:10:29 +01:00
2021-12-25 23:03:23 -08:00
public AnimationTriggerMessage(uint attachedNetId, string name)
2021-04-24 00:10:29 +01:00
{
2021-12-25 23:03:23 -08:00
AttachedNetId = attachedNetId;
Name = name;
2021-04-24 00:10:29 +01:00
}
public override void Serialize(QNetworkWriter writer)
{
base.Serialize(writer);
writer.Write(AttachedNetId);
writer.Write(Name);
}
2021-12-25 23:03:23 -08:00
public override void Deserialize(QNetworkReader reader)
{
base.Deserialize(reader);
AttachedNetId = reader.ReadUInt32();
Name = reader.ReadString();
}
public override bool ShouldReceive => WorldObjectManager.AllObjectsReady;
public override void OnReceiveRemote()
{
var animationSync = QSBPlayerManager.GetSyncObject<AnimationSync>(AttachedNetId);
if (animationSync == null)
{
return;
}
if (animationSync.VisibleAnimator == null)
{
return;
}
animationSync.VisibleAnimator.SetTrigger(Name);
}
2021-04-24 00:10:29 +01:00
}
}