49 lines
1.2 KiB
C#
Raw Normal View History

2020-12-14 16:24:52 +00:00
using QSB.Events;
2020-11-03 21:33:48 +00:00
using QSB.Player;
2020-08-22 17:08:56 +01:00
using System.Linq;
2020-08-21 14:04:13 +01:00
using UnityEngine;
2020-02-13 20:23:26 +01:00
2020-11-03 22:29:23 +00:00
namespace QSB.SectorSync
2020-02-15 20:48:02 +01:00
{
2020-12-02 21:23:01 +00:00
public class SectorSync : MonoBehaviour
{
private const float CheckInterval = 0.5f;
private float _checkTimer = CheckInterval;
2020-08-09 13:54:05 +01:00
2020-12-02 21:23:01 +00:00
private void Update()
{
if (!QSBSectorManager.Instance.IsReady)
{
return;
}
_checkTimer += Time.unscaledDeltaTime;
if (_checkTimer < CheckInterval)
{
return;
}
QSBPlayerManager.GetSyncObjects<TransformSync.TransformSync>().Where(x => x.HasAuthority).ToList().ForEach(CheckTransformSyncSector);
_checkTimer = 0;
}
2020-02-15 20:48:02 +01: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 21:59:50 +02:00
2020-12-02 21:23:01 +00:00
private void SendSector(uint id, QSBSector sector)
{
GlobalMessenger<uint, QSBSector>.FireEvent(EventNames.QSBSectorChange, id, sector);
}
}
2020-12-03 08:28:05 +00:00
}