using System; using System.Collections.Generic; using System.IO; using UnityEngine; public abstract class BasePhotoWindowManager : MonoBehaviour { public static void SetCopyData(string title, string value) { if (!BasePhotoWindowManager.clipboard_.ContainsKey(title)) { BasePhotoWindowManager.clipboard_.Add(title, value); } else { BasePhotoWindowManager.clipboard_[title] = value; } } public static string GetCopyData(string title) { if (!BasePhotoWindowManager.clipboard_.ContainsKey(title)) { return string.Empty; } return BasePhotoWindowManager.clipboard_[title]; } public void Reset() { int panelDepth = this.PanelDepth; Transform transform = base.gameObject.transform; for (int i = 0; i < transform.childCount; i++) { BasePhotoWindow component = transform.GetChild(i).gameObject.GetComponent(); if (!(component == null)) { component.depth = panelDepth++; component.SetWindowManager(this); } } } public virtual void Awake() { BasePhotoWindowManager.clipboard_ = new Dictionary(); this.Reset(); int panelDepth = this.PanelDepth; this.front_depth_ = -1; Transform transform = base.gameObject.transform; for (int i = 0; i < transform.childCount; i++) { BasePhotoWindow component = transform.GetChild(i).gameObject.GetComponent(); if (!(component == null) && component.enabled) { component.gameObject.SetActive(true); this.OnAddWindow(component); this.front_depth_ = Math.Max(this.front_depth_, component.depth); this.window_dic_.Add(new KeyValuePair(component, component.depth)); component.SetWindowManager(this); } } } public virtual void Start() { this.Deserialize(); } protected virtual bool OnAddWindow(BasePhotoWindow add_win) { return true; } public BasePhotoWindow GetWindow(string uniqueWindowName) { foreach (KeyValuePair keyValuePair in this.window_dic_) { if (keyValuePair.Key.uniqueName == uniqueWindowName) { return keyValuePair.Key; } } return null; } public virtual void ResetPosition() { foreach (KeyValuePair keyValuePair in this.window_dic_) { keyValuePair.Key.ResetPosition(); } } public void ActiveWindow(BasePhotoWindow window) { if (window.depth != this.front_depth_) { window.depth = ++this.front_depth_; } if (40 <= this.front_depth_) { SortedList sortedList = new SortedList(); foreach (KeyValuePair keyValuePair in this.window_dic_) { sortedList.Add(keyValuePair.Key.depth, keyValuePair.Key); } this.front_depth_ = -1; foreach (KeyValuePair keyValuePair2 in sortedList) { keyValuePair2.Value.depth = ++this.front_depth_; } } } public void OnDestroy() { this.Serialize(); } public Dictionary> GetWoldStoreData(BasePhotoWindow photo_window) { return this.GetWoldStoreData(photo_window.name); } public Dictionary> GetWoldStoreData(string name) { if (!this.world_store_data_.ContainsKey(name)) { this.world_store_data_.Add(name, new Dictionary>()); } return this.world_store_data_[name]; } public void Serialize() { string name = base.gameObject.name; Dictionary> dictionary = new Dictionary>(); foreach (KeyValuePair keyValuePair in this.window_dic_) { KeyValuePair> keyValuePair2 = keyValuePair.Key.Serialize(); dictionary.Add(keyValuePair2.Key, keyValuePair2.Value); } if (this.save_data_.ContainsKey(name)) { this.save_data_.Remove(name); } this.save_data_.Add(name, dictionary); string save_fullpath_uidata = this.save_fullpath_uidata; Directory.CreateDirectory(save_fullpath_uidata.Replace(Path.GetFileName(save_fullpath_uidata), string.Empty)); using (MemoryStream memoryStream = new MemoryStream()) { using (BinaryWriter binaryWriter = new BinaryWriter(memoryStream)) { binaryWriter.Write(this.save_header_uidata); binaryWriter.Write(1300); binaryWriter.Write(this.save_data_.Count); foreach (KeyValuePair>> keyValuePair3 in this.save_data_) { binaryWriter.Write(keyValuePair3.Key); binaryWriter.Write(keyValuePair3.Value.Count); foreach (KeyValuePair> keyValuePair4 in keyValuePair3.Value) { binaryWriter.Write(keyValuePair4.Key); binaryWriter.Write(keyValuePair4.Value.Count); foreach (KeyValuePair keyValuePair5 in keyValuePair4.Value) { binaryWriter.Write(keyValuePair5.Key); binaryWriter.Write(keyValuePair5.Value); } } } } File.WriteAllBytes(save_fullpath_uidata, memoryStream.ToArray()); } } public void Deserialize() { this.save_data_ = new Dictionary>>(); string save_fullpath_uidata = this.save_fullpath_uidata; Directory.CreateDirectory(save_fullpath_uidata.Replace(Path.GetFileName(save_fullpath_uidata), string.Empty)); if (!File.Exists(save_fullpath_uidata)) { return; } using (FileStream fileStream = new FileStream(save_fullpath_uidata, FileMode.Open)) { if (fileStream == null) { return; } byte[] buffer = new byte[fileStream.Length]; fileStream.Read(buffer, 0, (int)fileStream.Length); using (BinaryReader binaryReader = new BinaryReader(new MemoryStream(buffer))) { if (binaryReader.ReadString() != this.save_header_uidata) { NDebug.Assert(this.save_header_uidata + "ファイルのヘッダーが不正です。", false); return; } int num = binaryReader.ReadInt32(); int num2 = binaryReader.ReadInt32(); for (int i = 0; i < num2; i++) { string key = binaryReader.ReadString(); int num3 = binaryReader.ReadInt32(); Dictionary> dictionary = new Dictionary>(); for (int j = 0; j < num3; j++) { string key2 = binaryReader.ReadString(); int num4 = binaryReader.ReadInt32(); Dictionary dictionary2 = new Dictionary(); for (int k = 0; k < num4; k++) { string key3 = binaryReader.ReadString(); string value = binaryReader.ReadString(); dictionary2.Add(key3, value); } dictionary.Add(key2, dictionary2); } this.save_data_.Add(key, dictionary); } } } string name = base.gameObject.name; if (this.save_data_.ContainsKey(name)) { Dictionary> dictionary3 = this.save_data_[name]; if (dictionary3 != null && 0 < dictionary3.Count) { foreach (KeyValuePair keyValuePair in this.window_dic_) { keyValuePair.Key.Deserialize(dictionary3); } } } } protected abstract string save_fullpath_uidata { get; } protected abstract string save_header_uidata { get; } public int PanelDepth; protected List> window_dic_ = new List>(); protected Dictionary>> world_store_data_ = new Dictionary>>(); private static Dictionary clipboard_ = new Dictionary(); private int front_depth_; private Dictionary>> save_data_; }