PlacementData.cs 6.3 KB

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