do proper null checking on sectors

This commit is contained in:
JohnCorby 2022-12-28 12:28:29 -08:00
parent ce4072fed0
commit 177eea9e36

View File

@ -24,6 +24,8 @@ namespace NewHorizons.Handlers
{
var group = GetStreamingGroup(name);
if (sector)
{
sector.OnOccupantEnterSector += _ =>
{
if (sector.ContainsAnyOccupants(DynamicOccupant.Player | DynamicOccupant.Probe))
@ -35,6 +37,11 @@ namespace NewHorizons.Handlers
group.ReleaseGeneralAssets();
};
}
else
{
group.RequestGeneralAssets();
}
}
/// <summary>
/// makes it so that this object's streaming stuff will be connected to the given sector
@ -87,8 +94,6 @@ namespace NewHorizons.Handlers
foreach (var assetBundle in assetBundles)
{
StreamingManager.LoadStreamingAssets(assetBundle);
// Track the sector even if its null. null means stay loaded forever
if (!_sectorCache.TryGetValue(assetBundle, out var sectors))
{
@ -113,6 +118,11 @@ namespace NewHorizons.Handlers
StreamingManager.UnloadStreamingAssets(assetBundle);
};
}
else
{
foreach (var assetBundle in assetBundles)
StreamingManager.LoadStreamingAssets(assetBundle);
}
}
public static bool IsBundleInUse(string assetBundle)
@ -133,7 +143,7 @@ namespace NewHorizons.Handlers
}
else
{
return Locator.GetAstroObject(name)?.GetComponentInChildren<StreamingGroup>();
return Locator.GetAstroObject(name).GetComponentInChildren<StreamingGroup>();
}
}
}