PhotoBGObjectData.cs 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using UnityEngine;
  5. using wf;
  6. public class PhotoBGObjectData
  7. {
  8. private PhotoBGObjectData()
  9. {
  10. }
  11. public static void Create()
  12. {
  13. if (PhotoBGObjectData.bg_data_ != null)
  14. {
  15. return;
  16. }
  17. PhotoBGObjectData.bg_data_ = new List<PhotoBGObjectData>();
  18. HashSet<int> hashSet = new HashSet<int>();
  19. CsvCommonIdManager.ReadEnabledIdList(CsvCommonIdManager.FileSystemType.Normal, true, "phot_bg_object_enabled_list", ref hashSet);
  20. using (AFileBase afileBase = GameUty.FileSystem.FileOpen("phot_bg_object_list.nei"))
  21. {
  22. using (CsvParser csvParser = new CsvParser())
  23. {
  24. bool condition = csvParser.Open(afileBase);
  25. NDebug.Assert(condition, "phot_bg_object_list.nei\nopen failed.");
  26. for (int i = 1; i < csvParser.max_cell_y; i++)
  27. {
  28. if (csvParser.IsCellToExistData(0, i) && hashSet.Contains(csvParser.GetCellAsInteger(0, i)))
  29. {
  30. int num = 0;
  31. PhotoBGObjectData photoBGObjectData = new PhotoBGObjectData();
  32. photoBGObjectData.id = (long)csvParser.GetCellAsInteger(num++, i);
  33. photoBGObjectData.category = csvParser.GetCellAsString(num++, i);
  34. photoBGObjectData.name = csvParser.GetCellAsString(num++, i);
  35. photoBGObjectData.create_prefab_name = csvParser.GetCellAsString(num++, i);
  36. photoBGObjectData.create_asset_bundle_name = csvParser.GetCellAsString(num++, i);
  37. string cellAsString = csvParser.GetCellAsString(num++, i);
  38. if (string.IsNullOrEmpty(cellAsString) || PluginData.IsEnabled(cellAsString))
  39. {
  40. PhotoBGObjectData.bg_data_.Add(photoBGObjectData);
  41. }
  42. }
  43. }
  44. }
  45. }
  46. Action<string, List<string>> action = delegate(string path, List<string> result_list)
  47. {
  48. string[] files = Directory.GetFiles(path);
  49. for (int k = 0; k < files.Length; k++)
  50. {
  51. if (Path.GetExtension(files[k]) == ".poj")
  52. {
  53. result_list.Add(files[k]);
  54. }
  55. }
  56. };
  57. List<string> list = new List<string>();
  58. action(ObjectCreateWindow.folder_path, list);
  59. foreach (string fullPath in list)
  60. {
  61. PhotoBGObjectData.AddMyObject(fullPath);
  62. }
  63. PhotoBGObjectData.category_list_ = new Dictionary<string, List<PhotoBGObjectData>>();
  64. PhotoBGObjectData.popup_menu_list_ = new List<KeyValuePair<string, UnityEngine.Object>>();
  65. PhotoBGObjectData.popup_category_term_list = new List<string>();
  66. HashSet<string> hashSet2 = new HashSet<string>();
  67. for (int j = 0; j < PhotoBGObjectData.bg_data_.Count; j++)
  68. {
  69. if (!PhotoBGObjectData.category_list_.ContainsKey(PhotoBGObjectData.bg_data_[j].category))
  70. {
  71. PhotoBGObjectData.category_list_.Add(PhotoBGObjectData.bg_data_[j].category, new List<PhotoBGObjectData>());
  72. }
  73. PhotoBGObjectData.category_list_[PhotoBGObjectData.bg_data_[j].category].Add(PhotoBGObjectData.bg_data_[j]);
  74. if (!hashSet2.Contains(PhotoBGObjectData.bg_data_[j].category))
  75. {
  76. PhotoBGObjectData.popup_menu_list_.Add(new KeyValuePair<string, UnityEngine.Object>(PhotoBGObjectData.bg_data_[j].category, null));
  77. PhotoBGObjectData.popup_category_term_list.Add("ScenePhotoMode/背景オブジェクト/カテゴリー/" + PhotoBGObjectData.bg_data_[j].category);
  78. hashSet2.Add(PhotoBGObjectData.bg_data_[j].category);
  79. }
  80. }
  81. if (!hashSet2.Contains("マイオブジェクト"))
  82. {
  83. PhotoBGObjectData.popup_menu_list_.Add(new KeyValuePair<string, UnityEngine.Object>("マイオブジェクト", null));
  84. PhotoBGObjectData.popup_category_term_list.Add("ScenePhotoMode/背景オブジェクト/カテゴリー/マイオブジェクト");
  85. PhotoBGObjectData.category_list_.Add("マイオブジェクト", new List<PhotoBGObjectData>());
  86. }
  87. }
  88. public static PhotoBGObjectData AddMyObject(string fullPath)
  89. {
  90. if (!File.Exists(fullPath))
  91. {
  92. return null;
  93. }
  94. using (FileStream fileStream = new FileStream(fullPath, FileMode.Open, FileAccess.Read))
  95. {
  96. using (BinaryReader binaryReader = new BinaryReader(fileStream))
  97. {
  98. string a = binaryReader.ReadString();
  99. if (a != "COM3D2_PHOTO_CUSTOM_OBJECT")
  100. {
  101. return null;
  102. }
  103. }
  104. }
  105. string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(Path.GetFileName(fullPath));
  106. PhotoBGObjectData photoBGObjectData = new PhotoBGObjectData();
  107. photoBGObjectData.id = (long)fileNameWithoutExtension.GetHashCode();
  108. photoBGObjectData.category = "マイオブジェクト";
  109. photoBGObjectData.name = fileNameWithoutExtension;
  110. photoBGObjectData.direct_file = fullPath;
  111. PhotoBGObjectData.bg_data_.Add(photoBGObjectData);
  112. return photoBGObjectData;
  113. }
  114. public string termName
  115. {
  116. get
  117. {
  118. return (!(this.category == "マイオブジェクト")) ? ("ScenePhotoMode/背景オブジェクト/" + this.id.ToString() + "/名前") : string.Empty;
  119. }
  120. }
  121. public static List<PhotoBGObjectData> data
  122. {
  123. get
  124. {
  125. return PhotoBGObjectData.bg_data_;
  126. }
  127. }
  128. public static Dictionary<string, List<PhotoBGObjectData>> category_list
  129. {
  130. get
  131. {
  132. return PhotoBGObjectData.category_list_;
  133. }
  134. }
  135. public static List<string> popup_category_term_list { get; private set; }
  136. public static List<KeyValuePair<string, UnityEngine.Object>> popup_category_list
  137. {
  138. get
  139. {
  140. return PhotoBGObjectData.popup_menu_list_;
  141. }
  142. }
  143. public static PhotoBGObjectData Get(long id)
  144. {
  145. for (int i = 0; i < PhotoBGObjectData.bg_data_.Count; i++)
  146. {
  147. if (PhotoBGObjectData.bg_data_[i].id == id)
  148. {
  149. return PhotoBGObjectData.bg_data_[i];
  150. }
  151. }
  152. return null;
  153. }
  154. public GameObject Instantiate(string name)
  155. {
  156. Transform transform = GameMain.Instance.BgMgr.bg_parent_object.transform.Find("PhotoPrefab");
  157. if (transform == null)
  158. {
  159. GameObject gameObject = new GameObject("PhotoPrefab");
  160. gameObject.transform.SetParent(GameMain.Instance.BgMgr.bg_parent_object.transform, false);
  161. transform = gameObject.transform;
  162. }
  163. GameObject gameObject2 = null;
  164. if (!string.IsNullOrEmpty(this.create_prefab_name))
  165. {
  166. UnityEngine.Object @object = Resources.Load("Prefab/" + this.create_prefab_name);
  167. if (@object == null)
  168. {
  169. return null;
  170. }
  171. gameObject2 = (UnityEngine.Object.Instantiate(@object) as GameObject);
  172. }
  173. else if (!string.IsNullOrEmpty(this.create_asset_bundle_name))
  174. {
  175. GameObject gameObject3 = GameMain.Instance.BgMgr.CreateAssetBundle(this.create_asset_bundle_name);
  176. if (gameObject3 == null)
  177. {
  178. return null;
  179. }
  180. gameObject2 = UnityEngine.Object.Instantiate<GameObject>(gameObject3);
  181. }
  182. else if (!string.IsNullOrEmpty(this.direct_file))
  183. {
  184. BasePhotoCustomObject basePhotoCustomObject = BasePhotoCustomObject.InstantiateFromFile(transform.gameObject, this.direct_file);
  185. gameObject2 = basePhotoCustomObject.gameObject;
  186. }
  187. if (gameObject2 == null)
  188. {
  189. return null;
  190. }
  191. if (gameObject2.GetComponentInChildren<BoxCollider>() == null)
  192. {
  193. MeshRenderer componentInChildren = gameObject2.GetComponentInChildren<MeshRenderer>(true);
  194. if (componentInChildren != null)
  195. {
  196. componentInChildren.gameObject.AddComponent<BoxCollider>();
  197. }
  198. }
  199. if (!string.IsNullOrEmpty(name))
  200. {
  201. gameObject2.name = name;
  202. }
  203. gameObject2.transform.SetParent(transform);
  204. return gameObject2;
  205. }
  206. public long id;
  207. public string category;
  208. public string name;
  209. public string create_prefab_name;
  210. public string create_asset_bundle_name;
  211. public string direct_file;
  212. private static List<PhotoBGObjectData> bg_data_;
  213. private static Dictionary<string, List<PhotoBGObjectData>> category_list_;
  214. private static List<KeyValuePair<string, UnityEngine.Object>> popup_menu_list_;
  215. }