using System;
using System.Collections.Generic;
using UnityEngine;

namespace TextureBank
{
	public class TextureBank
	{
		public TextureBank()
		{
			this.dicTextures = new Dictionary<string, Texture2D>();
		}

		public Texture2D GetTexture(string fileName)
		{
			if (fileName.Contains(".tex"))
			{
				fileName.Replace(".tex", string.Empty);
			}
			if (this.dicTextures.ContainsKey(fileName))
			{
				return this.dicTextures[fileName];
			}
			if (!GameUty.FileSystem.IsExistentFile(fileName + ".tex"))
			{
				Debug.LogWarning("GetTexture: " + fileName + ".texは存在しません。nullを返します。");
				this.dicTextures[fileName] = null;
				return this.dicTextures[fileName];
			}
			Texture2D texture2D = ImportCM.CreateTexture(fileName + ".tex");
			this.dicTextures[fileName] = texture2D;
			return texture2D;
		}

		public void Dispace()
		{
			foreach (KeyValuePair<string, Texture2D> keyValuePair in this.dicTextures)
			{
				if (keyValuePair.Value != null)
				{
					UnityEngine.Object.Destroy(keyValuePair.Value);
				}
			}
			this.dicTextures.Clear();
		}

		private Dictionary<string, Texture2D> dicTextures;
	}
}
