PhotoModeObjectSave.cs 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. using System;
  2. using System.IO;
  3. using UnityEngine;
  4. public class PhotoModeObjectSave : MonoBehaviour
  5. {
  6. public void Awake()
  7. {
  8. EventDelegate.Add(UTY.GetChildObject(base.gameObject, "Base/Ok", false).GetComponent<UIButton>().onClick, new EventDelegate.Callback(this.OnBtnOk));
  9. EventDelegate.Add(UTY.GetChildObject(base.gameObject, "Base/Cancel", false).GetComponent<UIButton>().onClick, new EventDelegate.Callback(this.OnBtnCancel));
  10. }
  11. public void Start()
  12. {
  13. }
  14. public void Open(BasePhotoCustomObject saveObject, Action<string> successCallBack)
  15. {
  16. this.saveObject = saveObject;
  17. this.successCallBack = successCallBack;
  18. base.gameObject.SetActive(true);
  19. TweenAlpha tweenAlpha = base.gameObject.AddComponent<TweenAlpha>();
  20. tweenAlpha.from = 0f;
  21. tweenAlpha.to = 1f;
  22. tweenAlpha.duration = 0.3f;
  23. tweenAlpha.PlayForward();
  24. EventDelegate.Set(tweenAlpha.onFinished, delegate
  25. {
  26. TweenAlpha component = base.gameObject.GetComponent<TweenAlpha>();
  27. if (component != null)
  28. {
  29. UnityEngine.Object.DestroyImmediate(component);
  30. }
  31. });
  32. }
  33. public void OnBtnOk()
  34. {
  35. this.InputPoseName.RemoveFocus();
  36. char[] invalidFileNameChars = Path.GetInvalidFileNameChars();
  37. string text = this.InputPoseName.value;
  38. if (string.IsNullOrEmpty(text))
  39. {
  40. GameMain.Instance.SysDlg.Show("オブジェクト名が記入されていません", SystemDialog.TYPE.OK, null, null);
  41. return;
  42. }
  43. if (0 <= text.IndexOfAny(invalidFileNameChars))
  44. {
  45. GameMain.Instance.SysDlg.Show("オブジェクト名に使用できない文字が使われています", SystemDialog.TYPE.OK, null, null);
  46. return;
  47. }
  48. text = ObjectCreateWindow.folder_path + "\\" + text + ".poj";
  49. if (250 < text.Length)
  50. {
  51. GameMain.Instance.SysDlg.Show("オブジェクト名が長すぎます", SystemDialog.TYPE.OK, null, null);
  52. return;
  53. }
  54. if (File.Exists(text))
  55. {
  56. GameMain.Instance.SysDlg.Show("データが既に存在しています\n別の名前を指定してください", SystemDialog.TYPE.OK, null, null);
  57. return;
  58. }
  59. this.Save(text);
  60. }
  61. public void Save(string file_name)
  62. {
  63. try
  64. {
  65. File.WriteAllBytes(file_name, this.saveObject.Serialize());
  66. }
  67. catch
  68. {
  69. GameMain.Instance.SysDlg.Show("オブジェクトの保存に失敗しました", SystemDialog.TYPE.OK, null, null);
  70. return;
  71. }
  72. if (this.successCallBack != null)
  73. {
  74. this.successCallBack(file_name);
  75. }
  76. GameMain.Instance.SysDlg.Show("オブジェクトを保存しました\nオブジェクト管理ウィンドウのマイオブジェクトから選択できます", SystemDialog.TYPE.OK, delegate
  77. {
  78. GameMain.Instance.SysDlg.Close();
  79. this.OnBtnCancel();
  80. }, null);
  81. }
  82. public void OnBtnCancel()
  83. {
  84. this.InputPoseName.RemoveFocus();
  85. if (this.is_fade_processed)
  86. {
  87. return;
  88. }
  89. TweenAlpha tweenAlpha = base.gameObject.AddComponent<TweenAlpha>();
  90. tweenAlpha.from = 1f;
  91. tweenAlpha.to = 0f;
  92. tweenAlpha.duration = 0.3f;
  93. tweenAlpha.PlayForward();
  94. EventDelegate.Set(tweenAlpha.onFinished, delegate
  95. {
  96. TweenAlpha component = base.gameObject.GetComponent<TweenAlpha>();
  97. if (component != null)
  98. {
  99. UnityEngine.Object.DestroyImmediate(component);
  100. }
  101. base.gameObject.SetActive(false);
  102. });
  103. }
  104. private bool is_fade_processed
  105. {
  106. get
  107. {
  108. TweenAlpha component = base.gameObject.GetComponent<TweenAlpha>();
  109. if (component != null && !component.enabled)
  110. {
  111. component.enabled = true;
  112. }
  113. return component != null;
  114. }
  115. }
  116. public PhotoWindowManager PhotoMgr;
  117. public UIInput InputPoseName;
  118. private BasePhotoCustomObject saveObject;
  119. private Action<string> successCallBack;
  120. }