TextureBank.cs 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. using System;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. namespace TextureBank
  5. {
  6. public class TextureBank
  7. {
  8. public TextureBank()
  9. {
  10. this.dicTextures = new Dictionary<string, Texture2D>();
  11. }
  12. public Texture2D GetTexture(string fileName)
  13. {
  14. if (fileName.Contains(".tex"))
  15. {
  16. fileName.Replace(".tex", string.Empty);
  17. }
  18. if (this.dicTextures.ContainsKey(fileName))
  19. {
  20. return this.dicTextures[fileName];
  21. }
  22. if (!GameUty.FileSystem.IsExistentFile(fileName + ".tex"))
  23. {
  24. Debug.LogWarning("GetTexture: " + fileName + ".texは存在しません。nullを返します。");
  25. this.dicTextures[fileName] = null;
  26. return this.dicTextures[fileName];
  27. }
  28. Texture2D texture2D = ImportCM.CreateTexture(fileName + ".tex");
  29. this.dicTextures[fileName] = texture2D;
  30. return texture2D;
  31. }
  32. public void Dispace()
  33. {
  34. foreach (KeyValuePair<string, Texture2D> keyValuePair in this.dicTextures)
  35. {
  36. if (keyValuePair.Value != null)
  37. {
  38. UnityEngine.Object.Destroy(keyValuePair.Value);
  39. }
  40. }
  41. this.dicTextures.Clear();
  42. }
  43. private Dictionary<string, Texture2D> dicTextures;
  44. }
  45. }