using System; using System.Collections.Generic; using UnityEngine; using wf; namespace MyRoomCustom { public static class PlacementData { public static int Count { get { PlacementData.CreateData(); return PlacementData.enabledIDList.Count; } } public static bool Contains(int id) { PlacementData.CreateData(); return PlacementData.enabledIDList.Contains(id); } public static PlacementData.Data GetData(int id) { PlacementData.CreateData(); NDebug.Assert(PlacementData.basicDatas.ContainsKey(id), "自室カスタム.配置物\nID[" + id + "]のデータは存在しません"); return PlacementData.basicDatas[id]; } public static List GetAllDatas(bool onlyEnabled) { PlacementData.CreateData(); List list = new List(); foreach (KeyValuePair keyValuePair in PlacementData.basicDatas) { if (!onlyEnabled || PlacementData.enabledIDList.Contains(keyValuePair.Key)) { list.Add(keyValuePair.Value); } } return list; } public static List GetDatas(Func customCheckFunction) { PlacementData.CreateData(); List list = new List(); foreach (int key in PlacementData.enabledIDList) { PlacementData.Data data = PlacementData.basicDatas[key]; if (customCheckFunction(data)) { list.Add(data); } } return list; } public static List CategoryIDList { get { PlacementData.CreateCategoryData(); return new List(PlacementData.categoryIdManager.idMap.Keys); } } public static string GetCategoryName(int categoryID) { PlacementData.CreateCategoryData(); NDebug.Assert(PlacementData.categoryIdManager.idMap.ContainsKey(categoryID), string.Format("カテゴリID[{0}]の情報が存在しません", categoryID)); return PlacementData.categoryIdManager.idMap[categoryID].Key; } public static int GetCategoryID(string categoryName) { PlacementData.CreateCategoryData(); NDebug.Assert(PlacementData.categoryIdManager.nameMap.ContainsKey(categoryName), string.Format("カテゴリ名[{0}]の情報が存在しません", categoryName)); return PlacementData.categoryIdManager.nameMap[categoryName]; } public static void CreateData() { if (PlacementData.enabledIDList != null) { return; } PlacementData.CreateCategoryData(); PlacementData.basicDatas = new Dictionary(); PlacementData.enabledIDList = new HashSet(); CsvCommonIdManager.ReadEnabledIdList(CsvCommonIdManager.FileSystemType.Normal, true, "my_room_placement_obj_enabled_list", ref PlacementData.enabledIDList); using (AFileBase afileBase = GameUty.FileSystem.FileOpen("my_room_placement_obj_list.nei")) { using (CsvParser csvParser = new CsvParser()) { bool condition = csvParser.Open(afileBase); NDebug.Assert(condition, "my_room_placement_obj_list\nopen failed."); foreach (int num in PlacementData.enabledIDList) { PlacementData.Data value = new PlacementData.Data(num, csvParser); PlacementData.basicDatas.Add(num, value); } } } } private static void CreateCategoryData() { if (PlacementData.categoryIdManager != null) { return; } PlacementData.categoryIdManager = new CsvCommonIdManager("my_room_placement_obj_category", "自室カスタム.配置物カテゴリ", CsvCommonIdManager.Type.IdAndUniqueName, (int id) => true); } public static void Clear() { if (PlacementData.enabledIDList != null) { PlacementData.enabledIDList = null; } if (PlacementData.basicDatas != null) { PlacementData.basicDatas = null; } if (PlacementData.categoryIdManager != null) { PlacementData.categoryIdManager = null; } } private const string csvTopCommonName = "my_room_placement_obj"; private const string typeNameForErrorLog = "自室カスタム.配置物"; private static CsvCommonIdManager categoryIdManager; private static HashSet enabledIDList; private static Dictionary basicDatas; public class Data { public Data(int uniqueID, CsvParser csv) { for (int i = 1; i < csv.max_cell_y; i++) { if (csv.IsCellToExistData(0, i) && csv.GetCellAsInteger(0, i) == uniqueID) { int num = 1; this.ID = uniqueID; this.drawName = csv.GetCellAsString(num++, i); string cellAsString = csv.GetCellAsString(num++, i); this.resourceName = csv.GetCellAsString(num++, i); this.assetName = csv.GetCellAsString(num++, i); this.thumbnailName = csv.GetCellAsString(num++, i); this.categoryID = PlacementData.GetCategoryID(cellAsString); } } } public GameObject GetPrefab() { GameObject gameObject = null; if (!string.IsNullOrEmpty(this.resourceName)) { gameObject = Resources.Load("SceneCreativeRoom/Debug/Prefab/" + this.resourceName); } if (!gameObject && !string.IsNullOrEmpty(this.assetName)) { gameObject = GameMain.Instance.BgMgr.CreateAssetBundle(this.assetName); } if (!gameObject) { if (!string.IsNullOrEmpty(this.resourceName)) { Debug.LogWarningFormat("[Creative Room]プレハブ[{0}]が見つかりませんでした\nパス:「{1}」", new object[] { this.resourceName, "Assets/Resources/SceneCreativeRoom/Debug/Prefab/" + this.resourceName }); } else if (!string.IsNullOrEmpty(this.assetName)) { Debug.LogWarningFormat("[Creative Room]アセットバンドル[{0}]が見つかりませんでした", new object[] { this.assetName }); } return null; } return gameObject; } public Texture GetThumbnail() { Texture result = null; if (!string.IsNullOrEmpty(this.thumbnailName)) { string f_strFileName = this.thumbnailName + ".tex"; if (GameUty.FileSystem.IsExistentFile(f_strFileName)) { result = ImportCM.CreateTexture(f_strFileName); } } return result; } public string drawNameTerm { get { return "SceneCreativeRoom/オブジェクト/" + this.ID.ToString(); } } public readonly int ID; public readonly string drawName; public readonly string resourceName; public readonly string assetName; public readonly int categoryID; public readonly string thumbnailName; } } }