mirror of
https://github.com/misternebula/quantum-space-buddies.git
synced 2025-01-26 18:35:34 +00:00
42cb791c5d
Co-authored-by: Mister_Nebula <41904486+misternebula@users.noreply.github.com>
45 lines
1.4 KiB
C#
45 lines
1.4 KiB
C#
using QSB.Events;
|
|
using QSB.Messaging;
|
|
using QSB.Utility;
|
|
using QSB.WorldSync;
|
|
|
|
namespace QSB.TransformSync
|
|
{
|
|
public class PlayerSectorEvent : QSBEvent<WorldObjectMessage>
|
|
{
|
|
public override MessageType Type => MessageType.PlayerSectorChange;
|
|
|
|
public override void SetupListener()
|
|
{
|
|
GlobalMessenger<uint, QSBSector>.AddListener(EventNames.QSBSectorChange, (netId, sector) => SendEvent(CreateMessage(netId, sector)));
|
|
}
|
|
|
|
private WorldObjectMessage CreateMessage(uint netId, QSBSector sector) => new WorldObjectMessage
|
|
{
|
|
SenderId = netId,
|
|
ObjectId = sector.ObjectId
|
|
};
|
|
|
|
public override void OnReceiveRemote(WorldObjectMessage message)
|
|
{
|
|
if (!IsInUniverse)
|
|
{
|
|
return;
|
|
}
|
|
var sector = WorldRegistry.GetObject<QSBSector>(message.ObjectId);
|
|
|
|
if (sector == null)
|
|
{
|
|
DebugLog.ToConsole($"Sector with order id {message.ObjectId} not found!");
|
|
return;
|
|
}
|
|
|
|
var transformSync = PlayerRegistry.GetTransformSync(message.SenderId);
|
|
//DebugLog.ToConsole($"{transformSync.GetType().Name} of ID {message.SenderId} set to {sector.Name}");
|
|
UnityHelper.Instance.RunWhen(() => transformSync.SyncedTransform != null,
|
|
() => transformSync.SetReferenceSector(sector));
|
|
}
|
|
|
|
}
|
|
}
|