load existing sector list on sectorsync init

This commit is contained in:
Mister_Nebula 2021-07-13 15:24:57 +01:00
parent 78bbdf1169
commit 55ee454d1c

View File

@ -31,12 +31,19 @@ namespace QSB.SectorSync
public void Init<T>(SectorDetector detector, ISectoredSync<T> sectoredSync)
{
DebugLog.DebugWrite($"INIT SECTORSYNC detector:{detector.name}");
if (_sectorDetector != null)
{
_sectorDetector.OnEnterSector -= AddSector;
_sectorDetector.OnExitSector -= RemoveSector;
}
if (detector == null)
{
DebugLog.ToConsole($"Error - Trying to init SectorSync with null SectorDetector.", MessageType.Error);
return;
}
_sectorDetector = detector;
_sectorDetector.OnEnterSector += AddSector;
_sectorDetector.OnExitSector += RemoveSector;
@ -47,12 +54,31 @@ namespace QSB.SectorSync
DebugLog.ToConsole($"Warning - OWRigidbody for {_sectorDetector.name} is null!", MessageType.Warning);
}
PopulateSectorList();
_targetType = sectoredSync.Type;
_isReady = true;
}
private void PopulateSectorList()
{
var currentList = _sectorDetector.GetValue<List<Sector>>("_sectorList");
SectorList.Clear();
foreach (var sector in currentList)
{
if (sector == null)
{
continue;
}
AddSector(sector);
}
}
private void AddSector(Sector sector)
{
DebugLog.DebugWrite($"{_sectorDetector.name} enter sector {sector}");
var worldObject = QSBWorldSync.GetWorldFromUnity<QSBSector, Sector>(sector);
if (worldObject == null)
{
@ -70,6 +96,7 @@ namespace QSB.SectorSync
private void RemoveSector(Sector sector)
{
DebugLog.DebugWrite($"{_sectorDetector.name} exit sector {sector}");
var worldObject = QSBWorldSync.GetWorldFromUnity<QSBSector, Sector>(sector);
if (worldObject == null)
{