diff --git a/QSB/SectorSync/QSBSectorDetector.cs b/QSB/SectorSync/QSBSectorDetector.cs
index 39025afc..7ca1ebfc 100644
--- a/QSB/SectorSync/QSBSectorDetector.cs
+++ b/QSB/SectorSync/QSBSectorDetector.cs
@@ -87,25 +87,11 @@ namespace QSB.SectorSync
SectorList.Remove(worldObject);
}
+ ///
+ /// called only by the sector manager
+ ///
public QSBSector GetClosestSector()
{
- if (QSBSectorManager.Instance == null || !QSBSectorManager.Instance.IsReady)
- {
- return null;
- }
-
- if (!IsReady)
- {
- DebugLog.ToConsole($"Warning - Tried to use GetClosestSector() before this SectorSync is ready. Stacktrace:\r\n{Environment.StackTrace}", MessageType.Warning);
- return null;
- }
-
- if (_sectorDetector == null)
- {
- IsReady = false;
- return null;
- }
-
var inASector = SectorList.Any(x => x.ShouldSyncTo(_targetType));
var listToCheck = inASector
diff --git a/QSB/SectorSync/QSBSectorManager.cs b/QSB/SectorSync/QSBSectorManager.cs
index a03def65..f0987535 100644
--- a/QSB/SectorSync/QSBSectorManager.cs
+++ b/QSB/SectorSync/QSBSectorManager.cs
@@ -14,10 +14,10 @@ namespace QSB.SectorSync
public override WorldObjectType WorldObjectType => WorldObjectType.Both;
public static QSBSectorManager Instance { get; private set; }
- public bool IsReady { get; private set; }
+ private bool _isReady;
public readonly List FakeSectors = new();
- public readonly List TransformSyncs = new();
+ public readonly List SectoredSyncs = new();
private const float UpdateInterval = 0.4f;
private float _timer = UpdateInterval;
@@ -36,21 +36,17 @@ namespace QSB.SectorSync
public void UpdateReferenceSectors()
{
- if (!Instance.IsReady || !QSBWorldSync.AllObjectsReady)
+ if (!Instance._isReady || !QSBWorldSync.AllObjectsReady)
{
return;
}
- foreach (var sync in TransformSyncs)
+ foreach (var sync in SectoredSyncs)
{
- if (sync.AttachedTransform == null)
- {
- continue;
- }
-
if (sync.hasAuthority
- && sync.AttachedTransform.gameObject.activeInHierarchy
&& sync.IsInitialized
+ && sync.AttachedTransform
+ && sync.AttachedTransform.gameObject.activeInHierarchy
&& sync.SectorDetector.IsReady)
{
UpdateReferenceSector(sync);
@@ -58,6 +54,17 @@ namespace QSB.SectorSync
}
}
+ private static void UpdateReferenceSector(BaseSectoredSync sync)
+ {
+ var closestSector = sync.SectorDetector.GetClosestSector();
+ if (closestSector == null)
+ {
+ return;
+ }
+
+ sync.SetReferenceSector(closestSector);
+ }
+
public void Awake()
{
Instance = this;
@@ -84,21 +91,10 @@ namespace QSB.SectorSync
}
QSBWorldSync.Init();
- IsReady = QSBWorldSync.GetWorldObjects().Any();
+ _isReady = QSBWorldSync.GetWorldObjects().Any();
}
public override void UnbuildWorldObjects() =>
- IsReady = false;
-
- private static void UpdateReferenceSector(BaseSectoredSync transformSync)
- {
- var closestSector = transformSync.SectorDetector.GetClosestSector();
- if (closestSector == null)
- {
- return;
- }
-
- transformSync.SetReferenceSector(closestSector);
- }
+ _isReady = false;
}
}
diff --git a/QSB/Syncs/Sectored/BaseSectoredSync.cs b/QSB/Syncs/Sectored/BaseSectoredSync.cs
index 37eeff18..432675c5 100644
--- a/QSB/Syncs/Sectored/BaseSectoredSync.cs
+++ b/QSB/Syncs/Sectored/BaseSectoredSync.cs
@@ -17,14 +17,14 @@ namespace QSB.Syncs.Sectored
public override void OnStartClient()
{
SectorDetector = gameObject.AddComponent();
- QSBSectorManager.Instance.TransformSyncs.Add(this);
+ QSBSectorManager.Instance.SectoredSyncs.Add(this);
base.OnStartClient();
}
public override void OnStopClient()
{
base.OnStopClient();
- QSBSectorManager.Instance.TransformSyncs.Remove(this);
+ QSBSectorManager.Instance.SectoredSyncs.Remove(this);
Destroy(SectorDetector);
}
diff --git a/QSB/Syncs/SyncBase.cs b/QSB/Syncs/SyncBase.cs
index c6e6c247..331d93ff 100644
--- a/QSB/Syncs/SyncBase.cs
+++ b/QSB/Syncs/SyncBase.cs
@@ -171,7 +171,7 @@ namespace QSB.Syncs
return;
}
- if (AttachedTransform == null)
+ if (!AttachedTransform)
{
DebugLog.ToConsole($"Error - AttachedObject {LogName} is null!", MessageType.Error);
base.Update();
@@ -184,7 +184,7 @@ namespace QSB.Syncs
return;
}
- if (ReferenceTransform == null && !AllowNullReferenceTransform)
+ if (!ReferenceTransform && !AllowNullReferenceTransform)
{
DebugLog.ToConsole($"Warning - {LogName}'s ReferenceTransform is null. AttachedObject:{AttachedTransform.name}", MessageType.Warning);
base.Update();
@@ -197,7 +197,7 @@ namespace QSB.Syncs
return;
}
- if (ReferenceTransform != null && ReferenceTransform.position == Vector3.zero)
+ if (ReferenceTransform && ReferenceTransform.position == Vector3.zero)
{
DebugLog.ToConsole($"Warning - {LogName}'s ReferenceTransform is at (0,0,0). ReferenceTransform:{ReferenceTransform.name}, AttachedObject:{AttachedTransform.name}", MessageType.Warning);
}
@@ -259,8 +259,8 @@ namespace QSB.Syncs
{
if (!QSBCore.ShowLinesInDebug
|| !IsInitialized
- || AttachedTransform == null
- || ReferenceTransform == null)
+ || !AttachedTransform
+ || !ReferenceTransform)
{
return;
}
@@ -287,7 +287,7 @@ namespace QSB.Syncs
return;
}
- if (AttachedTransform != null)
+ if (AttachedTransform)
{
DebugGUI.DrawLabel(AttachedTransform.transform, LogName);
}