ObjectCreateWindow.cs 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501
  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. EventDelegate.Add(this.sphereBackDrawPopupList.onChange, delegate()
  106. {
  107. if (this.selectData != null && this.selectData.customObject.type == BasePhotoCustomObject.Type.Sphere)
  108. {
  109. PhotoCustomObjectSphere.RenderingType renderingType = PhotoCustomObjectSphere.RenderingType.TwoSides;
  110. if (UIPopupList.current.value.IndexOf("表面表示") == 0)
  111. {
  112. renderingType = PhotoCustomObjectSphere.RenderingType.Front;
  113. }
  114. else if (UIPopupList.current.value.IndexOf("裏面表示") == 0)
  115. {
  116. renderingType = PhotoCustomObjectSphere.RenderingType.Back;
  117. }
  118. (this.selectData.customObject as PhotoCustomObjectSphere).renderingType = renderingType;
  119. }
  120. });
  121. this.camera_move_support_ = base.gameObject.AddComponent<WfCameraMoveSupport>();
  122. this.scroll_view_ = NGUITools.FindInParents<UIScrollView>(this.objectListGrid.transform);
  123. EventDelegate.Add(this.saveButton.onClick, new EventDelegate.Callback(this.OnClickSave));
  124. EventDelegate.Add(this.textureRestoreButton.onClick, new EventDelegate.Callback(this.OnClickTextureRestore));
  125. this.CheckPrevVisible.check = false;
  126. this.CheckPrevVisible.onClick.Add(delegate(WFCheckBox check_box)
  127. {
  128. if (this.selectData != null)
  129. {
  130. this.selectData.customObject.visible = check_box.check;
  131. }
  132. });
  133. this.textureSelectSubtWindow.GetButtonOnClickEventList(BasePhotoSubWindow.BtnType.End).Add(delegate
  134. {
  135. this.visibleTextureSelectWindow = false;
  136. });
  137. this.textureSelectSubtWindow.SetButtonEnabled(BasePhotoSubWindow.BtnType.End, true, false);
  138. GameObject gameObject = GameObject.Find("CustomObjectPrev");
  139. if (gameObject == null)
  140. {
  141. gameObject = new GameObject("CustomObjectPrev");
  142. }
  143. gameObject.transform.localPosition = new Vector3(0f, 1.5f, -0.8f);
  144. GameObject gameObject2 = Utility.CreatePrefab(gameObject, "ScenePhotoMode/CustomObject/Plane", false);
  145. BasePhotoCustomObject component = gameObject2.GetComponent<BasePhotoCustomObject>();
  146. this.target_list_.Add(new ObjectCreateWindow.Data(component));
  147. this.CreateTabButton(this.objectListGrid.gameObject, component, "新規オブジェクト");
  148. Action<string, List<string>> action = delegate(string path, List<string> result_list)
  149. {
  150. string[] files = Directory.GetFiles(path);
  151. for (int i = 0; i < files.Length; i++)
  152. {
  153. if (Path.GetExtension(files[i]) == ".poj")
  154. {
  155. result_list.Add(files[i]);
  156. }
  157. }
  158. };
  159. List<string> list = new List<string>();
  160. action(ObjectCreateWindow.folder_path, list);
  161. foreach (string text in list)
  162. {
  163. BasePhotoCustomObject basePhotoCustomObject = this.CreateLoadCustomObject(gameObject, text);
  164. if (!(basePhotoCustomObject == null))
  165. {
  166. this.target_list_.Add(new ObjectCreateWindow.Data(basePhotoCustomObject, text));
  167. this.CreateTabButton(this.objectListGrid.gameObject, basePhotoCustomObject, text);
  168. }
  169. }
  170. foreach (ObjectCreateWindow.Data data in this.target_list_)
  171. {
  172. data.customObject.visible = false;
  173. }
  174. UIWFTabPanel component2 = this.objectListGrid.GetComponent<UIWFTabPanel>();
  175. component2.UpdateChildren();
  176. component2.Select(this.objectListGrid.GetChild(0).gameObject.GetComponent<UIWFTabButton>());
  177. Utility.ResetNGUI(this.objectListGrid);
  178. Utility.ResetNGUI(this.scroll_view_);
  179. this.UpdateChildren();
  180. }
  181. public override void Start()
  182. {
  183. base.Start();
  184. this.visibleTextureSelectWindow = false;
  185. }
  186. private void OnDestroy()
  187. {
  188. }
  189. public void OnClickSelectTextureButton()
  190. {
  191. this.visibleTextureSelectWindow = !this.visibleTextureSelectWindow;
  192. }
  193. public void OnChangeSelectTexture(string pngPath)
  194. {
  195. this.textureExpTextObject.SetActive(false);
  196. if (!string.IsNullOrEmpty(this.selectData.fullPath) && this.selectData.backupPng == null)
  197. {
  198. byte[] imageBinarys = this.selectData.customObject.imageBinarys;
  199. this.selectData.backupPng = new byte[imageBinarys.Length];
  200. Array.Copy(imageBinarys, this.selectData.backupPng, imageBinarys.Length);
  201. this.textureRestoreButton.isEnabled = true;
  202. }
  203. this.selectData.customObject.SetTexture(pngPath);
  204. UI2DSprite componentInChildren = this.selectTextureButton.GetComponentInChildren<UI2DSprite>(true);
  205. 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));
  206. componentInChildren.sprite2D = sprite2D;
  207. }
  208. private void UpdateObjectEditUI(ObjectCreateWindow.Data targetData)
  209. {
  210. if (targetData == null)
  211. {
  212. return;
  213. }
  214. if (this.typeSelectPopupList != null)
  215. {
  216. this.typeSelectPopupList.value = ((targetData.customObject.type != BasePhotoCustomObject.Type.Plane) ? "スフィア" : "プレーン");
  217. this.typeSelectPopupList.GetComponent<UIButton>().isEnabled = (targetData == this.target_list_[0]);
  218. }
  219. if (!string.IsNullOrEmpty(targetData.fullPath))
  220. {
  221. this.saveButton.GetComponentInChildren<UILabel>().text = "更新";
  222. this.textureExpTextObject.SetActive(false);
  223. }
  224. else
  225. {
  226. this.saveButton.GetComponentInChildren<UILabel>().text = "保存";
  227. if (targetData.customObject.mainTexture != null)
  228. {
  229. this.textureExpTextObject.SetActive(false);
  230. }
  231. else
  232. {
  233. this.textureExpTextObject.SetActive(true);
  234. }
  235. }
  236. this.textureRestoreButton.gameObject.SetActive(!string.IsNullOrEmpty(targetData.fullPath));
  237. this.textureRestoreButton.isEnabled = (targetData.backupPng != null);
  238. foreach (ObjectCreateWindow.Data data in this.target_list_)
  239. {
  240. data.customObject.visible = (data == targetData && this.CheckPrevVisible.check);
  241. }
  242. BasePhotoCustomObject customObject = targetData.customObject;
  243. UI2DSprite componentInChildren = this.selectTextureButton.GetComponentInChildren<UI2DSprite>(true);
  244. if (customObject.mainTexture != null)
  245. {
  246. Sprite sprite2D = Sprite.Create(customObject.mainTexture, new Rect(0f, 0f, (float)customObject.mainTexture.width, (float)customObject.mainTexture.height), default(Vector2));
  247. componentInChildren.sprite2D = sprite2D;
  248. }
  249. else
  250. {
  251. componentInChildren.sprite2D = null;
  252. }
  253. this.editScaleSlider.value = customObject.scale;
  254. this.texColorPalette.ColorPalette.SetColor(customObject.textureColor);
  255. this.texColorPalette.ColorPalette.UIUpdate();
  256. this.planeUIParent.SetActive(false);
  257. this.sphereUIParent.SetActive(false);
  258. if (this.selectData.customObject.type == BasePhotoCustomObject.Type.Plane)
  259. {
  260. this.planeUIParent.SetActive(true);
  261. PhotoCustomObjectPlane.BackRenderingType backRenderingType = (this.selectData.customObject as PhotoCustomObjectPlane).backRenderingType;
  262. this.planeBackDrawPopupList.value = ((backRenderingType != PhotoCustomObjectPlane.BackRenderingType.Flip) ? ((backRenderingType != PhotoCustomObjectPlane.BackRenderingType.None) ? "鏡合わせ" : "透明") : "反転");
  263. }
  264. else if (this.selectData.customObject.type == BasePhotoCustomObject.Type.Sphere)
  265. {
  266. this.sphereUIParent.SetActive(true);
  267. PhotoCustomObjectSphere.RenderingType renderingType = (this.selectData.customObject as PhotoCustomObjectSphere).renderingType;
  268. this.sphereBackDrawPopupList.value = ((renderingType != PhotoCustomObjectSphere.RenderingType.TwoSides) ? ((renderingType != PhotoCustomObjectSphere.RenderingType.Front) ? "裏面表示" : "表面表示") : "両面表示");
  269. }
  270. }
  271. public void OnSelectItem(BasePhotoCustomObject select)
  272. {
  273. foreach (ObjectCreateWindow.Data data in this.target_list_)
  274. {
  275. if (data.customObject == select)
  276. {
  277. this.selectData = data;
  278. this.UpdateObjectEditUI(this.selectData);
  279. break;
  280. }
  281. }
  282. }
  283. public void OnClickTextureRestore()
  284. {
  285. if (this.selectData == null || this.selectData.backupPng == null)
  286. {
  287. return;
  288. }
  289. this.selectData.customObject.SetTexture(this.selectData.backupPng);
  290. UI2DSprite componentInChildren = this.selectTextureButton.GetComponentInChildren<UI2DSprite>(true);
  291. 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));
  292. componentInChildren.sprite2D = sprite2D;
  293. this.textureRestoreButton.isEnabled = false;
  294. this.selectData.backupPng = null;
  295. }
  296. public void OnClickSave()
  297. {
  298. if (this.selectData == null)
  299. {
  300. return;
  301. }
  302. if (this.selectData.customObject.mainTexture == null)
  303. {
  304. GameMain.Instance.SysDlg.Show("テクスチャが未設定です", SystemDialog.TYPE.OK, null, null);
  305. return;
  306. }
  307. if (string.IsNullOrEmpty(this.selectData.fullPath))
  308. {
  309. this.savePanel.Open(this.selectData.customObject, delegate(string filePath)
  310. {
  311. GameObject parent = GameObject.Find("CustomObjectPrev");
  312. BasePhotoCustomObject basePhotoCustomObject = this.CreateLoadCustomObject(parent, filePath);
  313. if (basePhotoCustomObject == null)
  314. {
  315. return;
  316. }
  317. this.target_list_.Add(new ObjectCreateWindow.Data(basePhotoCustomObject, filePath));
  318. this.CreateTabButton(this.objectListGrid.gameObject, basePhotoCustomObject, filePath);
  319. this.objectListGrid.GetComponent<UIWFTabPanel>().UpdateChildren();
  320. Utility.ResetNGUI(this.objectListGrid);
  321. Utility.ResetNGUI(this.scroll_view_);
  322. this.UpdateChildren();
  323. ObjectManagerWindow objectManagerWindow2 = base.mgr.GetWindow(PhotoWindowManager.WindowType.ObjectManager) as ObjectManagerWindow;
  324. objectManagerWindow2.createBgObjectWindow.AddMyObject(filePath);
  325. });
  326. }
  327. else
  328. {
  329. if (File.Exists(this.selectData.fullPath))
  330. {
  331. File.Delete(this.selectData.fullPath);
  332. }
  333. try
  334. {
  335. File.WriteAllBytes(this.selectData.fullPath, this.selectData.customObject.Serialize());
  336. ObjectManagerWindow objectManagerWindow = base.mgr.GetWindow(PhotoWindowManager.WindowType.ObjectManager) as ObjectManagerWindow;
  337. objectManagerWindow.createBgObjectWindow.UpdateMyObject(this.selectData.fullPath);
  338. }
  339. catch
  340. {
  341. GameMain.Instance.SysDlg.Show("オブジェクトの保存に失敗しました", SystemDialog.TYPE.OK, null, null);
  342. }
  343. }
  344. }
  345. public override void OnMaidAddEvent(Maid maid, bool is_deserialize_load)
  346. {
  347. }
  348. public override void OnMaidRemoveEventPrev(Maid maid)
  349. {
  350. }
  351. public void OnClickCameraFocus()
  352. {
  353. if (this.select_trans_target_ == null || this.select_trans_target_.obj == null)
  354. {
  355. return;
  356. }
  357. Vector3 position = this.select_trans_target_.obj.transform.position;
  358. float distance = 4f;
  359. Vector2 aroundAngle = new Vector2(-180f, 4.7f);
  360. this.camera_move_support_.StartCameraPosition(position, distance, aroundAngle);
  361. }
  362. private BasePhotoCustomObject CreateLoadCustomObject(GameObject parent, string filePath)
  363. {
  364. BasePhotoCustomObject basePhotoCustomObject = BasePhotoCustomObject.InstantiateFromFile(parent, filePath);
  365. if (basePhotoCustomObject == null)
  366. {
  367. return null;
  368. }
  369. string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(Path.GetFileName(filePath));
  370. basePhotoCustomObject.gameObject.name = fileNameWithoutExtension.GetHashCode().ToString();
  371. basePhotoCustomObject.visible = false;
  372. return basePhotoCustomObject;
  373. }
  374. private UIWFTabButton CreateTabButton(GameObject parent_obj, BasePhotoCustomObject target, string filePath)
  375. {
  376. GameObject gameObject = Utility.CreatePrefab(parent_obj, "ScenePhotoMode/WindowListItem", true);
  377. gameObject.name = Path.GetFileNameWithoutExtension(Path.GetFileName(filePath));
  378. gameObject.GetComponentInChildren<UILabel>().text = gameObject.name;
  379. UIWFTabButton component = gameObject.GetComponent<UIWFTabButton>();
  380. this.buttonDic.Add(component.GetHashCode(), target);
  381. EventDelegate.Add(component.onSelect, delegate()
  382. {
  383. if (!UIWFSelectButton.current.isSelected)
  384. {
  385. return;
  386. }
  387. if (this.buttonDic.ContainsKey(UIWFSelectButton.current.GetHashCode()))
  388. {
  389. this.OnSelectItem(this.buttonDic[UIWFSelectButton.current.GetHashCode()]);
  390. }
  391. });
  392. return component;
  393. }
  394. public override void OnSerializeEvent()
  395. {
  396. }
  397. public override void OnDeserializeEvent()
  398. {
  399. }
  400. public override KeyValuePair<string, Dictionary<string, string>> Serialize()
  401. {
  402. KeyValuePair<string, Dictionary<string, string>> result = base.Serialize();
  403. Dictionary<string, string> value = result.Value;
  404. result = new KeyValuePair<string, Dictionary<string, string>>(result.Key, value);
  405. return result;
  406. }
  407. public override void Deserialize(Dictionary<string, Dictionary<string, string>> data)
  408. {
  409. base.Deserialize(data);
  410. string key = base.gameObject.name + "title";
  411. if (!data.ContainsKey(key))
  412. {
  413. return;
  414. }
  415. this.visibleTextureSelectWindow = false;
  416. }
  417. public PhotoModeObjectSave savePanel;
  418. public UIButton selectTextureButton;
  419. public GameObject textureExpTextObject;
  420. public UIButton textureRestoreButton;
  421. public TextureSelectSubWindow textureSelectSubtWindow;
  422. public UIGrid objectListGrid;
  423. public UIPopupList typeSelectPopupList;
  424. public WFCheckBox CheckPrevVisible;
  425. public UIButton saveButton;
  426. public PhotoSliderAndInput editScaleSlider;
  427. public WindowPartsInputColorrPalette texColorPalette;
  428. public GameObject planeUIParent;
  429. public UIPopupList planeBackDrawPopupList;
  430. public GameObject sphereUIParent;
  431. public UIPopupList sphereBackDrawPopupList;
  432. private Dictionary<int, BasePhotoCustomObject> buttonDic = new Dictionary<int, BasePhotoCustomObject>();
  433. private List<ObjectCreateWindow.Data> target_list_ = new List<ObjectCreateWindow.Data>();
  434. private ObjectCreateWindow.Data selectData;
  435. private bool change_bg_;
  436. private PhotoTransTargetObject select_trans_target_;
  437. private WfCameraMoveSupport camera_move_support_;
  438. private UIScrollView scroll_view_;
  439. private class Data
  440. {
  441. public Data(BasePhotoCustomObject obj)
  442. {
  443. this.customObject = obj;
  444. }
  445. public Data(BasePhotoCustomObject obj, string fullPath)
  446. {
  447. this.customObject = obj;
  448. this.fullPath = fullPath;
  449. }
  450. public BasePhotoCustomObject customObject;
  451. public byte[] backupPng;
  452. public string fullPath;
  453. }
  454. }