2020-12-14 16:24:52 +00:00
|
|
|
|
using QSB.Events;
|
2020-11-03 21:33:48 +00:00
|
|
|
|
using QSB.Player;
|
2020-12-31 12:10:55 +00:00
|
|
|
|
using QSB.SectorSync.WorldObjects;
|
2021-02-19 12:42:37 +00:00
|
|
|
|
using QSB.Utility;
|
2020-08-22 16:08:56 +00:00
|
|
|
|
using System.Linq;
|
2020-08-21 13:04:13 +00:00
|
|
|
|
using UnityEngine;
|
2020-02-13 19:23:26 +00:00
|
|
|
|
|
2020-11-03 22:29:23 +00:00
|
|
|
|
namespace QSB.SectorSync
|
2020-02-15 19:48:02 +00:00
|
|
|
|
{
|
2021-02-19 12:42:37 +00:00
|
|
|
|
public class SectorSync : MonoBehaviour, IRepeating
|
2020-12-02 21:23:01 +00:00
|
|
|
|
{
|
2021-02-19 12:42:37 +00:00
|
|
|
|
public void Invoke()
|
2020-12-02 21:23:01 +00:00
|
|
|
|
{
|
|
|
|
|
if (!QSBSectorManager.Instance.IsReady)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
2020-12-14 20:41:56 +00:00
|
|
|
|
QSBPlayerManager.GetSyncObjects<TransformSync.TransformSync>()
|
2020-12-14 21:20:53 +00:00
|
|
|
|
.Where(x => x.HasAuthority).ToList().ForEach(CheckTransformSyncSector);
|
2020-12-02 21:23:01 +00:00
|
|
|
|
}
|
2020-02-15 19:48:02 +00:00
|
|
|
|
|
2020-12-02 21:23:01 +00:00
|
|
|
|
private void CheckTransformSyncSector(TransformSync.TransformSync transformSync)
|
|
|
|
|
{
|
|
|
|
|
var syncedTransform = transformSync.SyncedTransform;
|
|
|
|
|
if (syncedTransform == null || syncedTransform.position == Vector3.zero)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
var closestSector = QSBSectorManager.Instance.GetClosestSector(syncedTransform);
|
|
|
|
|
if (closestSector == transformSync.ReferenceSector)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
transformSync.SetReferenceSector(closestSector);
|
|
|
|
|
SendSector(transformSync.NetId.Value, closestSector);
|
|
|
|
|
}
|
2020-08-05 19:59:50 +00:00
|
|
|
|
|
2020-12-14 21:20:53 +00:00
|
|
|
|
private void SendSector(uint id, QSBSector sector) =>
|
2021-02-13 10:11:02 +00:00
|
|
|
|
QSBEventManager.FireEvent(EventNames.QSBSectorChange, id, sector);
|
2020-12-14 21:20:53 +00:00
|
|
|
|
}
|
2020-12-03 08:28:05 +00:00
|
|
|
|
}
|