88 lines
2.5 KiB
C#
88 lines
2.5 KiB
C#
|
|
using System.Collections.Generic;
|
||
|
|
using UnityEngine;
|
||
|
|
using System;
|
||
|
|
|
||
|
|
public enum ETextureType
|
||
|
|
{
|
||
|
|
AI_Image_1, AI_Image_2, AI_Image_3,
|
||
|
|
AI_Image_4, AI_Image_5, AI_Image_6,
|
||
|
|
}
|
||
|
|
public enum EPrefabType
|
||
|
|
{
|
||
|
|
|
||
|
|
}
|
||
|
|
public class ResourceManager : MonoBehaviour
|
||
|
|
{
|
||
|
|
public const string PREFAB_PATH = "Prefabs/";
|
||
|
|
public const string TEXTURES_PATH = "Textures/";
|
||
|
|
public const string DATA_TABLE_PATH = "CSV_Datas/";
|
||
|
|
|
||
|
|
private Dictionary<ETextureType, Sprite> _dicSprites;
|
||
|
|
private Dictionary<CodeJay.Enum.ECardType, Sprite> _dicCardSprites;
|
||
|
|
private Dictionary<EPrefabType, GameObject> _dicPrefabs;
|
||
|
|
private List<Sprite> _lstProductIcons;
|
||
|
|
|
||
|
|
private void Awake()
|
||
|
|
{
|
||
|
|
_dicSprites = new Dictionary<ETextureType, Sprite>();
|
||
|
|
_dicCardSprites = new Dictionary<CodeJay.Enum.ECardType, Sprite>();
|
||
|
|
_dicPrefabs = new Dictionary<EPrefabType, GameObject>();
|
||
|
|
_lstProductIcons = new List<Sprite>();
|
||
|
|
|
||
|
|
this.LoadSprites();
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
private void LoadSprites()
|
||
|
|
{
|
||
|
|
var spriteArray = Resources.LoadAll<Sprite>(TEXTURES_PATH + "AI_Images");
|
||
|
|
Array.Sort(spriteArray, (Sprite a, Sprite b) => { return int.Parse(a.name) < int.Parse(b.name) ? -1 : 1; });
|
||
|
|
|
||
|
|
for (int i = 0; i < spriteArray.Length; i++)
|
||
|
|
{
|
||
|
|
_dicSprites.Add(ETextureType.AI_Image_1 + i, spriteArray[i]);
|
||
|
|
}
|
||
|
|
|
||
|
|
spriteArray = Resources.LoadAll<Sprite>(TEXTURES_PATH + "CardList");
|
||
|
|
|
||
|
|
for (int i = 0; i < spriteArray.Length; i++)
|
||
|
|
{
|
||
|
|
_dicCardSprites.Add((CodeJay.Enum.ECardType)i, spriteArray[i]);
|
||
|
|
}
|
||
|
|
|
||
|
|
spriteArray = Resources.LoadAll<Sprite>(TEXTURES_PATH + "ProductIcons");
|
||
|
|
|
||
|
|
for (int i = 0; i < spriteArray.Length; i++)
|
||
|
|
{
|
||
|
|
_lstProductIcons.Add(spriteArray[i]);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
#region Getter
|
||
|
|
public Sprite GetSprite(ETextureType key)
|
||
|
|
{
|
||
|
|
return _dicSprites[key] ? _dicSprites[key] : null;
|
||
|
|
}
|
||
|
|
|
||
|
|
public Sprite GetSprite(CodeJay.Enum.ECardType type)
|
||
|
|
{
|
||
|
|
return _dicCardSprites[type] ? _dicCardSprites[type] : null;
|
||
|
|
}
|
||
|
|
|
||
|
|
public Sprite GetProductSprite(int index)
|
||
|
|
{
|
||
|
|
if (index < 0 || index >= _lstProductIcons.Count)
|
||
|
|
return _lstProductIcons[0];
|
||
|
|
else
|
||
|
|
return _lstProductIcons[index];
|
||
|
|
}
|
||
|
|
|
||
|
|
public Sprite GetAISpriteFromResources(int index)
|
||
|
|
{
|
||
|
|
return Resources.Load<Sprite>(TEXTURES_PATH + "AI_Images/0");
|
||
|
|
//return Resources.Load<Sprite>(TEXTURES_PATH + "AI_Images/" + index.ToString());
|
||
|
|
}
|
||
|
|
#endregion
|
||
|
|
}
|
||
|
|
|