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;
|
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
|
|
|
|
{
|
2020-12-02 21:23:01 +00:00
|
|
|
|
public class SectorSync : MonoBehaviour
|
|
|
|
|
{
|
2021-01-31 15:29:39 +00:00
|
|
|
|
private const float CheckInterval = 0.5f;
|
2020-12-02 21:23:01 +00:00
|
|
|
|
private float _checkTimer = CheckInterval;
|
2020-08-09 12:54:05 +00:00
|
|
|
|
|
2020-12-20 09:45:50 +00:00
|
|
|
|
public void Update()
|
2020-12-02 21:23:01 +00:00
|
|
|
|
{
|
|
|
|
|
if (!QSBSectorManager.Instance.IsReady)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
_checkTimer += Time.unscaledDeltaTime;
|
|
|
|
|
if (_checkTimer < CheckInterval)
|
|
|
|
|
{
|
|
|
|
|
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
|
|
|
|
_checkTimer = 0;
|
|
|
|
|
}
|
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-10 19:34:41 +00:00
|
|
|
|
QSBEventManager.FireEvent(EventNames.QSBSectorChange, id, sector);
|
2020-12-14 21:20:53 +00:00
|
|
|
|
}
|
2020-12-03 08:28:05 +00:00
|
|
|
|
}
|