1using NaughtyAttributes;
2using System.Collections;
3using System.Collections.Generic;
10 private Dictionary<string, Texture2D> FullRes;
11 private Dictionary<string, Texture2D> LowRes;
12 [ReadOnly] [SerializeField]
private int numOfPictures = 0;
21 DontDestroyOnLoad(gameObject);
22 FullRes =
new Dictionary<string, Texture2D>();
23 LowRes =
new Dictionary<string, Texture2D>();
26 public void AddTexture(
string filename, Texture2D texture)
28 filename = filename.Replace(
" (Clone)",
"");
29 if (FullRes.ContainsKey(filename))
32 Debug.LogWarning($
"{filename} already in dicionary! destroying!");
36 FullRes.Add(filename, texture);
37 Debug.Log($
"Texture '{filename}' with x: {texture.width} y: {texture.height}");
39 Texture2D copyTexture =
new Texture2D(texture.width, texture.height);
40 copyTexture.SetPixels(texture.GetPixels());
43 LowRes.Add(filename, copyTexture);
49 filename = filename.Replace(
"(Clone)",
"").Trim();
50 return LowRes.ContainsKey(filename);
55 filename = filename.Replace(
"(Clone)",
"").Trim();
56 if (FullRes.ContainsKey(filename))
58 Debug.Log(
"[GlobalTextureHolder] GetFullRes called on: " + filename +
" size X: " + FullRes[filename].width);
59 return FullRes[filename];
61 if (File.Exists(Path.Combine(Application.streamingAssetsPath,
"pictures", filename)))
63 Debug.Log(
"[GlobalTextureHolder] GetFullRes called on: " + filename);
65 var fileData = File.ReadAllBytes(Path.Combine(Application.streamingAssetsPath,
"pictures", filename));
66 var tex =
new Texture2D(1, 1);
67 tex.LoadImage(fileData);
68 FullRes.Add(filename, tex);
71 Debug.LogWarning(
"GetFullRes returns with NULL!");
76 filename = filename.Replace(
"(Clone)",
"").Trim();
77 if (LowRes.ContainsKey(filename))
79 return LowRes[filename];
bool HasTexture(string filename)
void AddTexture(string filename, Texture2D texture)
Texture2D GetLowRes(string filename)
Texture2D GetFullRes(string filename)
static GlobalTextureHolder instance
static void Resize(Texture2D texture2D, int targetX, int targetY, bool mipmap=true, FilterMode filter=FilterMode.Bilinear)