quantum-space-buddies/QSB/Utility/LinkedWorldObject/LinkMessage.cs
2022-03-14 03:34:00 -07:00

25 lines
742 B
C#

using Mirror;
using QSB.Messaging;
using QSB.WorldSync;
namespace QSB.Utility.LinkedWorldObject;
/// <summary>
/// sent from the host to a non-host
/// telling a world object and network behaviour to link
/// </summary>
public class LinkMessage : QSBMessage<(int ObjectId, uint NetId)>
{
public LinkMessage(IWorldObject worldObject, NetworkBehaviour networkBehaviour) :
base((worldObject.ObjectId, networkBehaviour.netId)) { }
public override void OnReceiveRemote()
{
var worldObject = Data.ObjectId.GetWorldObject<ILinkedWorldObject<NetworkBehaviour>>();
var identity = NetworkClient.spawned[Data.NetId];
var networkBehaviour = identity.GetComponent<ILinkedNetworkBehaviour>();
worldObject.LinkTo(networkBehaviour);
}
}