55 lines
1.5 KiB
C#
55 lines
1.5 KiB
C#
using FirstVillain.Converter;
|
|
using FirstVillain.Entities;
|
|
using FirstVillain.EventBus;
|
|
using FirstVillain.Singleton;
|
|
using Newtonsoft.Json;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.AddressableAssets;
|
|
using UnityEngine.ResourceManagement.AsyncOperations;
|
|
|
|
//규칙 : 테이블을 필요할 때마다 로드해서 사용한다.
|
|
public class TableManager : UnitySingleton<TableManager>
|
|
{
|
|
public int LoadTableCount { get; private set; } = 0;
|
|
|
|
public void LoadTable<T>(E_TABLE table, Action<Wrapper<T>> result)
|
|
{
|
|
LoadTableCount++;
|
|
LoadTableAsset(table, result);
|
|
}
|
|
|
|
private void LoadTableAsset<T>(E_TABLE table, Action<Wrapper<T>> result)
|
|
{
|
|
AddressableManager.Instance.LoadAssetAsync<TextAsset>(table.ToString(), asset => {
|
|
result(JsonConvert.DeserializeObject<Wrapper<T>>(asset.text));
|
|
});
|
|
}
|
|
|
|
#region LoadAssets
|
|
|
|
|
|
#endregion LoadAssets
|
|
//테이블별로 테이블 가져오는 함수를 계속 추가해 줘야하는 단점...
|
|
#region Prop
|
|
public void GetPropInfoById(E_TABLE table, int id, Action<JPropInfoData> result)
|
|
{
|
|
LoadTableAsset<JPropInfoData>(table, loaded =>
|
|
{
|
|
var list = loaded.list;
|
|
result(list.Find(arg => arg.Id == id));
|
|
});
|
|
}
|
|
|
|
public void GetPropInfoList(E_TABLE table, Action<List<JPropInfoData>> result)
|
|
{
|
|
LoadTableAsset<JPropInfoData>(table, loaded =>
|
|
{
|
|
result(loaded.list);
|
|
});
|
|
}
|
|
|
|
#endregion Prop
|
|
}
|