2020-08-22 18:08:25 +01:00
|
|
|
|
using OWML.Common;
|
2020-11-03 21:42:14 +00:00
|
|
|
|
using QSB.EventsCore;
|
2020-11-03 22:29:23 +00:00
|
|
|
|
using QSB.SectorSync;
|
2020-08-09 13:54:05 +01:00
|
|
|
|
using QSB.Utility;
|
2020-08-16 17:15:36 +02:00
|
|
|
|
using QSB.WorldSync;
|
2020-11-03 22:18:22 +00:00
|
|
|
|
using QSB.WorldSync.Events;
|
2020-08-09 12:38:35 +01:00
|
|
|
|
|
2020-11-03 22:29:23 +00:00
|
|
|
|
namespace QSB.Player.Events
|
2020-08-09 12:38:35 +01:00
|
|
|
|
{
|
2020-12-02 21:23:01 +00:00
|
|
|
|
public class PlayerSectorEvent : QSBEvent<WorldObjectMessage>
|
|
|
|
|
{
|
|
|
|
|
public override EventType Type => EventType.PlayerSectorChange;
|
|
|
|
|
|
|
|
|
|
public override void SetupListener()
|
|
|
|
|
{
|
|
|
|
|
GlobalMessenger<uint, QSBSector>.AddListener(EventNames.QSBSectorChange, Handler);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void CloseListener()
|
|
|
|
|
{
|
|
|
|
|
GlobalMessenger<uint, QSBSector>.RemoveListener(EventNames.QSBSectorChange, Handler);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void Handler(uint netId, QSBSector sector) => SendEvent(CreateMessage(netId, sector));
|
|
|
|
|
|
|
|
|
|
private WorldObjectMessage CreateMessage(uint netId, QSBSector sector) => new WorldObjectMessage
|
|
|
|
|
{
|
|
|
|
|
AboutId = netId,
|
|
|
|
|
ObjectId = sector.ObjectId
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
public override void OnReceiveRemote(WorldObjectMessage message)
|
|
|
|
|
{
|
|
|
|
|
if (!QSBSceneManager.IsInUniverse)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
var sector = WorldRegistry.GetObject<QSBSector>(message.ObjectId);
|
|
|
|
|
|
|
|
|
|
if (sector == null)
|
|
|
|
|
{
|
|
|
|
|
DebugLog.ToConsole($"Sector with order id {message.ObjectId} not found!", MessageType.Warning);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var transformSync = QSBPlayerManager.GetSyncObject<TransformSync.TransformSync>(message.AboutId);
|
|
|
|
|
|
|
|
|
|
QSB.Helper.Events.Unity.RunWhen(() => transformSync?.SyncedTransform != null,
|
|
|
|
|
() => transformSync?.SetReferenceSector(sector));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
2020-08-09 12:38:35 +01:00
|
|
|
|
}
|