using GameDataEditor; using System.Collections.Generic; using UnityEngine; public class FieMasterData where T : IGDEData, new() { public delegate bool FieMasterDataFilterDelegate(T data); private Dictionary _allDataList = new Dictionary(); private static FieMasterData _instance; public static FieMasterData I { get { if (_instance == null) { _instance = new FieMasterData(); } return _instance; } } public FieMasterData() { GDEDataManager.Init("MasterData/fie_master_data"); InitMasterData(); } public void InitMasterData() { Dictionary data = null; GDEDataManager.GetAllDataBySchema(typeof(T).Name.Replace("GDE", string.Empty).Replace("Data", string.Empty), out data); if (data == null) { Debug.LogError("GDE faild to load spreadsheet. Schema Name : " + typeof(T).ToString()); } foreach (KeyValuePair item in data) { T value = new T(); GDEDataManager.DataDictionary.TryGetCustom(item.Key, out value); _allDataList[item.Key] = value; } } public Dictionary GetAllMasterData() { return _allDataList; } public T GetMasterData(string key) { if (!I._allDataList.ContainsKey(key)) { return (T)null; } return I._allDataList[key]; } public static List FindMasterDataList(FieMasterDataFilterDelegate filterDelegate = null) { if (I._allDataList.Count <= 0) { return null; } List list = new List(); foreach (KeyValuePair allData in I._allDataList) { if (filterDelegate(allData.Value)) { list.Add(allData.Value); } } return list; } public static T FindMasterData(FieMasterDataFilterDelegate filterDelegate = null) { if (I._allDataList.Count <= 0) { return (T)null; } foreach (KeyValuePair allData in I._allDataList) { if (filterDelegate(allData.Value)) { return allData.Value; } } return (T)null; } public Dictionary FindMasterDataDictionary(FieMasterDataFilterDelegate filterDelegate = null) { if (I._allDataList.Count <= 0) { return null; } if (filterDelegate != null) { Dictionary dictionary = new Dictionary(); { foreach (KeyValuePair allData in I._allDataList) { if (filterDelegate(allData.Value)) { dictionary[allData.Key] = allData.Value; } } return dictionary; } } return I._allDataList; } }