PhotoBGObjectData.cs 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  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. HashSet<string> hashSet2 = new HashSet<string>();
  66. for (int j = 0; j < PhotoBGObjectData.bg_data_.Count; j++)
  67. {
  68. if (!PhotoBGObjectData.category_list_.ContainsKey(PhotoBGObjectData.bg_data_[j].category))
  69. {
  70. PhotoBGObjectData.category_list_.Add(PhotoBGObjectData.bg_data_[j].category, new List<PhotoBGObjectData>());
  71. }
  72. PhotoBGObjectData.category_list_[PhotoBGObjectData.bg_data_[j].category].Add(PhotoBGObjectData.bg_data_[j]);
  73. if (!hashSet2.Contains(PhotoBGObjectData.bg_data_[j].category))
  74. {
  75. PhotoBGObjectData.popup_menu_list_.Add(new KeyValuePair<string, UnityEngine.Object>(PhotoBGObjectData.bg_data_[j].category, null));
  76. hashSet2.Add(PhotoBGObjectData.bg_data_[j].category);
  77. }
  78. }
  79. if (!hashSet2.Contains("マイオブジェクト"))
  80. {
  81. PhotoBGObjectData.popup_menu_list_.Add(new KeyValuePair<string, UnityEngine.Object>("マイオブジェクト", null));
  82. PhotoBGObjectData.category_list_.Add("マイオブジェクト", new List<PhotoBGObjectData>());
  83. }
  84. }
  85. public static PhotoBGObjectData AddMyObject(string fullPath)
  86. {
  87. if (!File.Exists(fullPath))
  88. {
  89. return null;
  90. }
  91. using (FileStream fileStream = new FileStream(fullPath, FileMode.Open, FileAccess.Read))
  92. {
  93. using (BinaryReader binaryReader = new BinaryReader(fileStream))
  94. {
  95. string a = binaryReader.ReadString();
  96. if (a != "COM3D2_PHOTO_CUSTOM_OBJECT")
  97. {
  98. return null;
  99. }
  100. }
  101. }
  102. string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(Path.GetFileName(fullPath));
  103. PhotoBGObjectData photoBGObjectData = new PhotoBGObjectData();
  104. photoBGObjectData.id = (long)fileNameWithoutExtension.GetHashCode();
  105. photoBGObjectData.category = "マイオブジェクト";
  106. photoBGObjectData.name = fileNameWithoutExtension;
  107. photoBGObjectData.direct_file = fullPath;
  108. PhotoBGObjectData.bg_data_.Add(photoBGObjectData);
  109. return photoBGObjectData;
  110. }
  111. public static List<PhotoBGObjectData> data
  112. {
  113. get
  114. {
  115. return PhotoBGObjectData.bg_data_;
  116. }
  117. }
  118. public static Dictionary<string, List<PhotoBGObjectData>> category_list
  119. {
  120. get
  121. {
  122. return PhotoBGObjectData.category_list_;
  123. }
  124. }
  125. public static List<KeyValuePair<string, UnityEngine.Object>> popup_category_list
  126. {
  127. get
  128. {
  129. return PhotoBGObjectData.popup_menu_list_;
  130. }
  131. }
  132. public static PhotoBGObjectData Get(long id)
  133. {
  134. for (int i = 0; i < PhotoBGObjectData.bg_data_.Count; i++)
  135. {
  136. if (PhotoBGObjectData.bg_data_[i].id == id)
  137. {
  138. return PhotoBGObjectData.bg_data_[i];
  139. }
  140. }
  141. return null;
  142. }
  143. public GameObject Instantiate(string name)
  144. {
  145. Transform transform = GameMain.Instance.BgMgr.bg_parent_object.transform.Find("PhotoPrefab");
  146. if (transform == null)
  147. {
  148. GameObject gameObject = new GameObject("PhotoPrefab");
  149. gameObject.transform.SetParent(GameMain.Instance.BgMgr.bg_parent_object.transform, false);
  150. transform = gameObject.transform;
  151. }
  152. GameObject gameObject2 = null;
  153. if (!string.IsNullOrEmpty(this.create_prefab_name))
  154. {
  155. UnityEngine.Object @object = Resources.Load("Prefab/" + this.create_prefab_name);
  156. if (@object == null)
  157. {
  158. return null;
  159. }
  160. gameObject2 = (UnityEngine.Object.Instantiate(@object) as GameObject);
  161. }
  162. else if (!string.IsNullOrEmpty(this.create_asset_bundle_name))
  163. {
  164. GameObject gameObject3 = GameMain.Instance.BgMgr.CreateAssetBundle(this.create_asset_bundle_name);
  165. if (gameObject3 == null)
  166. {
  167. return null;
  168. }
  169. gameObject2 = UnityEngine.Object.Instantiate<GameObject>(gameObject3);
  170. }
  171. else if (!string.IsNullOrEmpty(this.direct_file))
  172. {
  173. BasePhotoCustomObject basePhotoCustomObject = BasePhotoCustomObject.InstantiateFromFile(transform.gameObject, this.direct_file);
  174. gameObject2 = basePhotoCustomObject.gameObject;
  175. }
  176. if (gameObject2 == null)
  177. {
  178. return null;
  179. }
  180. if (gameObject2.GetComponentInChildren<BoxCollider>() == null)
  181. {
  182. MeshRenderer componentInChildren = gameObject2.GetComponentInChildren<MeshRenderer>(true);
  183. if (componentInChildren != null)
  184. {
  185. componentInChildren.gameObject.AddComponent<BoxCollider>();
  186. }
  187. }
  188. if (!string.IsNullOrEmpty(name))
  189. {
  190. gameObject2.name = name;
  191. }
  192. gameObject2.transform.SetParent(transform);
  193. return gameObject2;
  194. }
  195. public long id;
  196. public string category;
  197. public string name;
  198. public string create_prefab_name;
  199. public string create_asset_bundle_name;
  200. public string direct_file;
  201. private static List<PhotoBGObjectData> bg_data_;
  202. private static Dictionary<string, List<PhotoBGObjectData>> category_list_;
  203. private static List<KeyValuePair<string, UnityEngine.Object>> popup_menu_list_;
  204. }