This repository has been archived on 2026-01-20. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
AW_2025/Assets/Scripts/Manager/DataManager.cs
2025-02-24 15:18:12 +09:00

60 lines
1.4 KiB
C#

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