CreateBGObjectSubWindow.cs 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using UnityEngine;
  5. using wf;
  6. public class CreateBGObjectSubWindow : BasePhotoSubWindow
  7. {
  8. public void Awake()
  9. {
  10. PhotoBGObjectData.Create();
  11. if (this.addButtonList.popup_value_list != null)
  12. {
  13. return;
  14. }
  15. Dictionary<string, List<string>> dictionary = new Dictionary<string, List<string>>();
  16. Dictionary<string, List<KeyValuePair<string, object>>> dictionary2 = new Dictionary<string, List<KeyValuePair<string, object>>>();
  17. foreach (KeyValuePair<string, List<PhotoBGObjectData>> keyValuePair in PhotoBGObjectData.category_list)
  18. {
  19. if (!dictionary2.ContainsKey(keyValuePair.Key))
  20. {
  21. dictionary2.Add(keyValuePair.Key, new List<KeyValuePair<string, object>>());
  22. dictionary.Add(keyValuePair.Key, new List<string>());
  23. }
  24. for (int i = 0; i < keyValuePair.Value.Count; i++)
  25. {
  26. dictionary2[keyValuePair.Key].Add(new KeyValuePair<string, object>(keyValuePair.Value[i].name, keyValuePair.Value[i]));
  27. dictionary[keyValuePair.Key].Add(keyValuePair.Value[i].termName);
  28. }
  29. }
  30. this.addButtonList.SetData(dictionary2, dictionary, false);
  31. this.addButtonList.onClickEventList.Add(new Action<object>(this.OnClickItem));
  32. this.addButtonList.PopUpList.PopupList.isLocalized = GameUty.supportMultiLanguage;
  33. this.addButtonList.PopUpList.PopupList.itemTerms = ((!GameUty.supportMultiLanguage) ? null : PhotoBGObjectData.popup_category_term_list);
  34. this.addButtonList.popup_value_list = PhotoBGObjectData.popup_category_list;
  35. }
  36. public override void Initizalize(BasePhotoWindow parentWindow)
  37. {
  38. this.Awake();
  39. base.Initizalize(parentWindow);
  40. parentWindow.UpdateChildren();
  41. this.addButtonList.SetPopupValue(PhotoBGObjectData.popup_category_list[0].Key);
  42. }
  43. public void OnDestroy()
  44. {
  45. if (GameMain.Instance == null || GameMain.Instance.BgMgr == null || GameMain.Instance.BgMgr.bg_parent_object == null)
  46. {
  47. return;
  48. }
  49. foreach (CreateBGObjectSubWindow.BgObject bgObject in this.create_obj_list_)
  50. {
  51. if (this.mgr != null && this.mgr.GetWindow(PhotoWindowManager.WindowType.ObjectManager) != null)
  52. {
  53. ObjectManagerWindow objectManagerWindow = this.mgr.GetWindow(PhotoWindowManager.WindowType.ObjectManager) as ObjectManagerWindow;
  54. objectManagerWindow.RemoveTransTargetObject(bgObject.game_object);
  55. }
  56. UnityEngine.Object.DestroyImmediate(bgObject.game_object);
  57. }
  58. this.create_obj_list_.Clear();
  59. }
  60. private void OnClickItem(object select_data_obj)
  61. {
  62. if (select_data_obj == null)
  63. {
  64. return;
  65. }
  66. PhotoBGObjectData add_bg_data = select_data_obj as PhotoBGObjectData;
  67. this.AddObject(add_bg_data, string.Empty);
  68. }
  69. public void AddMyObject(string filePath)
  70. {
  71. PhotoBGObjectData photoBGObjectData = PhotoBGObjectData.AddMyObject(filePath);
  72. this.addButtonList.AddData("マイオブジェクト", new KeyValuePair<string, object>(photoBGObjectData.name, photoBGObjectData));
  73. }
  74. public void UpdateMyObject(string filePath)
  75. {
  76. foreach (CreateBGObjectSubWindow.BgObject bgObject in this.create_obj_list_)
  77. {
  78. if (!string.IsNullOrEmpty(bgObject.data.direct_file))
  79. {
  80. if (filePath == bgObject.data.direct_file)
  81. {
  82. PhotoCustomObjectPlane component = bgObject.game_object.GetComponent<PhotoCustomObjectPlane>();
  83. component.Desilialize(File.ReadAllBytes(filePath));
  84. }
  85. }
  86. }
  87. }
  88. private CreateBGObjectSubWindow.BgObject AddObject(PhotoBGObjectData add_bg_data, string create_time = "")
  89. {
  90. if (add_bg_data == null)
  91. {
  92. return null;
  93. }
  94. CreateBGObjectSubWindow.BgObject bgObject = new CreateBGObjectSubWindow.BgObject();
  95. bgObject.data = add_bg_data;
  96. if (!string.IsNullOrEmpty(create_time))
  97. {
  98. bgObject.create_time = create_time;
  99. }
  100. for (int i = 0; i < this.create_obj_list_.Count; i++)
  101. {
  102. if (this.create_obj_list_[i].create_time == bgObject.create_time)
  103. {
  104. return null;
  105. }
  106. }
  107. bgObject.game_object = bgObject.data.Instantiate(bgObject.create_time);
  108. if (bgObject.game_object == null)
  109. {
  110. return null;
  111. }
  112. this.create_obj_list_.Add(bgObject);
  113. this.create_obj_list_.Sort();
  114. ObjectManagerWindow objectManagerWindow = this.mgr.GetWindow(PhotoWindowManager.WindowType.ObjectManager) as ObjectManagerWindow;
  115. objectManagerWindow.AddTransTargetObject(bgObject.game_object, bgObject.data.name, bgObject.data.termName, PhotoTransTargetObject.Type.Prefab);
  116. return bgObject;
  117. }
  118. public void RemoveObject(GameObject removeObject)
  119. {
  120. if (removeObject == null)
  121. {
  122. return;
  123. }
  124. CreateBGObjectSubWindow.BgObject bgObject = null;
  125. foreach (CreateBGObjectSubWindow.BgObject bgObject2 in this.create_obj_list_)
  126. {
  127. if (bgObject2.game_object == removeObject)
  128. {
  129. bgObject = bgObject2;
  130. break;
  131. }
  132. }
  133. if (bgObject != null)
  134. {
  135. this.RemoveObject(bgObject);
  136. }
  137. }
  138. private void RemoveObject(CreateBGObjectSubWindow.BgObject removeObject)
  139. {
  140. if (removeObject == null)
  141. {
  142. return;
  143. }
  144. ObjectManagerWindow objectManagerWindow = this.mgr.GetWindow(PhotoWindowManager.WindowType.ObjectManager) as ObjectManagerWindow;
  145. objectManagerWindow.RemoveTransTargetObject(removeObject.game_object);
  146. UnityEngine.Object.DestroyImmediate(removeObject.game_object);
  147. this.create_obj_list_.Remove(removeObject);
  148. }
  149. public void OnSerializeEvent(ref Dictionary<string, Dictionary<string, string>> storeData)
  150. {
  151. for (int i = 0; i < this.create_obj_list_.Count; i++)
  152. {
  153. Dictionary<string, string> dictionary = new Dictionary<string, string>();
  154. CreateBGObjectSubWindow.BgObject bgObject = this.create_obj_list_[i];
  155. Transform transform = bgObject.game_object.transform;
  156. dictionary["id"] = bgObject.data.id.ToString();
  157. dictionary["position"] = transform.position.ToString("G9");
  158. dictionary["rotation"] = transform.rotation.ToString("G9");
  159. dictionary["scale"] = transform.localScale.ToString("G9");
  160. dictionary["visible"] = transform.gameObject.activeSelf.ToString();
  161. storeData.Add(bgObject.create_time, dictionary);
  162. }
  163. }
  164. public void OnDeserializeEvent(ref Dictionary<string, Dictionary<string, string>> storeData)
  165. {
  166. this.OnDestroy();
  167. List<string> list = new List<string>();
  168. foreach (KeyValuePair<string, Dictionary<string, string>> keyValuePair in storeData)
  169. {
  170. Dictionary<string, string> value = keyValuePair.Value;
  171. long id = long.Parse(value["id"]);
  172. string key = keyValuePair.Key;
  173. CreateBGObjectSubWindow.BgObject bgObject = this.AddObject(PhotoBGObjectData.Get(id), key);
  174. if (bgObject != null && bgObject.game_object != null)
  175. {
  176. Transform transform = bgObject.game_object.transform;
  177. transform.position = Parse.Vector3(value["position"]);
  178. transform.rotation = Parse.Quaternion(value["rotation"]);
  179. transform.localScale = Parse.Vector3(value["scale"]);
  180. bgObject.game_object.SetActive(bool.Parse(value["visible"]));
  181. }
  182. else
  183. {
  184. list.Add(keyValuePair.Key);
  185. }
  186. }
  187. for (int i = 0; i < list.Count; i++)
  188. {
  189. storeData.Remove(list[i]);
  190. }
  191. Utility.ResetNGUI(this.addButtonList.ScrollView);
  192. }
  193. public new PhotoWindowManager mgr
  194. {
  195. get
  196. {
  197. return base.mgr as PhotoWindowManager;
  198. }
  199. }
  200. public PopupAndButtonList addButtonList;
  201. private List<CreateBGObjectSubWindow.BgObject> create_obj_list_ = new List<CreateBGObjectSubWindow.BgObject>();
  202. private class BgObject : IComparable<CreateBGObjectSubWindow.BgObject>
  203. {
  204. public BgObject()
  205. {
  206. this.create_time = DateTime.Now.ToString("yyyyMMddHHmmssfff");
  207. }
  208. public int CompareTo(CreateBGObjectSubWindow.BgObject obj)
  209. {
  210. if (obj == null)
  211. {
  212. return 1;
  213. }
  214. return long.Parse(this.create_time).CompareTo(long.Parse(obj.create_time));
  215. }
  216. public string create_time;
  217. public GameObject game_object;
  218. public PhotoBGObjectData data;
  219. }
  220. }