quantum-space-buddies/QSB/Utility/LinkedWorldObject/RequestLinksMessage.cs
2022-03-14 05:13:12 -07:00

29 lines
760 B
C#

using Mirror;
using QSB.Messaging;
using QSB.WorldSync;
namespace QSB.Utility.LinkedWorldObject;
/// <summary>
/// sent to the host when all world objects are added.
/// used in order to link world objects to network behaviours.
/// </summary>
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<ILinkedWorldObject<NetworkBehaviour>>())
{
new LinkMessage(worldObject, worldObject.NetworkBehaviour) { To = to }.Send();
}
DebugLog.DebugWrite($"sent world object links to {to}");
}
}