Clear texture cache on scene reload

This commit is contained in:
Nick 2022-05-01 00:06:19 -04:00
parent 7b4b949927
commit aa0f9b6d8b
2 changed files with 11 additions and 1 deletions

View File

@ -135,6 +135,7 @@ namespace NewHorizons
Logger.Log($"Scene Loaded: {scene.name} {mode}");
SearchUtilities.ClearCache();
ImageUtilities.ClearCache();
_isChangingStarSystem = false;

View File

@ -143,11 +143,20 @@ namespace NewHorizons.Utility
var texture = new Texture2D(2, 2);
texture.name = Path.GetFileNameWithoutExtension(path);
texture.LoadImage(data);
UnityEngine.Object.DontDestroyOnLoad(texture);
_loadedTextures.Add(path, texture);
return texture;
}
public static void ClearCache()
{
foreach(var texture in _loadedTextures.Values)
{
if (texture == null) continue;
UnityEngine.Object.Destroy(texture);
}
_loadedTextures.Clear();
}
public static Color GetAverageColor(Texture2D src)
{
var pixels = src.GetPixels32();