quantum-space-buddies/QSB/Utility/LinkedWorldObject/RequestLinksMessage.cs

29 lines
760 B
C#
Raw Normal View History

using Mirror;
using QSB.Messaging;
2022-03-14 07:51:25 +00:00
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>>())
2022-03-14 07:51:25 +00:00
{
new LinkMessage(worldObject, worldObject.NetworkBehaviour) { To = to }.Send();
}
2022-03-14 12:13:12 +00:00
DebugLog.DebugWrite($"sent world object links to {to}");
2022-03-14 07:51:25 +00:00
}
}