2020-08-13 21:46:16 +02:00
|
|
|
|
using QSB.Events;
|
|
|
|
|
using QSB.Messaging;
|
2020-08-09 13:54:05 +01:00
|
|
|
|
using QSB.Utility;
|
2020-08-16 17:15:36 +02:00
|
|
|
|
using QSB.WorldSync;
|
2020-08-09 12:38:35 +01:00
|
|
|
|
|
2020-08-13 21:46:16 +02:00
|
|
|
|
namespace QSB.TransformSync
|
2020-08-09 12:38:35 +01:00
|
|
|
|
{
|
2020-08-16 17:15:36 +02:00
|
|
|
|
public class PlayerSectorEvent : QSBEvent<WorldObjectMessage>
|
2020-08-09 12:38:35 +01:00
|
|
|
|
{
|
|
|
|
|
public override MessageType Type => MessageType.PlayerSectorChange;
|
|
|
|
|
|
|
|
|
|
public override void SetupListener()
|
|
|
|
|
{
|
2020-08-17 12:00:31 +01:00
|
|
|
|
GlobalMessenger<uint, QSBSector>.AddListener(EventNames.QSBSectorChange, Handler);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void CloseListener()
|
|
|
|
|
{
|
|
|
|
|
GlobalMessenger<uint, QSBSector>.RemoveListener(EventNames.QSBSectorChange, Handler);
|
2020-08-09 12:38:35 +01:00
|
|
|
|
}
|
2020-08-15 21:55:25 +02:00
|
|
|
|
|
2020-08-17 11:58:50 +01:00
|
|
|
|
private void Handler(uint netId, QSBSector sector) => SendEvent(CreateMessage(netId, sector));
|
2020-08-15 21:55:25 +02:00
|
|
|
|
|
2020-08-16 17:15:36 +02:00
|
|
|
|
private WorldObjectMessage CreateMessage(uint netId, QSBSector sector) => new WorldObjectMessage
|
2020-08-10 18:17:54 +02:00
|
|
|
|
{
|
|
|
|
|
SenderId = netId,
|
2020-08-16 17:15:36 +02:00
|
|
|
|
ObjectId = sector.ObjectId
|
2020-08-10 18:17:54 +02:00
|
|
|
|
};
|
|
|
|
|
|
2020-08-16 17:15:36 +02:00
|
|
|
|
public override void OnReceiveRemote(WorldObjectMessage message)
|
2020-08-09 12:38:35 +01:00
|
|
|
|
{
|
2020-08-16 22:39:21 +02:00
|
|
|
|
if (!QSBSceneManager.IsInUniverse)
|
2020-08-10 20:14:19 +02:00
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
2020-08-16 17:15:36 +02:00
|
|
|
|
var sector = WorldRegistry.GetObject<QSBSector>(message.ObjectId);
|
2020-08-09 13:54:05 +01:00
|
|
|
|
|
|
|
|
|
if (sector == null)
|
|
|
|
|
{
|
2020-08-16 17:35:27 +02:00
|
|
|
|
DebugLog.ToConsole($"Sector with order id {message.ObjectId} not found!");
|
2020-08-09 13:54:05 +01:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var transformSync = PlayerRegistry.GetTransformSync(message.SenderId);
|
2020-08-16 17:35:27 +02:00
|
|
|
|
//DebugLog.ToConsole($"{transformSync.GetType().Name} of ID {message.SenderId} set to {sector.Name}");
|
2020-08-14 22:59:18 +02:00
|
|
|
|
UnityHelper.Instance.RunWhen(() => transformSync.SyncedTransform != null,
|
2020-08-14 23:00:56 +02:00
|
|
|
|
() => transformSync.SetReferenceSector(sector));
|
2020-08-09 12:38:35 +01:00
|
|
|
|
}
|
2020-08-13 17:44:27 +01:00
|
|
|
|
|
2020-08-09 12:38:35 +01:00
|
|
|
|
}
|
|
|
|
|
}
|