PlacementData.cs 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. using System;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using wf;
  5. namespace MyRoomCustom
  6. {
  7. public static class PlacementData
  8. {
  9. public static int Count
  10. {
  11. get
  12. {
  13. PlacementData.CreateData();
  14. return PlacementData.commonIdManager.idMap.Count;
  15. }
  16. }
  17. public static bool Contains(int id)
  18. {
  19. PlacementData.CreateData();
  20. return PlacementData.commonIdManager.idMap.ContainsKey(id);
  21. }
  22. public static PlacementData.Data GetData(int id)
  23. {
  24. PlacementData.CreateData();
  25. NDebug.Assert(PlacementData.basicDatas.ContainsKey(id), "自室カスタム.配置物\nID[" + id + "]のデータは存在しません");
  26. return PlacementData.basicDatas[id];
  27. }
  28. public static bool IsEnabled(int id)
  29. {
  30. PlacementData.CreateData();
  31. return PlacementData.commonIdManager.enabledIdList.Contains(id);
  32. }
  33. public static List<PlacementData.Data> GetAllDatas(bool onlyEnabled)
  34. {
  35. PlacementData.CreateData();
  36. List<PlacementData.Data> list = new List<PlacementData.Data>();
  37. foreach (KeyValuePair<int, KeyValuePair<string, string>> keyValuePair in PlacementData.commonIdManager.idMap)
  38. {
  39. if (!onlyEnabled || PlacementData.commonIdManager.enabledIdList.Contains(keyValuePair.Key))
  40. {
  41. list.Add(PlacementData.basicDatas[keyValuePair.Key]);
  42. }
  43. }
  44. return list;
  45. }
  46. public static List<PlacementData.Data> GetDatas(Func<PlacementData.Data, bool> customCheckFunction)
  47. {
  48. PlacementData.CreateData();
  49. List<PlacementData.Data> list = new List<PlacementData.Data>();
  50. foreach (KeyValuePair<int, KeyValuePair<string, string>> keyValuePair in PlacementData.commonIdManager.idMap)
  51. {
  52. PlacementData.Data data = PlacementData.basicDatas[keyValuePair.Key];
  53. if (customCheckFunction(data))
  54. {
  55. list.Add(data);
  56. }
  57. }
  58. return list;
  59. }
  60. public static List<int> CategoryIDList
  61. {
  62. get
  63. {
  64. PlacementData.CreateCategoryData();
  65. return new List<int>(PlacementData.categoryIdManager.idMap.Keys);
  66. }
  67. }
  68. public static string GetCategoryName(int categoryID)
  69. {
  70. PlacementData.CreateCategoryData();
  71. NDebug.Assert(PlacementData.categoryIdManager.idMap.ContainsKey(categoryID), string.Format("カテゴリID[{0}]の情報が存在しません", categoryID));
  72. return PlacementData.categoryIdManager.idMap[categoryID].Key;
  73. }
  74. public static int GetCategoryID(string categoryName)
  75. {
  76. PlacementData.CreateCategoryData();
  77. NDebug.Assert(PlacementData.categoryIdManager.nameMap.ContainsKey(categoryName), string.Format("カテゴリ名[{0}]の情報が存在しません", categoryName));
  78. return PlacementData.categoryIdManager.nameMap[categoryName];
  79. }
  80. public static void CreateData()
  81. {
  82. PlacementData.CreateCategoryData();
  83. if (PlacementData.commonIdManager != null)
  84. {
  85. return;
  86. }
  87. PlacementData.commonIdManager = new CsvCommonIdManager("my_room_placement_obj", "自室カスタム.配置物", CsvCommonIdManager.Type.IdOnly, null);
  88. PlacementData.basicDatas = new Dictionary<int, PlacementData.Data>();
  89. string[] array = new string[]
  90. {
  91. "list"
  92. };
  93. KeyValuePair<AFileBase, CsvParser>[] array2 = new KeyValuePair<AFileBase, CsvParser>[array.Length];
  94. for (int i = 0; i < array2.Length; i++)
  95. {
  96. string text = "my_room_placement_obj_" + array[i] + ".nei";
  97. AFileBase afileBase = GameUty.FileSystem.FileOpen(text);
  98. CsvParser csvParser = new CsvParser();
  99. bool condition = csvParser.Open(afileBase);
  100. NDebug.Assert(condition, text + "\nopen failed.");
  101. array2[i] = new KeyValuePair<AFileBase, CsvParser>(afileBase, csvParser);
  102. }
  103. foreach (KeyValuePair<int, KeyValuePair<string, string>> keyValuePair in PlacementData.commonIdManager.idMap)
  104. {
  105. int key = keyValuePair.Key;
  106. PlacementData.Data value = new PlacementData.Data(key, array2[0].Value);
  107. PlacementData.basicDatas.Add(key, value);
  108. }
  109. foreach (KeyValuePair<AFileBase, CsvParser> keyValuePair2 in array2)
  110. {
  111. keyValuePair2.Value.Dispose();
  112. keyValuePair2.Key.Dispose();
  113. }
  114. }
  115. private static void CreateCategoryData()
  116. {
  117. if (PlacementData.categoryIdManager != null)
  118. {
  119. return;
  120. }
  121. PlacementData.categoryIdManager = new CsvCommonIdManager("my_room_placement_obj_category", "自室カスタム.配置物カテゴリ", CsvCommonIdManager.Type.IdAndUniqueName, (int id) => true);
  122. }
  123. public static void Clear()
  124. {
  125. if (PlacementData.commonIdManager != null)
  126. {
  127. PlacementData.commonIdManager = null;
  128. }
  129. if (PlacementData.categoryIdManager != null)
  130. {
  131. PlacementData.categoryIdManager = null;
  132. }
  133. }
  134. private const string csvTopCommonName = "my_room_placement_obj";
  135. private const string typeNameForErrorLog = "自室カスタム.配置物";
  136. private static CsvCommonIdManager commonIdManager;
  137. private static CsvCommonIdManager categoryIdManager;
  138. private static Dictionary<int, PlacementData.Data> basicDatas;
  139. public class Data
  140. {
  141. public Data(int uniqueID, CsvParser csv)
  142. {
  143. for (int i = 1; i < csv.max_cell_y; i++)
  144. {
  145. if (csv.IsCellToExistData(0, i) && csv.GetCellAsInteger(0, i) == uniqueID)
  146. {
  147. int num = 1;
  148. this.ID = uniqueID;
  149. this.drawName = csv.GetCellAsString(num++, i);
  150. string cellAsString = csv.GetCellAsString(num++, i);
  151. this.resourceName = csv.GetCellAsString(num++, i);
  152. this.assetName = csv.GetCellAsString(num++, i);
  153. this.thumbnailName = csv.GetCellAsString(num++, i);
  154. this.categoryID = PlacementData.GetCategoryID(cellAsString);
  155. }
  156. }
  157. }
  158. public GameObject GetPrefab()
  159. {
  160. GameObject gameObject = null;
  161. if (!string.IsNullOrEmpty(this.resourceName))
  162. {
  163. gameObject = Resources.Load<GameObject>("SceneCreativeRoom/Debug/Prefab/" + this.resourceName);
  164. }
  165. if (!gameObject && !string.IsNullOrEmpty(this.assetName))
  166. {
  167. gameObject = GameMain.Instance.BgMgr.CreateAssetBundle(this.assetName);
  168. }
  169. if (!gameObject)
  170. {
  171. if (!string.IsNullOrEmpty(this.resourceName))
  172. {
  173. Debug.LogWarningFormat("[Creative Room]プレハブ[{0}]が見つかりませんでした\nパス:「{1}」", new object[]
  174. {
  175. this.resourceName,
  176. "Assets/Resources/SceneCreativeRoom/Debug/Prefab/" + this.resourceName
  177. });
  178. }
  179. else if (!string.IsNullOrEmpty(this.assetName))
  180. {
  181. Debug.LogWarningFormat("[Creative Room]アセットバンドル[{0}]が見つかりませんでした", new object[]
  182. {
  183. this.assetName
  184. });
  185. }
  186. return null;
  187. }
  188. return gameObject;
  189. }
  190. public Texture GetThumbnail()
  191. {
  192. Texture result = null;
  193. if (!string.IsNullOrEmpty(this.thumbnailName))
  194. {
  195. string f_strFileName = this.thumbnailName + ".tex";
  196. if (GameUty.FileSystem.IsExistentFile(f_strFileName))
  197. {
  198. result = ImportCM.CreateTexture(f_strFileName);
  199. }
  200. }
  201. return result;
  202. }
  203. public readonly int ID;
  204. public readonly string drawName;
  205. public readonly string resourceName;
  206. public readonly string assetName;
  207. public readonly int categoryID;
  208. public readonly string thumbnailName;
  209. }
  210. }
  211. }