39 lines
1.4 KiB
C#
39 lines
1.4 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using UnityEngine;
|
|
|
|
|
|
public interface ILoader<Key, Value>
|
|
{
|
|
Dictionary<Key, Value> MakeDict();
|
|
}
|
|
|
|
public class DataManager
|
|
{
|
|
// 데이터매니저는 만들기 전에 파일 형태를 먼저 생각해야함 : json, xml, csv 등등
|
|
// 근데 주로 json을 많이 씀
|
|
|
|
public Dictionary<int, Status> StatusDict {get; private set;} = new Dictionary<int, Status>();
|
|
public void Init()
|
|
{
|
|
// TextAsset textAsset = Managers.Resource.Load<TextAsset>("Data/StatusData");
|
|
// StatusData data = JsonUtility.FromJson<StatusData>(textAsset.text);
|
|
|
|
// 링크하는거 버그가 (iOS)에서 이걸 잘 안쓰게 되고 바로 넣어주는작업을 할예정인데 알고는 있어라.
|
|
// 뒤에 들어가는 람다식의 값이 키로 해서 해당 데이터 객체의 다른 값들이 밸류로 들어가게 된다
|
|
// StatusDict = data.status.ToDictionary(s => s.level);
|
|
|
|
StatusDict = LoadJSON<StatusData, int, Status>("Statusdata").MakeDict();
|
|
}
|
|
|
|
// Init에서 초기화 해주던걸 이렇게 해주면 조금더 깔끔하고 반복 없이 만들 수 있다.
|
|
Loader LoadJSON<Loader, key, Value>(string path) where Loader : ILoader<key, Value>
|
|
{
|
|
TextAsset textAsset = Managers.Resource.Load<TextAsset>($"Data/{path}");
|
|
Loader data = JsonUtility.FromJson<Loader>(textAsset.text);
|
|
return data;
|
|
}
|
|
}
|
|
|