83 lines
2.9 KiB
C#
83 lines
2.9 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Threading.Tasks;
|
|
using UnityEngine;
|
|
using UnityEngine.U2D;
|
|
|
|
namespace DDD
|
|
{
|
|
public class DataManager : Singleton<DataManager>, IManager
|
|
{
|
|
public ItemDataSo ItemDataSo { get; private set; }
|
|
public RecipeDataSo RecipeDataSo { get; private set; }
|
|
public FoodDataSo FoodDataSo { get; private set; }
|
|
public DrinkDataSo DrinkDataSo { get; private set; }
|
|
public IngredientDataSo IngredientDataSo { get; private set; }
|
|
public TasteDataSo TasteDataSo { get; private set; }
|
|
public EnvironmentDataSo EnvironmentDataSo { get; private set; }
|
|
|
|
private Dictionary<string, Sprite> _spriteAtlas;
|
|
|
|
public bool IsInitialized { get; private set; }
|
|
|
|
public void PreInit()
|
|
{
|
|
|
|
}
|
|
|
|
public async Task Init()
|
|
{
|
|
ItemDataSo = await AssetManager.LoadAsset<ItemDataSo>(DataConstants.ItemDataSo);
|
|
RecipeDataSo = await AssetManager.LoadAsset<RecipeDataSo>(DataConstants.RecipeDataSo);
|
|
FoodDataSo = await AssetManager.LoadAsset<FoodDataSo>(DataConstants.FoodDataSo);
|
|
DrinkDataSo = await AssetManager.LoadAsset<DrinkDataSo>(DataConstants.DrinkDataSo);
|
|
IngredientDataSo = await AssetManager.LoadAsset<IngredientDataSo>(DataConstants.IngredientDataSo);
|
|
TasteDataSo = await AssetManager.LoadAsset<TasteDataSo>(DataConstants.TasteDataSo);
|
|
EnvironmentDataSo = await AssetManager.LoadAsset<EnvironmentDataSo>(DataConstants.EnvironmentDataSo);
|
|
|
|
List<SpriteAtlas> spriteAtlases = await AssetManager.LoadAssetsByLabel<SpriteAtlas>(DataConstants.AtlasLabel);
|
|
_spriteAtlas = new Dictionary<string, Sprite>(spriteAtlases.Count);
|
|
|
|
foreach (var atlas in spriteAtlases)
|
|
{
|
|
if (atlas == null) continue;
|
|
|
|
var count = atlas.spriteCount;
|
|
if (count == 0) continue;
|
|
|
|
var sprites = new Sprite[count];
|
|
atlas.GetSprites(sprites);
|
|
|
|
foreach (var sprite in sprites)
|
|
{
|
|
if (sprite == null) continue;
|
|
|
|
var key = sprite.name.Replace(CommonConstants.Clone, string.Empty).Trim();
|
|
_spriteAtlas.TryAdd(key, sprite);
|
|
}
|
|
}
|
|
|
|
IsInitialized = true;
|
|
}
|
|
|
|
public void PostInit()
|
|
{
|
|
|
|
}
|
|
|
|
public async Task WaitUntilInitialized()
|
|
{
|
|
while (!IsInitialized)
|
|
{
|
|
await Task.Yield();
|
|
}
|
|
}
|
|
|
|
public Sprite GetSprite(string key) => _spriteAtlas.GetValueOrDefault(key);
|
|
|
|
// TODO : So가 늘어나는 경우 관리 방법 변경 필요성이 있음
|
|
// GetItemType(id)
|
|
// GetItemImage
|
|
// GetItemName
|
|
}
|
|
} |