BasePhotoWindowManager.cs 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using UnityEngine;
  5. public abstract class BasePhotoWindowManager : MonoBehaviour
  6. {
  7. public static void SetCopyData(string title, string value)
  8. {
  9. if (!BasePhotoWindowManager.clipboard_.ContainsKey(title))
  10. {
  11. BasePhotoWindowManager.clipboard_.Add(title, value);
  12. }
  13. else
  14. {
  15. BasePhotoWindowManager.clipboard_[title] = value;
  16. }
  17. }
  18. public static string GetCopyData(string title)
  19. {
  20. if (!BasePhotoWindowManager.clipboard_.ContainsKey(title))
  21. {
  22. return string.Empty;
  23. }
  24. return BasePhotoWindowManager.clipboard_[title];
  25. }
  26. public void Reset()
  27. {
  28. int panelDepth = this.PanelDepth;
  29. Transform transform = base.gameObject.transform;
  30. for (int i = 0; i < transform.childCount; i++)
  31. {
  32. BasePhotoWindow component = transform.GetChild(i).gameObject.GetComponent<BasePhotoWindow>();
  33. if (!(component == null))
  34. {
  35. component.depth = panelDepth++;
  36. component.SetWindowManager(this);
  37. }
  38. }
  39. }
  40. public virtual void Awake()
  41. {
  42. BasePhotoWindowManager.clipboard_ = new Dictionary<string, string>();
  43. this.Reset();
  44. int panelDepth = this.PanelDepth;
  45. this.front_depth_ = -1;
  46. Transform transform = base.gameObject.transform;
  47. for (int i = 0; i < transform.childCount; i++)
  48. {
  49. BasePhotoWindow component = transform.GetChild(i).gameObject.GetComponent<BasePhotoWindow>();
  50. if (!(component == null) && component.enabled)
  51. {
  52. component.gameObject.SetActive(true);
  53. this.OnAddWindow(component);
  54. this.front_depth_ = Math.Max(this.front_depth_, component.depth);
  55. this.window_dic_.Add(new KeyValuePair<BasePhotoWindow, int>(component, component.depth));
  56. component.SetWindowManager(this);
  57. }
  58. }
  59. }
  60. public virtual void Start()
  61. {
  62. this.Deserialize();
  63. }
  64. protected virtual bool OnAddWindow(BasePhotoWindow add_win)
  65. {
  66. return true;
  67. }
  68. public BasePhotoWindow GetWindow(string uniqueWindowName)
  69. {
  70. foreach (KeyValuePair<BasePhotoWindow, int> keyValuePair in this.window_dic_)
  71. {
  72. if (keyValuePair.Key.uniqueName == uniqueWindowName)
  73. {
  74. return keyValuePair.Key;
  75. }
  76. }
  77. return null;
  78. }
  79. public virtual void ResetPosition()
  80. {
  81. foreach (KeyValuePair<BasePhotoWindow, int> keyValuePair in this.window_dic_)
  82. {
  83. keyValuePair.Key.ResetPosition();
  84. }
  85. }
  86. public void ActiveWindow(BasePhotoWindow window)
  87. {
  88. if (window.depth != this.front_depth_)
  89. {
  90. window.depth = ++this.front_depth_;
  91. }
  92. if (40 <= this.front_depth_)
  93. {
  94. SortedList<int, BasePhotoWindow> sortedList = new SortedList<int, BasePhotoWindow>();
  95. foreach (KeyValuePair<BasePhotoWindow, int> keyValuePair in this.window_dic_)
  96. {
  97. sortedList.Add(keyValuePair.Key.depth, keyValuePair.Key);
  98. }
  99. this.front_depth_ = -1;
  100. foreach (KeyValuePair<int, BasePhotoWindow> keyValuePair2 in sortedList)
  101. {
  102. keyValuePair2.Value.depth = ++this.front_depth_;
  103. }
  104. }
  105. }
  106. public void OnDestroy()
  107. {
  108. this.Serialize();
  109. }
  110. public Dictionary<string, Dictionary<string, string>> GetWoldStoreData(BasePhotoWindow photo_window)
  111. {
  112. return this.GetWoldStoreData(photo_window.name);
  113. }
  114. public Dictionary<string, Dictionary<string, string>> GetWoldStoreData(string name)
  115. {
  116. if (!this.world_store_data_.ContainsKey(name))
  117. {
  118. this.world_store_data_.Add(name, new Dictionary<string, Dictionary<string, string>>());
  119. }
  120. return this.world_store_data_[name];
  121. }
  122. public void Serialize()
  123. {
  124. string name = base.gameObject.name;
  125. Dictionary<string, Dictionary<string, string>> dictionary = new Dictionary<string, Dictionary<string, string>>();
  126. foreach (KeyValuePair<BasePhotoWindow, int> keyValuePair in this.window_dic_)
  127. {
  128. KeyValuePair<string, Dictionary<string, string>> keyValuePair2 = keyValuePair.Key.Serialize();
  129. dictionary.Add(keyValuePair2.Key, keyValuePair2.Value);
  130. }
  131. if (this.save_data_.ContainsKey(name))
  132. {
  133. this.save_data_.Remove(name);
  134. }
  135. this.save_data_.Add(name, dictionary);
  136. string save_fullpath_uidata = this.save_fullpath_uidata;
  137. Directory.CreateDirectory(save_fullpath_uidata.Replace(Path.GetFileName(save_fullpath_uidata), string.Empty));
  138. using (MemoryStream memoryStream = new MemoryStream())
  139. {
  140. using (BinaryWriter binaryWriter = new BinaryWriter(memoryStream))
  141. {
  142. binaryWriter.Write(this.save_header_uidata);
  143. binaryWriter.Write(1270);
  144. binaryWriter.Write(this.save_data_.Count);
  145. foreach (KeyValuePair<string, Dictionary<string, Dictionary<string, string>>> keyValuePair3 in this.save_data_)
  146. {
  147. binaryWriter.Write(keyValuePair3.Key);
  148. binaryWriter.Write(keyValuePair3.Value.Count);
  149. foreach (KeyValuePair<string, Dictionary<string, string>> keyValuePair4 in keyValuePair3.Value)
  150. {
  151. binaryWriter.Write(keyValuePair4.Key);
  152. binaryWriter.Write(keyValuePair4.Value.Count);
  153. foreach (KeyValuePair<string, string> keyValuePair5 in keyValuePair4.Value)
  154. {
  155. binaryWriter.Write(keyValuePair5.Key);
  156. binaryWriter.Write(keyValuePair5.Value);
  157. }
  158. }
  159. }
  160. }
  161. File.WriteAllBytes(save_fullpath_uidata, memoryStream.ToArray());
  162. }
  163. }
  164. public void Deserialize()
  165. {
  166. this.save_data_ = new Dictionary<string, Dictionary<string, Dictionary<string, string>>>();
  167. string save_fullpath_uidata = this.save_fullpath_uidata;
  168. Directory.CreateDirectory(save_fullpath_uidata.Replace(Path.GetFileName(save_fullpath_uidata), string.Empty));
  169. if (!File.Exists(save_fullpath_uidata))
  170. {
  171. return;
  172. }
  173. using (FileStream fileStream = new FileStream(save_fullpath_uidata, FileMode.Open))
  174. {
  175. if (fileStream == null)
  176. {
  177. return;
  178. }
  179. byte[] buffer = new byte[fileStream.Length];
  180. fileStream.Read(buffer, 0, (int)fileStream.Length);
  181. using (BinaryReader binaryReader = new BinaryReader(new MemoryStream(buffer)))
  182. {
  183. if (binaryReader.ReadString() != this.save_header_uidata)
  184. {
  185. NDebug.Assert(this.save_header_uidata + "ファイルのヘッダーが不正です。", false);
  186. return;
  187. }
  188. int num = binaryReader.ReadInt32();
  189. int num2 = binaryReader.ReadInt32();
  190. for (int i = 0; i < num2; i++)
  191. {
  192. string key = binaryReader.ReadString();
  193. int num3 = binaryReader.ReadInt32();
  194. Dictionary<string, Dictionary<string, string>> dictionary = new Dictionary<string, Dictionary<string, string>>();
  195. for (int j = 0; j < num3; j++)
  196. {
  197. string key2 = binaryReader.ReadString();
  198. int num4 = binaryReader.ReadInt32();
  199. Dictionary<string, string> dictionary2 = new Dictionary<string, string>();
  200. for (int k = 0; k < num4; k++)
  201. {
  202. string key3 = binaryReader.ReadString();
  203. string value = binaryReader.ReadString();
  204. dictionary2.Add(key3, value);
  205. }
  206. dictionary.Add(key2, dictionary2);
  207. }
  208. this.save_data_.Add(key, dictionary);
  209. }
  210. }
  211. }
  212. string name = base.gameObject.name;
  213. if (this.save_data_.ContainsKey(name))
  214. {
  215. Dictionary<string, Dictionary<string, string>> dictionary3 = this.save_data_[name];
  216. if (dictionary3 != null && 0 < dictionary3.Count)
  217. {
  218. foreach (KeyValuePair<BasePhotoWindow, int> keyValuePair in this.window_dic_)
  219. {
  220. keyValuePair.Key.Deserialize(dictionary3);
  221. }
  222. }
  223. }
  224. }
  225. protected abstract string save_fullpath_uidata { get; }
  226. protected abstract string save_header_uidata { get; }
  227. public int PanelDepth;
  228. protected List<KeyValuePair<BasePhotoWindow, int>> window_dic_ = new List<KeyValuePair<BasePhotoWindow, int>>();
  229. protected Dictionary<string, Dictionary<string, Dictionary<string, string>>> world_store_data_ = new Dictionary<string, Dictionary<string, Dictionary<string, string>>>();
  230. private static Dictionary<string, string> clipboard_ = new Dictionary<string, string>();
  231. private int front_depth_;
  232. private Dictionary<string, Dictionary<string, Dictionary<string, string>>> save_data_;
  233. }