Refresh cache only one scene change

This commit is contained in:
Nick 2022-05-14 15:04:08 -04:00
parent b1e66f14fb
commit 127f8f62c5

View File

@ -58,6 +58,7 @@ namespace NewHorizons
private string _defaultStarSystem = "SolarSystem";
private string _currentStarSystem = "SolarSystem";
private bool _isChangingStarSystem = false;
private bool _refreshCacheOnLoad = false; // Will refresh when changing systems
private bool _firstLoad = true;
private ShipWarpController _shipWarpController;
@ -169,10 +170,20 @@ namespace NewHorizons
private void OnSceneUnloaded(Scene scene)
{
// Always clear this one because the game objects will be null now
SearchUtilities.ClearCache();
ImageUtilities.ClearCache();
AudioUtilities.ClearCache();
AssetBundleUtilities.ClearCache();
// Clear caches if we've left the actual game scene or if we've specified to do it
// Refresh cache of load should only be true if the new system isnt the same as the last one
if (_refreshCacheOnLoad || !_isChangingStarSystem)
{
ImageUtilities.ClearCache();
AudioUtilities.ClearCache();
AssetBundleUtilities.ClearCache();
}
_refreshCacheOnLoad = false;
IsSystemReady = false;
}
@ -455,6 +466,8 @@ namespace NewHorizons
sceneToLoad = OWScene.SolarSystem;
}
_refreshCacheOnLoad = _currentStarSystem != newStarSystem;
_currentStarSystem = newStarSystem;
LoadManager.LoadSceneAsync(sceneToLoad, true, LoadManager.FadeType.ToBlack, 0.1f, true);