ObjectCreateWindow.cs 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using UnityEngine;
  5. using wf;
  6. public class ObjectCreateWindow : BaseMaidPhotoWindow
  7. {
  8. public static string folder_path
  9. {
  10. get
  11. {
  12. string text = PhotoWindowManager.path_photo_folder + "MyObject";
  13. if (!Directory.Exists(text))
  14. {
  15. Directory.CreateDirectory(text);
  16. }
  17. return text;
  18. }
  19. }
  20. public bool visibleTextureSelectWindow
  21. {
  22. get
  23. {
  24. return this.textureSelectSubtWindow.visible;
  25. }
  26. set
  27. {
  28. this.textureSelectSubtWindow.visible = value;
  29. }
  30. }
  31. public override void Awake()
  32. {
  33. base.Awake();
  34. EventDelegate.Add(this.selectTextureButton.onClick, new EventDelegate.Callback(this.OnClickSelectTextureButton));
  35. if (this.typeSelectPopupList != null)
  36. {
  37. EventDelegate.Add(this.typeSelectPopupList.onChange, delegate
  38. {
  39. if (this.selectData == this.target_list_[0])
  40. {
  41. GameObject parent = GameObject.Find("CustomObjectPrev");
  42. GameObject gameObject3 = null;
  43. if (UIPopupList.current.value.IndexOf("プレーン") != -1 && this.selectData.customObject.type != BasePhotoCustomObject.Type.Plane)
  44. {
  45. gameObject3 = Utility.CreatePrefab(parent, "ScenePhotoMode/CustomObject/Plane", false);
  46. }
  47. else if (UIPopupList.current.value.IndexOf("スフィア") != -1 && this.selectData.customObject.type != BasePhotoCustomObject.Type.Sphere)
  48. {
  49. gameObject3 = Utility.CreatePrefab(parent, "ScenePhotoMode/CustomObject/Sphere", false);
  50. }
  51. if (gameObject3 != null)
  52. {
  53. int key = -1;
  54. foreach (KeyValuePair<int, BasePhotoCustomObject> keyValuePair in this.buttonDic)
  55. {
  56. if (keyValuePair.Value == this.selectData.customObject)
  57. {
  58. key = keyValuePair.Key;
  59. break;
  60. }
  61. }
  62. BasePhotoCustomObject component3 = gameObject3.GetComponent<BasePhotoCustomObject>();
  63. ObjectCreateWindow.Data value = new ObjectCreateWindow.Data(component3);
  64. this.target_list_[0] = value;
  65. this.buttonDic[key] = component3;
  66. UnityEngine.Object.DestroyImmediate(this.selectData.customObject.gameObject);
  67. this.selectData = null;
  68. this.selectData = value;
  69. this.UpdateObjectEditUI(this.selectData);
  70. }
  71. }
  72. });
  73. }
  74. this.editScaleSlider.ResetValue();
  75. this.editScaleSlider.onChangeValue.Add(delegate(float val)
  76. {
  77. if (this.selectData != null)
  78. {
  79. this.selectData.customObject.scale = val;
  80. }
  81. });
  82. this.texColorPalette.onChangeValue.Add(delegate(WindowPartsInputColorrPalette colorInputs, Color setColor)
  83. {
  84. if (this.selectData != null)
  85. {
  86. this.selectData.customObject.textureColor = setColor;
  87. }
  88. });
  89. EventDelegate.Add(this.planeBackDrawPopupList.onChange, delegate
  90. {
  91. if (this.selectData != null && this.selectData.customObject.type == BasePhotoCustomObject.Type.Plane)
  92. {
  93. PhotoCustomObjectPlane.BackRenderingType backRenderingType = PhotoCustomObjectPlane.BackRenderingType.Mirror;
  94. if (UIPopupList.current.value.IndexOf("反転") == 0)
  95. {
  96. backRenderingType = PhotoCustomObjectPlane.BackRenderingType.Flip;
  97. }
  98. else if (UIPopupList.current.value.IndexOf("透明") == 0)
  99. {
  100. backRenderingType = PhotoCustomObjectPlane.BackRenderingType.None;
  101. }
  102. (this.selectData.customObject as PhotoCustomObjectPlane).backRenderingType = backRenderingType;
  103. }
  104. });
  105. this.camera_move_support_ = base.gameObject.AddComponent<WfCameraMoveSupport>();
  106. this.scroll_view_ = NGUITools.FindInParents<UIScrollView>(this.objectListGrid.transform);
  107. EventDelegate.Add(this.saveButton.onClick, new EventDelegate.Callback(this.OnClickSave));
  108. EventDelegate.Add(this.textureRestoreButton.onClick, new EventDelegate.Callback(this.OnClickTextureRestore));
  109. this.CheckPrevVisible.check = false;
  110. this.CheckPrevVisible.onClick.Add(delegate(WFCheckBox check_box)
  111. {
  112. if (this.selectData != null)
  113. {
  114. this.selectData.customObject.visible = check_box.check;
  115. }
  116. });
  117. this.textureSelectSubtWindow.GetButtonOnClickEventList(BasePhotoSubWindow.BtnType.End).Add(delegate
  118. {
  119. this.visibleTextureSelectWindow = false;
  120. });
  121. this.textureSelectSubtWindow.SetButtonEnabled(BasePhotoSubWindow.BtnType.End, true, false);
  122. GameObject gameObject = GameObject.Find("CustomObjectPrev");
  123. if (gameObject == null)
  124. {
  125. gameObject = new GameObject("CustomObjectPrev");
  126. }
  127. gameObject.transform.localPosition = new Vector3(0f, 1.5f, -0.8f);
  128. GameObject gameObject2 = Utility.CreatePrefab(gameObject, "ScenePhotoMode/CustomObject/Plane", false);
  129. BasePhotoCustomObject component = gameObject2.GetComponent<BasePhotoCustomObject>();
  130. this.target_list_.Add(new ObjectCreateWindow.Data(component));
  131. this.CreateTabButton(this.objectListGrid.gameObject, component, "新規オブジェクト");
  132. Action<string, List<string>> action = delegate(string path, List<string> result_list)
  133. {
  134. string[] files = Directory.GetFiles(path);
  135. for (int i = 0; i < files.Length; i++)
  136. {
  137. if (Path.GetExtension(files[i]) == ".poj")
  138. {
  139. result_list.Add(files[i]);
  140. }
  141. }
  142. };
  143. List<string> list = new List<string>();
  144. action(ObjectCreateWindow.folder_path, list);
  145. foreach (string text in list)
  146. {
  147. BasePhotoCustomObject basePhotoCustomObject = this.CreateLoadCustomObject(gameObject, text);
  148. if (!(basePhotoCustomObject == null))
  149. {
  150. this.target_list_.Add(new ObjectCreateWindow.Data(basePhotoCustomObject, text));
  151. this.CreateTabButton(this.objectListGrid.gameObject, basePhotoCustomObject, text);
  152. }
  153. }
  154. foreach (ObjectCreateWindow.Data data in this.target_list_)
  155. {
  156. data.customObject.visible = false;
  157. }
  158. UIWFTabPanel component2 = this.objectListGrid.GetComponent<UIWFTabPanel>();
  159. component2.UpdateChildren();
  160. component2.Select(this.objectListGrid.GetChild(0).gameObject.GetComponent<UIWFTabButton>());
  161. Utility.ResetNGUI(this.objectListGrid);
  162. Utility.ResetNGUI(this.scroll_view_);
  163. this.UpdateChildren();
  164. }
  165. public override void Start()
  166. {
  167. base.Start();
  168. this.visibleTextureSelectWindow = false;
  169. }
  170. private void OnDestroy()
  171. {
  172. }
  173. public void OnClickSelectTextureButton()
  174. {
  175. this.visibleTextureSelectWindow = !this.visibleTextureSelectWindow;
  176. }
  177. public void OnChangeSelectTexture(string pngPath)
  178. {
  179. this.textureExpTextObject.SetActive(false);
  180. if (!string.IsNullOrEmpty(this.selectData.fullPath) && this.selectData.backupPng == null)
  181. {
  182. byte[] imageBinarys = this.selectData.customObject.imageBinarys;
  183. this.selectData.backupPng = new byte[imageBinarys.Length];
  184. Array.Copy(imageBinarys, this.selectData.backupPng, imageBinarys.Length);
  185. this.textureRestoreButton.isEnabled = true;
  186. }
  187. this.selectData.customObject.SetTexture(pngPath);
  188. UI2DSprite componentInChildren = this.selectTextureButton.GetComponentInChildren<UI2DSprite>(true);
  189. Sprite sprite2D = Sprite.Create(this.selectData.customObject.mainTexture, new Rect(0f, 0f, (float)this.selectData.customObject.mainTexture.width, (float)this.selectData.customObject.mainTexture.height), default(Vector2));
  190. componentInChildren.sprite2D = sprite2D;
  191. }
  192. private void UpdateObjectEditUI(ObjectCreateWindow.Data targetData)
  193. {
  194. if (targetData == null)
  195. {
  196. return;
  197. }
  198. if (this.typeSelectPopupList != null)
  199. {
  200. this.typeSelectPopupList.value = ((targetData.customObject.type != BasePhotoCustomObject.Type.Plane) ? "スフィア" : "プレーン");
  201. this.typeSelectPopupList.GetComponent<UIButton>().isEnabled = (targetData == this.target_list_[0]);
  202. }
  203. if (!string.IsNullOrEmpty(targetData.fullPath))
  204. {
  205. this.saveButton.GetComponentInChildren<UILabel>().text = "更新";
  206. this.textureExpTextObject.SetActive(false);
  207. }
  208. else
  209. {
  210. this.saveButton.GetComponentInChildren<UILabel>().text = "保存";
  211. if (targetData.customObject.mainTexture != null)
  212. {
  213. this.textureExpTextObject.SetActive(false);
  214. }
  215. else
  216. {
  217. this.textureExpTextObject.SetActive(true);
  218. }
  219. }
  220. this.textureRestoreButton.gameObject.SetActive(!string.IsNullOrEmpty(targetData.fullPath));
  221. this.textureRestoreButton.isEnabled = (targetData.backupPng != null);
  222. foreach (ObjectCreateWindow.Data data in this.target_list_)
  223. {
  224. data.customObject.visible = (data == targetData && this.CheckPrevVisible.check);
  225. }
  226. BasePhotoCustomObject customObject = targetData.customObject;
  227. UI2DSprite componentInChildren = this.selectTextureButton.GetComponentInChildren<UI2DSprite>(true);
  228. if (customObject.mainTexture != null)
  229. {
  230. Sprite sprite2D = Sprite.Create(customObject.mainTexture, new Rect(0f, 0f, (float)customObject.mainTexture.width, (float)customObject.mainTexture.height), default(Vector2));
  231. componentInChildren.sprite2D = sprite2D;
  232. }
  233. else
  234. {
  235. componentInChildren.sprite2D = null;
  236. }
  237. this.editScaleSlider.value = customObject.scale;
  238. this.texColorPalette.ColorPalette.SetColor(customObject.textureColor);
  239. this.texColorPalette.ColorPalette.UIUpdate();
  240. if (this.selectData.customObject.type == BasePhotoCustomObject.Type.Plane)
  241. {
  242. this.planeUIParent.SetActive(true);
  243. PhotoCustomObjectPlane.BackRenderingType backRenderingType = (this.selectData.customObject as PhotoCustomObjectPlane).backRenderingType;
  244. this.planeBackDrawPopupList.value = ((backRenderingType != PhotoCustomObjectPlane.BackRenderingType.Flip) ? ((backRenderingType != PhotoCustomObjectPlane.BackRenderingType.None) ? "鏡合わせ" : "透明") : "反転");
  245. }
  246. else
  247. {
  248. this.planeUIParent.SetActive(false);
  249. }
  250. }
  251. public void OnSelectItem(BasePhotoCustomObject select)
  252. {
  253. foreach (ObjectCreateWindow.Data data in this.target_list_)
  254. {
  255. if (data.customObject == select)
  256. {
  257. this.selectData = data;
  258. this.UpdateObjectEditUI(this.selectData);
  259. break;
  260. }
  261. }
  262. }
  263. public void OnClickTextureRestore()
  264. {
  265. if (this.selectData == null || this.selectData.backupPng == null)
  266. {
  267. return;
  268. }
  269. this.selectData.customObject.SetTexture(this.selectData.backupPng);
  270. UI2DSprite componentInChildren = this.selectTextureButton.GetComponentInChildren<UI2DSprite>(true);
  271. Sprite sprite2D = Sprite.Create(this.selectData.customObject.mainTexture, new Rect(0f, 0f, (float)this.selectData.customObject.mainTexture.width, (float)this.selectData.customObject.mainTexture.height), default(Vector2));
  272. componentInChildren.sprite2D = sprite2D;
  273. this.textureRestoreButton.isEnabled = false;
  274. this.selectData.backupPng = null;
  275. }
  276. public void OnClickSave()
  277. {
  278. if (this.selectData == null)
  279. {
  280. return;
  281. }
  282. if (this.selectData.customObject.mainTexture == null)
  283. {
  284. GameMain.Instance.SysDlg.Show("テクスチャが未設定です", SystemDialog.TYPE.OK, null, null);
  285. return;
  286. }
  287. if (string.IsNullOrEmpty(this.selectData.fullPath))
  288. {
  289. this.savePanel.Open(this.selectData.customObject, delegate(string filePath)
  290. {
  291. GameObject parent = GameObject.Find("CustomObjectPrev");
  292. BasePhotoCustomObject basePhotoCustomObject = this.CreateLoadCustomObject(parent, filePath);
  293. if (basePhotoCustomObject == null)
  294. {
  295. return;
  296. }
  297. this.target_list_.Add(new ObjectCreateWindow.Data(basePhotoCustomObject, filePath));
  298. this.CreateTabButton(this.objectListGrid.gameObject, basePhotoCustomObject, filePath);
  299. this.objectListGrid.GetComponent<UIWFTabPanel>().UpdateChildren();
  300. Utility.ResetNGUI(this.objectListGrid);
  301. Utility.ResetNGUI(this.scroll_view_);
  302. this.UpdateChildren();
  303. ObjectManagerWindow objectManagerWindow2 = base.mgr.GetWindow(PhotoWindowManager.WindowType.ObjectManager) as ObjectManagerWindow;
  304. objectManagerWindow2.createBgObjectWindow.AddMyObject(filePath);
  305. });
  306. }
  307. else
  308. {
  309. if (File.Exists(this.selectData.fullPath))
  310. {
  311. File.Delete(this.selectData.fullPath);
  312. }
  313. try
  314. {
  315. File.WriteAllBytes(this.selectData.fullPath, this.selectData.customObject.Serialize());
  316. ObjectManagerWindow objectManagerWindow = base.mgr.GetWindow(PhotoWindowManager.WindowType.ObjectManager) as ObjectManagerWindow;
  317. objectManagerWindow.createBgObjectWindow.UpdateMyObject(this.selectData.fullPath);
  318. }
  319. catch
  320. {
  321. GameMain.Instance.SysDlg.Show("オブジェクトの保存に失敗しました", SystemDialog.TYPE.OK, null, null);
  322. }
  323. }
  324. }
  325. public override void OnMaidAddEvent(Maid maid, bool is_deserialize_load)
  326. {
  327. }
  328. public override void OnMaidRemoveEventPrev(Maid maid)
  329. {
  330. }
  331. public void OnClickCameraFocus()
  332. {
  333. if (this.select_trans_target_ == null || this.select_trans_target_.obj == null)
  334. {
  335. return;
  336. }
  337. Vector3 position = this.select_trans_target_.obj.transform.position;
  338. float distance = 4f;
  339. Vector2 aroundAngle = new Vector2(-180f, 4.7f);
  340. this.camera_move_support_.StartCameraPosition(position, distance, aroundAngle);
  341. }
  342. private BasePhotoCustomObject CreateLoadCustomObject(GameObject parent, string filePath)
  343. {
  344. BasePhotoCustomObject basePhotoCustomObject = BasePhotoCustomObject.InstantiateFromFile(parent, filePath);
  345. if (basePhotoCustomObject == null)
  346. {
  347. return null;
  348. }
  349. string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(Path.GetFileName(filePath));
  350. basePhotoCustomObject.gameObject.name = fileNameWithoutExtension.GetHashCode().ToString();
  351. basePhotoCustomObject.visible = false;
  352. return basePhotoCustomObject;
  353. }
  354. private UIWFTabButton CreateTabButton(GameObject parent_obj, BasePhotoCustomObject target, string filePath)
  355. {
  356. GameObject gameObject = Utility.CreatePrefab(parent_obj, "ScenePhotoMode/WindowListItem", true);
  357. gameObject.name = Path.GetFileNameWithoutExtension(Path.GetFileName(filePath));
  358. gameObject.GetComponentInChildren<UILabel>().text = gameObject.name;
  359. UIWFTabButton component = gameObject.GetComponent<UIWFTabButton>();
  360. this.buttonDic.Add(component.GetHashCode(), target);
  361. EventDelegate.Add(component.onSelect, delegate
  362. {
  363. if (!UIWFSelectButton.current.isSelected)
  364. {
  365. return;
  366. }
  367. if (this.buttonDic.ContainsKey(UIWFSelectButton.current.GetHashCode()))
  368. {
  369. this.OnSelectItem(this.buttonDic[UIWFSelectButton.current.GetHashCode()]);
  370. }
  371. });
  372. return component;
  373. }
  374. public override void OnSerializeEvent()
  375. {
  376. }
  377. public override void OnDeserializeEvent()
  378. {
  379. }
  380. public override KeyValuePair<string, Dictionary<string, string>> Serialize()
  381. {
  382. KeyValuePair<string, Dictionary<string, string>> result = base.Serialize();
  383. Dictionary<string, string> value = result.Value;
  384. result = new KeyValuePair<string, Dictionary<string, string>>(result.Key, value);
  385. return result;
  386. }
  387. public override void Deserialize(Dictionary<string, Dictionary<string, string>> data)
  388. {
  389. base.Deserialize(data);
  390. string key = base.gameObject.name + "title";
  391. if (!data.ContainsKey(key))
  392. {
  393. return;
  394. }
  395. this.visibleTextureSelectWindow = false;
  396. }
  397. public PhotoModeObjectSave savePanel;
  398. public UIButton selectTextureButton;
  399. public GameObject textureExpTextObject;
  400. public UIButton textureRestoreButton;
  401. public TextureSelectSubWindow textureSelectSubtWindow;
  402. public UIGrid objectListGrid;
  403. public UIPopupList typeSelectPopupList;
  404. public WFCheckBox CheckPrevVisible;
  405. public UIButton saveButton;
  406. public PhotoSliderAndInput editScaleSlider;
  407. public WindowPartsInputColorrPalette texColorPalette;
  408. public GameObject planeUIParent;
  409. public UIPopupList planeBackDrawPopupList;
  410. private Dictionary<int, BasePhotoCustomObject> buttonDic = new Dictionary<int, BasePhotoCustomObject>();
  411. private List<ObjectCreateWindow.Data> target_list_ = new List<ObjectCreateWindow.Data>();
  412. private ObjectCreateWindow.Data selectData;
  413. private bool change_bg_;
  414. private PhotoTransTargetObject select_trans_target_;
  415. private WfCameraMoveSupport camera_move_support_;
  416. private UIScrollView scroll_view_;
  417. private class Data
  418. {
  419. public Data(BasePhotoCustomObject obj)
  420. {
  421. this.customObject = obj;
  422. }
  423. public Data(BasePhotoCustomObject obj, string fullPath)
  424. {
  425. this.customObject = obj;
  426. this.fullPath = fullPath;
  427. }
  428. public BasePhotoCustomObject customObject;
  429. public byte[] backupPng;
  430. public string fullPath;
  431. }
  432. }