using Mirror;
using QSB.Messaging;
using QSB.WorldSync;
namespace QSB.Utility.LinkedWorldObject;
///
/// sent to the host when all world objects are added.
/// used in order to link world objects to network behaviours.
///
public class RequestLinksMessage : QSBMessage
{
public RequestLinksMessage() => To = 0;
public override void OnReceiveRemote() =>
Delay.RunWhen(() => QSBWorldSync.AllObjectsAdded,
() => SendLinks(From));
private static void SendLinks(uint to)
{
foreach (var worldObject in QSBWorldSync.GetWorldObjects>())
{
new LinkMessage(worldObject, worldObject.NetworkBehaviour) { To = to }.Send();
}
DebugLog.DebugWrite($"sent world object links to {to}");
}
}