PhotoModePoseSave.cs 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  1. using System;
  2. using System.IO;
  3. using System.Xml.Linq;
  4. using UnityEngine;
  5. public class PhotoModePoseSave : MonoBehaviour
  6. {
  7. public static string folder_path
  8. {
  9. get
  10. {
  11. string text = PhotoWindowManager.path_photo_folder + "MyPose";
  12. if (!Directory.Exists(text))
  13. {
  14. Directory.CreateDirectory(text);
  15. }
  16. return text;
  17. }
  18. }
  19. public void Awake()
  20. {
  21. EventDelegate.Add(UTY.GetChildObject(base.gameObject, "Base/Ok", false).GetComponent<UIButton>().onClick, new EventDelegate.Callback(this.OnBtnOk));
  22. EventDelegate.Add(UTY.GetChildObject(base.gameObject, "Base/Cancel", false).GetComponent<UIButton>().onClick, new EventDelegate.Callback(this.OnBtnCancel));
  23. }
  24. public void Start()
  25. {
  26. }
  27. public void OpenFingerSaveMode(XDocument save_target_xml, string save_dir_name, Action success_call_back)
  28. {
  29. if (save_target_xml == null)
  30. {
  31. return;
  32. }
  33. this.mode_ = PhotoModePoseSave.Mode.Finger;
  34. this.save_target_binary_ = null;
  35. this.save_target_xml_ = save_target_xml;
  36. this.save_dir_name_ = save_dir_name;
  37. this.success_call_back_ = success_call_back;
  38. this.Open();
  39. }
  40. public void OpenPoseSaveMode(byte[] save_target_binary)
  41. {
  42. if (this.is_fade_processed || save_target_binary == null || save_target_binary.Length <= 0)
  43. {
  44. return;
  45. }
  46. this.mode_ = PhotoModePoseSave.Mode.Pose;
  47. this.save_target_xml_ = null;
  48. this.save_target_binary_ = save_target_binary;
  49. this.Open();
  50. }
  51. public void OnBtnOk()
  52. {
  53. this.InputPoseName.RemoveFocus();
  54. char[] invalidFileNameChars = Path.GetInvalidFileNameChars();
  55. string file_name = this.InputPoseName.value;
  56. if (string.IsNullOrEmpty(file_name))
  57. {
  58. GameMain.Instance.SysDlg.ShowFromLanguageTerm("ScenePhotoMode/Pエディット/ダイアログ/ポーズ名が記入されていません", null, SystemDialog.TYPE.OK, null, null);
  59. return;
  60. }
  61. if (0 <= file_name.IndexOfAny(invalidFileNameChars))
  62. {
  63. GameMain.Instance.SysDlg.ShowFromLanguageTerm("ScenePhotoMode/Pエディット/ダイアログ/ポーズ名に使用できない文字が使われています", null, SystemDialog.TYPE.OK, null, null);
  64. return;
  65. }
  66. if (this.mode_ == PhotoModePoseSave.Mode.Pose)
  67. {
  68. file_name = this.mode_folder_path + "\\" + file_name + ".anm";
  69. }
  70. else
  71. {
  72. file_name = this.mode_folder_path + "\\" + file_name + ".xml";
  73. }
  74. if (250 < file_name.Length)
  75. {
  76. GameMain.Instance.SysDlg.ShowFromLanguageTerm("ScenePhotoMode/Pエディット/ダイアログ/ポーズ名が長すぎます", null, SystemDialog.TYPE.OK, null, null);
  77. return;
  78. }
  79. if (File.Exists(file_name))
  80. {
  81. GameMain.Instance.SysDlg.ShowFromLanguageTerm("ScenePhotoMode/Pエディット/ダイアログ/データが既に存在しています上書きしますか?", null, SystemDialog.TYPE.YES_NO, delegate
  82. {
  83. GameMain.Instance.SysDlg.Close();
  84. this.Save(file_name);
  85. }, null);
  86. return;
  87. }
  88. this.Save(file_name);
  89. }
  90. public void Save(string file_name)
  91. {
  92. if (this.mode_ == PhotoModePoseSave.Mode.Pose)
  93. {
  94. if (this.save_target_binary_ == null && this.save_target_binary_.Length <= 0)
  95. {
  96. return;
  97. }
  98. }
  99. else if (this.save_target_xml_ == null)
  100. {
  101. return;
  102. }
  103. bool flag = File.Exists(file_name);
  104. try
  105. {
  106. if (this.mode_ == PhotoModePoseSave.Mode.Pose)
  107. {
  108. File.WriteAllBytes(file_name, this.save_target_binary_);
  109. }
  110. else
  111. {
  112. this.save_target_xml_.Save(file_name);
  113. }
  114. MotionWindow motionWindow = this.PhotoMgr.GetWindow(PhotoWindowManager.WindowType.Motion) as MotionWindow;
  115. if (this.mode_ == PhotoModePoseSave.Mode.Pose)
  116. {
  117. if (!flag)
  118. {
  119. motionWindow.AddMyPose(file_name);
  120. }
  121. else
  122. {
  123. motionWindow.OnUpdateMyPose(file_name);
  124. }
  125. }
  126. if (this.success_call_back_ != null)
  127. {
  128. this.success_call_back_();
  129. }
  130. }
  131. catch
  132. {
  133. GameMain.Instance.SysDlg.ShowFromLanguageTerm("ScenePhotoMode/Pエディット/ダイアログ/ポーズの保存に失敗しました", null, SystemDialog.TYPE.OK, null, null);
  134. return;
  135. }
  136. if (this.mode_ == PhotoModePoseSave.Mode.Pose)
  137. {
  138. GameMain.Instance.SysDlg.ShowFromLanguageTerm("ScenePhotoMode/Pエディット/ダイアログ/ポーズを保存しましたモーションウィンドウのマイポーズから選択できます", null, SystemDialog.TYPE.OK, delegate
  139. {
  140. GameMain.Instance.SysDlg.Close();
  141. this.OnBtnCancel();
  142. }, null);
  143. }
  144. else
  145. {
  146. GameMain.Instance.SysDlg.ShowFromLanguageTerm("ScenePhotoMode/Pエディット/ダイアログ/ポーズを保存しました", null, SystemDialog.TYPE.OK, delegate
  147. {
  148. GameMain.Instance.SysDlg.Close();
  149. this.OnBtnCancel();
  150. }, null);
  151. }
  152. }
  153. public void OnBtnCancel()
  154. {
  155. this.InputPoseName.RemoveFocus();
  156. if (this.is_fade_processed)
  157. {
  158. return;
  159. }
  160. TweenAlpha tweenAlpha = base.gameObject.AddComponent<TweenAlpha>();
  161. tweenAlpha.from = 1f;
  162. tweenAlpha.to = 0f;
  163. tweenAlpha.duration = 0.3f;
  164. tweenAlpha.PlayForward();
  165. EventDelegate.Set(tweenAlpha.onFinished, delegate()
  166. {
  167. TweenAlpha component = base.gameObject.GetComponent<TweenAlpha>();
  168. if (component != null)
  169. {
  170. UnityEngine.Object.DestroyImmediate(component);
  171. }
  172. base.gameObject.SetActive(false);
  173. });
  174. }
  175. private void Open()
  176. {
  177. base.gameObject.SetActive(true);
  178. TweenAlpha tweenAlpha = base.gameObject.AddComponent<TweenAlpha>();
  179. tweenAlpha.from = 0f;
  180. tweenAlpha.to = 1f;
  181. tweenAlpha.duration = 0.3f;
  182. tweenAlpha.PlayForward();
  183. EventDelegate.Set(tweenAlpha.onFinished, delegate()
  184. {
  185. TweenAlpha component = base.gameObject.GetComponent<TweenAlpha>();
  186. if (component != null)
  187. {
  188. UnityEngine.Object.DestroyImmediate(component);
  189. }
  190. });
  191. }
  192. private void Update()
  193. {
  194. }
  195. private void OnChangeTitle(PhotSaveLoagDataUnit unit)
  196. {
  197. }
  198. public void OnClickBG()
  199. {
  200. if (this.is_fade_processed)
  201. {
  202. return;
  203. }
  204. if (UICamera.currentTouchID == -2)
  205. {
  206. this.OnBtnCancel();
  207. }
  208. }
  209. private bool is_fade_processed
  210. {
  211. get
  212. {
  213. TweenAlpha component = base.gameObject.GetComponent<TweenAlpha>();
  214. if (component != null && !component.enabled)
  215. {
  216. component.enabled = true;
  217. }
  218. return component != null;
  219. }
  220. }
  221. private string mode_folder_path
  222. {
  223. get
  224. {
  225. string text = string.Empty;
  226. if (this.mode_ == PhotoModePoseSave.Mode.Pose)
  227. {
  228. text = PhotoModePoseSave.folder_path;
  229. }
  230. else
  231. {
  232. if (!Directory.Exists(PhotoWindowManager.path_photo_folder + "FingerData"))
  233. {
  234. Directory.CreateDirectory(PhotoWindowManager.path_photo_folder + "FingerData");
  235. }
  236. text = PhotoWindowManager.path_photo_folder + "FingerData/" + this.save_dir_name_;
  237. if (!Directory.Exists(text))
  238. {
  239. Directory.CreateDirectory(text);
  240. }
  241. }
  242. return text;
  243. }
  244. }
  245. public PhotoWindowManager PhotoMgr;
  246. public UIInput InputPoseName;
  247. private PhotoModePoseSave.Mode mode_;
  248. private byte[] save_target_binary_;
  249. private string save_dir_name_;
  250. private XDocument save_target_xml_;
  251. private Action success_call_back_;
  252. private enum Mode
  253. {
  254. Pose,
  255. Finger
  256. }
  257. }