BGObjectWindow.cs 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. using System;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using wf;
  5. public class BGObjectWindow : BaseMaidPhotoWindow
  6. {
  7. public override void Awake()
  8. {
  9. base.Awake();
  10. PhotoBGObjectData.Create();
  11. this.scroll_view_ = NGUITools.FindInParents<UIScrollView>(this.Grid.transform);
  12. this.add_scroll_view_ = NGUITools.FindInParents<UIScrollView>(this.AddGrid.transform);
  13. for (int i = 0; i < PhotoBGObjectData.data.Count; i++)
  14. {
  15. PhotoBGObjectData photoBGObjectData = PhotoBGObjectData.data[i];
  16. GameObject gameObject = Utility.CreatePrefab(this.Grid.gameObject, "ScenePhotoMode/WindowListItemNormalButton", true);
  17. gameObject.name = photoBGObjectData.id.ToString();
  18. gameObject.GetComponentInChildren<UILabel>().text = photoBGObjectData.name;
  19. EventDelegate.Add(gameObject.GetComponent<UIButton>().onClick, new EventDelegate.Callback(this.OnClickAdd));
  20. }
  21. NGUITools.FindInParents<UIScrollView>(this.Grid.transform).ResetPosition();
  22. this.Grid.Reposition();
  23. this.UpdateChildren();
  24. }
  25. public override void Start()
  26. {
  27. base.Start();
  28. }
  29. public void OnDestroy()
  30. {
  31. if (GameMain.Instance == null || GameMain.Instance.BgMgr == null || GameMain.Instance.BgMgr.bg_parent_object == null)
  32. {
  33. return;
  34. }
  35. foreach (BGObjectWindow.BgObject bgObject in this.create_obj_list_)
  36. {
  37. if (this.mgr != null && this.mgr.GetWindow(PhotoWindowManager.WindowType.ObjectManager) != null)
  38. {
  39. ObjectManagerWindow objectManagerWindow = this.mgr.GetWindow(PhotoWindowManager.WindowType.ObjectManager) as ObjectManagerWindow;
  40. objectManagerWindow.RemoveTransTargetObject(bgObject.game_object);
  41. }
  42. UnityEngine.Object.DestroyImmediate(bgObject.game_object);
  43. }
  44. this.create_obj_list_.Clear();
  45. }
  46. public void OnClickAdd()
  47. {
  48. this.AddObject(PhotoBGObjectData.Get(long.Parse(UIButton.current.name)), string.Empty);
  49. }
  50. public void OnClickRemove()
  51. {
  52. string name = UIButton.current.name;
  53. for (int i = 0; i < this.create_obj_list_.Count; i++)
  54. {
  55. if (this.create_obj_list_[i].create_time == name)
  56. {
  57. ObjectManagerWindow objectManagerWindow = this.mgr.GetWindow(PhotoWindowManager.WindowType.ObjectManager) as ObjectManagerWindow;
  58. objectManagerWindow.RemoveTransTargetObject(this.create_obj_list_[i].game_object);
  59. UnityEngine.Object.DestroyImmediate(this.create_obj_list_[i].game_object);
  60. this.create_obj_list_.RemoveAt(i);
  61. UnityEngine.Object.DestroyImmediate(UIButton.current.gameObject);
  62. this.AddGrid.Reposition();
  63. this.add_scroll_view_.UpdateScrollbars();
  64. break;
  65. }
  66. }
  67. }
  68. public override void OnSerializeEvent()
  69. {
  70. base.OnSerializeEvent();
  71. Dictionary<string, Dictionary<string, string>> woldStoreData = base.GetWoldStoreData();
  72. woldStoreData.Clear();
  73. for (int i = 0; i < this.create_obj_list_.Count; i++)
  74. {
  75. Dictionary<string, string> dictionary = new Dictionary<string, string>();
  76. BGObjectWindow.BgObject bgObject = this.create_obj_list_[i];
  77. Transform transform = bgObject.game_object.transform;
  78. dictionary["id"] = bgObject.data.id.ToString();
  79. dictionary["position"] = transform.position.ToString("G9");
  80. dictionary["rotation"] = transform.rotation.ToString("G9");
  81. dictionary["scale"] = transform.localScale.ToString("G9");
  82. dictionary["visible"] = transform.gameObject.activeSelf.ToString();
  83. woldStoreData.Add(bgObject.create_time, dictionary);
  84. }
  85. }
  86. public override void OnDeserializeEvent()
  87. {
  88. UIButton current = UIButton.current;
  89. List<Transform> childList = this.AddGrid.GetChildList();
  90. for (int i = 0; i < childList.Count; i++)
  91. {
  92. UIButton.current = childList[i].GetComponentInChildren<UIButton>();
  93. this.OnClickRemove();
  94. }
  95. UIButton.current = current;
  96. this.OnDestroy();
  97. this.create_obj_list_.Clear();
  98. List<string> list = new List<string>();
  99. Dictionary<string, Dictionary<string, string>> woldStoreData = base.GetWoldStoreData();
  100. foreach (KeyValuePair<string, Dictionary<string, string>> keyValuePair in woldStoreData)
  101. {
  102. Dictionary<string, string> value = keyValuePair.Value;
  103. long id = long.Parse(value["id"]);
  104. string key = keyValuePair.Key;
  105. BGObjectWindow.BgObject bgObject = this.AddObject(PhotoBGObjectData.Get(id), key);
  106. if (bgObject != null && bgObject.game_object != null)
  107. {
  108. Transform transform = bgObject.game_object.transform;
  109. transform.position = Parse.Vector3(value["position"]);
  110. transform.rotation = Parse.Quaternion(value["rotation"]);
  111. transform.localScale = Parse.Vector3(value["scale"]);
  112. bgObject.game_object.SetActive(bool.Parse(value["visible"]));
  113. }
  114. else
  115. {
  116. list.Add(keyValuePair.Key);
  117. }
  118. }
  119. for (int j = 0; j < list.Count; j++)
  120. {
  121. woldStoreData.Remove(list[j]);
  122. }
  123. this.Grid.Reposition();
  124. this.AddGrid.Reposition();
  125. this.scroll_view_.ResetPosition();
  126. this.add_scroll_view_.ResetPosition();
  127. }
  128. private BGObjectWindow.BgObject AddObject(PhotoBGObjectData add_bg_data, string create_time = "")
  129. {
  130. if (add_bg_data == null)
  131. {
  132. return null;
  133. }
  134. BGObjectWindow.BgObject bgObject = new BGObjectWindow.BgObject();
  135. bgObject.data = add_bg_data;
  136. if (!string.IsNullOrEmpty(create_time))
  137. {
  138. bgObject.create_time = create_time;
  139. }
  140. for (int i = 0; i < this.create_obj_list_.Count; i++)
  141. {
  142. if (this.create_obj_list_[i].create_time == bgObject.create_time)
  143. {
  144. return null;
  145. }
  146. }
  147. bgObject.game_object = bgObject.data.Instantiate(bgObject.create_time);
  148. if (bgObject.game_object == null)
  149. {
  150. return null;
  151. }
  152. this.create_obj_list_.Add(bgObject);
  153. this.create_obj_list_.Sort();
  154. ObjectManagerWindow objectManagerWindow = this.mgr.GetWindow(PhotoWindowManager.WindowType.ObjectManager) as ObjectManagerWindow;
  155. objectManagerWindow.AddTransTargetObject(bgObject.game_object, bgObject.data.name, PhotoTransTargetObject.Type.Prefab);
  156. GameObject gameObject = Utility.CreatePrefab(this.AddGrid.gameObject, "ScenePhotoMode/WindowListItemNormalButton", true);
  157. gameObject.name = bgObject.create_time.ToString();
  158. gameObject.GetComponentInChildren<UILabel>().text = bgObject.data.name;
  159. EventDelegate.Add(gameObject.GetComponent<UIButton>().onClick, new EventDelegate.Callback(this.OnClickRemove));
  160. this.AddGrid.Reposition();
  161. this.add_scroll_view_.UpdateScrollbars();
  162. return bgObject;
  163. }
  164. public new PhotoWindowManager mgr
  165. {
  166. get
  167. {
  168. return base.mgr;
  169. }
  170. }
  171. public UIGrid Grid;
  172. public UIGrid AddGrid;
  173. private UIScrollView scroll_view_;
  174. private UIScrollView add_scroll_view_;
  175. private List<BGObjectWindow.BgObject> create_obj_list_ = new List<BGObjectWindow.BgObject>();
  176. private class BgObject : IComparable<BGObjectWindow.BgObject>
  177. {
  178. public BgObject()
  179. {
  180. this.create_time = DateTime.Now.ToString("yyyyMMddHHmmssfff");
  181. }
  182. public int CompareTo(BGObjectWindow.BgObject obj)
  183. {
  184. if (obj == null)
  185. {
  186. return 1;
  187. }
  188. return long.Parse(this.create_time).CompareTo(long.Parse(obj.create_time));
  189. }
  190. public string create_time;
  191. public GameObject game_object;
  192. public PhotoBGObjectData data;
  193. }
  194. }