CreateBGObjectSubWindow.cs 7.1 KB

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