123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239 |
- using System;
- using System.Collections.Generic;
- using System.IO;
- using UnityEngine;
- using wf;
- public class CreateBGObjectSubWindow : BasePhotoSubWindow
- {
- public void Awake()
- {
- PhotoBGObjectData.Create();
- if (this.addButtonList.popup_value_list != null)
- {
- return;
- }
- Dictionary<string, List<string>> dictionary = new Dictionary<string, List<string>>();
- Dictionary<string, List<KeyValuePair<string, object>>> dictionary2 = new Dictionary<string, List<KeyValuePair<string, object>>>();
- foreach (KeyValuePair<string, List<PhotoBGObjectData>> keyValuePair in PhotoBGObjectData.category_list)
- {
- if (!dictionary2.ContainsKey(keyValuePair.Key))
- {
- dictionary2.Add(keyValuePair.Key, new List<KeyValuePair<string, object>>());
- dictionary.Add(keyValuePair.Key, new List<string>());
- }
- for (int i = 0; i < keyValuePair.Value.Count; i++)
- {
- dictionary2[keyValuePair.Key].Add(new KeyValuePair<string, object>(keyValuePair.Value[i].name, keyValuePair.Value[i]));
- dictionary[keyValuePair.Key].Add(keyValuePair.Value[i].termName);
- }
- }
- this.addButtonList.SetData(dictionary2, dictionary, false);
- this.addButtonList.onClickEventList.Add(new Action<object>(this.OnClickItem));
- this.addButtonList.PopUpList.PopupList.isLocalized = GameUty.supportMultiLanguage;
- this.addButtonList.PopUpList.PopupList.itemTerms = ((!GameUty.supportMultiLanguage) ? null : PhotoBGObjectData.popup_category_term_list);
- this.addButtonList.popup_value_list = PhotoBGObjectData.popup_category_list;
- }
- public override void Initizalize(BasePhotoWindow parentWindow)
- {
- this.Awake();
- base.Initizalize(parentWindow);
- parentWindow.UpdateChildren();
- this.addButtonList.SetPopupValue(PhotoBGObjectData.popup_category_list[0].Key);
- }
- public void OnDestroy()
- {
- if (GameMain.Instance == null || GameMain.Instance.BgMgr == null || GameMain.Instance.BgMgr.bg_parent_object == null)
- {
- return;
- }
- foreach (CreateBGObjectSubWindow.BgObject bgObject in this.create_obj_list_)
- {
- if (this.mgr != null && this.mgr.GetWindow(PhotoWindowManager.WindowType.ObjectManager) != null)
- {
- ObjectManagerWindow objectManagerWindow = this.mgr.GetWindow(PhotoWindowManager.WindowType.ObjectManager) as ObjectManagerWindow;
- objectManagerWindow.RemoveTransTargetObject(bgObject.game_object);
- }
- UnityEngine.Object.DestroyImmediate(bgObject.game_object);
- }
- this.create_obj_list_.Clear();
- }
- private void OnClickItem(object select_data_obj)
- {
- if (select_data_obj == null)
- {
- return;
- }
- PhotoBGObjectData add_bg_data = select_data_obj as PhotoBGObjectData;
- this.AddObject(add_bg_data, string.Empty);
- }
- public void AddMyObject(string filePath)
- {
- PhotoBGObjectData photoBGObjectData = PhotoBGObjectData.AddMyObject(filePath);
- this.addButtonList.AddData("マイオブジェクト", new KeyValuePair<string, object>(photoBGObjectData.name, photoBGObjectData));
- }
- public void UpdateMyObject(string filePath)
- {
- foreach (CreateBGObjectSubWindow.BgObject bgObject in this.create_obj_list_)
- {
- if (!string.IsNullOrEmpty(bgObject.data.direct_file))
- {
- if (filePath == bgObject.data.direct_file)
- {
- PhotoCustomObjectPlane component = bgObject.game_object.GetComponent<PhotoCustomObjectPlane>();
- component.Desilialize(File.ReadAllBytes(filePath));
- }
- }
- }
- }
- private CreateBGObjectSubWindow.BgObject AddObject(PhotoBGObjectData add_bg_data, string create_time = "")
- {
- if (add_bg_data == null)
- {
- return null;
- }
- CreateBGObjectSubWindow.BgObject bgObject = new CreateBGObjectSubWindow.BgObject();
- bgObject.data = add_bg_data;
- if (!string.IsNullOrEmpty(create_time))
- {
- bgObject.create_time = create_time;
- }
- for (int i = 0; i < this.create_obj_list_.Count; i++)
- {
- if (this.create_obj_list_[i].create_time == bgObject.create_time)
- {
- return null;
- }
- }
- bgObject.game_object = bgObject.data.Instantiate(bgObject.create_time);
- if (bgObject.game_object == null)
- {
- return null;
- }
- this.create_obj_list_.Add(bgObject);
- this.create_obj_list_.Sort();
- ObjectManagerWindow objectManagerWindow = this.mgr.GetWindow(PhotoWindowManager.WindowType.ObjectManager) as ObjectManagerWindow;
- objectManagerWindow.AddTransTargetObject(bgObject.game_object, bgObject.data.name, bgObject.data.termName, PhotoTransTargetObject.Type.Prefab);
- return bgObject;
- }
- public void RemoveObject(GameObject removeObject)
- {
- if (removeObject == null)
- {
- return;
- }
- CreateBGObjectSubWindow.BgObject bgObject = null;
- foreach (CreateBGObjectSubWindow.BgObject bgObject2 in this.create_obj_list_)
- {
- if (bgObject2.game_object == removeObject)
- {
- bgObject = bgObject2;
- break;
- }
- }
- if (bgObject != null)
- {
- this.RemoveObject(bgObject);
- }
- }
- private void RemoveObject(CreateBGObjectSubWindow.BgObject removeObject)
- {
- if (removeObject == null)
- {
- return;
- }
- ObjectManagerWindow objectManagerWindow = this.mgr.GetWindow(PhotoWindowManager.WindowType.ObjectManager) as ObjectManagerWindow;
- objectManagerWindow.RemoveTransTargetObject(removeObject.game_object);
- UnityEngine.Object.DestroyImmediate(removeObject.game_object);
- this.create_obj_list_.Remove(removeObject);
- }
- public void OnSerializeEvent(ref Dictionary<string, Dictionary<string, string>> storeData)
- {
- for (int i = 0; i < this.create_obj_list_.Count; i++)
- {
- Dictionary<string, string> dictionary = new Dictionary<string, string>();
- CreateBGObjectSubWindow.BgObject bgObject = this.create_obj_list_[i];
- Transform transform = bgObject.game_object.transform;
- dictionary["id"] = bgObject.data.id.ToString();
- dictionary["position"] = transform.position.ToString("G9");
- dictionary["rotation"] = transform.rotation.ToString("G9");
- dictionary["scale"] = transform.localScale.ToString("G9");
- dictionary["visible"] = transform.gameObject.activeSelf.ToString();
- storeData.Add(bgObject.create_time, dictionary);
- }
- }
- public void OnDeserializeEvent(ref Dictionary<string, Dictionary<string, string>> storeData)
- {
- this.OnDestroy();
- List<string> list = new List<string>();
- foreach (KeyValuePair<string, Dictionary<string, string>> keyValuePair in storeData)
- {
- Dictionary<string, string> value = keyValuePair.Value;
- long id = long.Parse(value["id"]);
- string key = keyValuePair.Key;
- CreateBGObjectSubWindow.BgObject bgObject = this.AddObject(PhotoBGObjectData.Get(id), key);
- if (bgObject != null && bgObject.game_object != null)
- {
- Transform transform = bgObject.game_object.transform;
- transform.position = Parse.Vector3(value["position"]);
- transform.rotation = Parse.Quaternion(value["rotation"]);
- transform.localScale = Parse.Vector3(value["scale"]);
- bgObject.game_object.SetActive(bool.Parse(value["visible"]));
- }
- else
- {
- list.Add(keyValuePair.Key);
- }
- }
- for (int i = 0; i < list.Count; i++)
- {
- storeData.Remove(list[i]);
- }
- Utility.ResetNGUI(this.addButtonList.ScrollView);
- }
- public new PhotoWindowManager mgr
- {
- get
- {
- return base.mgr as PhotoWindowManager;
- }
- }
- public PopupAndButtonList addButtonList;
- private List<CreateBGObjectSubWindow.BgObject> create_obj_list_ = new List<CreateBGObjectSubWindow.BgObject>();
- private class BgObject : IComparable<CreateBGObjectSubWindow.BgObject>
- {
- public BgObject()
- {
- this.create_time = DateTime.Now.ToString("yyyyMMddHHmmssfff");
- }
- public int CompareTo(CreateBGObjectSubWindow.BgObject obj)
- {
- if (obj == null)
- {
- return 1;
- }
- return long.Parse(this.create_time).CompareTo(long.Parse(obj.create_time));
- }
- public string create_time;
- public GameObject game_object;
- public PhotoBGObjectData data;
- }
- }
|