using System.Collections.Generic; using System.IO; using System.Xml.Serialization; using UnityEngine; namespace Noah { public interface ILoader { Dictionary MakeDic(); bool Validate(); } public class DataManager { public Dictionary AddressSpaceDatas { get; private set; } public void Init() { // AddressSpaceDatas AddressSpaceDatas = LoadJson("AddressSpaceData").MakeDic(); } private Item LoadSingleXml(string name) { XmlSerializer xs = new XmlSerializer(typeof(Item)); TextAsset textAsset = Resources.Load("Data/" + name); using (MemoryStream stream = new MemoryStream(System.Text.Encoding.UTF8.GetBytes(textAsset.text))) return (Item)xs.Deserialize(stream); } private Loader LoadXml(string name) where Loader : ILoader, new() { XmlSerializer xs = new XmlSerializer(typeof(Loader)); TextAsset textAsset = Resources.Load("Data/" + name); using (MemoryStream stream = new MemoryStream(System.Text.Encoding.UTF8.GetBytes(textAsset.text))) return (Loader)xs.Deserialize(stream); } private Loader LoadJson(string path) where Loader : ILoader { TextAsset textAsset = Managers.Resource.Load($"Data/{path}"); return JsonUtility.FromJson(textAsset.text); } } }