This repository has been archived by the owner on Sep 21, 2022. It is now read-only.
/
TextureCache.cs
48 lines (42 loc) · 1.62 KB
/
TextureCache.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
using System.Collections.Generic;
using UnityEngine;
namespace ModIO.UI
{
/// <summary>Manages caching of the textures required by the UI.</summary>
public class TextureCache : MonoBehaviour
{
// ---------[ SINGLETON ]---------
/// <summary>The singleton instance of the TextureCache.</summary>
private static TextureCache _instance;
/// <summary>The singleton instance of the TextureCache.</summary>
public static TextureCache instance
{
get
{
if(TextureCache._instance == null)
{
TextureCache._instance = UIUtilities.FindComponentInScene<TextureCache>(true);
if(TextureCache._instance == null)
{
GameObject instanceGO = new GameObject("mod.io UI Texture Cache");
TextureCache._instance = instanceGO.AddComponent<TextureCache>();
}
}
return TextureCache._instance;
}
}
// ---------[ FIELDS ]---------
/// <summary>Should the cache be cleared on disable</summary>
public bool clearCacheOnDisable = true;
/// <summary>The texture cache holding all versions of cached images.</summary>
public Dictionary<ImageDisplayData, Texture2D[]> cache = new Dictionary<ImageDisplayData, Texture2D[]>();
// ---------[ INITIALIZATION ]---------
protected virtual void OnDisable()
{
if(this.clearCacheOnDisable)
{
this.cache.Clear();
}
}
}
}