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