2020-08-22 18:08:25 +01:00
|
|
|
|
using OWML.Common;
|
|
|
|
|
using QSB.Events;
|
2020-08-13 21:46:16 +02:00
|
|
|
|
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
|
|
|
|
{
|
2020-08-22 18:08:25 +01:00
|
|
|
|
public override EventType Type => EventType.PlayerSectorChange;
|
2020-08-09 12:38:35 +01:00
|
|
|
|
|
|
|
|
|
public override void SetupListener()
|
|
|
|
|
{
|
2020-09-04 20:09:25 +01:00
|
|
|
|
GlobalMessenger<uint, QSBSector>.AddListener(EventNames.QSBSectorChange, Handler);
|
2020-08-17 12:00:31 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void CloseListener()
|
|
|
|
|
{
|
2020-09-04 20:09:25 +01:00
|
|
|
|
GlobalMessenger<uint, QSBSector>.RemoveListener(EventNames.QSBSectorChange, Handler);
|
2020-08-09 12:38:35 +01:00
|
|
|
|
}
|
2020-08-15 21:55:25 +02:00
|
|
|
|
|
2020-09-04 20:09:25 +01:00
|
|
|
|
private void Handler(uint netId, QSBSector sector) => SendEvent(CreateMessage(netId, sector));
|
2020-08-15 21:55:25 +02:00
|
|
|
|
|
2020-09-04 20:09:25 +01:00
|
|
|
|
private WorldObjectMessage CreateMessage(uint netId, QSBSector sector) => new WorldObjectMessage
|
2020-08-10 18:17:54 +02:00
|
|
|
|
{
|
2020-08-17 16:51:56 +01:00
|
|
|
|
AboutId = 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-22 18:08:25 +01:00
|
|
|
|
DebugLog.ToConsole($"Sector with order id {message.ObjectId} not found!", MessageType.Warning);
|
2020-08-09 13:54:05 +01:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-31 09:36:29 +01:00
|
|
|
|
var transformSync = PlayerRegistry.GetSyncObject<TransformSync>(message.AboutId);
|
2020-08-18 14:00:37 +01:00
|
|
|
|
|
2020-09-07 20:31:39 +01:00
|
|
|
|
QSB.Helper.Events.Unity.RunWhen(() => transformSync?.SyncedTransform != null,
|
|
|
|
|
() => 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
|
|
|
|
}
|
|
|
|
|
}
|