using System; using System.IO; using UnityEngine; public class PhotoModeObjectSave : MonoBehaviour { public void Awake() { EventDelegate.Add(UTY.GetChildObject(base.gameObject, "Base/Ok", false).GetComponent().onClick, new EventDelegate.Callback(this.OnBtnOk)); EventDelegate.Add(UTY.GetChildObject(base.gameObject, "Base/Cancel", false).GetComponent().onClick, new EventDelegate.Callback(this.OnBtnCancel)); } public void Start() { } public void Open(BasePhotoCustomObject saveObject, Action successCallBack) { this.saveObject = saveObject; this.successCallBack = successCallBack; base.gameObject.SetActive(true); TweenAlpha tweenAlpha = base.gameObject.AddComponent(); tweenAlpha.from = 0f; tweenAlpha.to = 1f; tweenAlpha.duration = 0.3f; tweenAlpha.PlayForward(); EventDelegate.Set(tweenAlpha.onFinished, delegate { TweenAlpha component = base.gameObject.GetComponent(); if (component != null) { UnityEngine.Object.DestroyImmediate(component); } }); } public void OnBtnOk() { this.InputPoseName.RemoveFocus(); char[] invalidFileNameChars = Path.GetInvalidFileNameChars(); string text = this.InputPoseName.value; if (string.IsNullOrEmpty(text)) { GameMain.Instance.SysDlg.Show("オブジェクト名が記入されていません", SystemDialog.TYPE.OK, null, null); return; } if (0 <= text.IndexOfAny(invalidFileNameChars)) { GameMain.Instance.SysDlg.Show("オブジェクト名に使用できない文字が使われています", SystemDialog.TYPE.OK, null, null); return; } text = ObjectCreateWindow.folder_path + "\\" + text + ".poj"; if (250 < text.Length) { GameMain.Instance.SysDlg.Show("オブジェクト名が長すぎます", SystemDialog.TYPE.OK, null, null); return; } if (File.Exists(text)) { GameMain.Instance.SysDlg.Show("データが既に存在しています\n別の名前を指定してください", SystemDialog.TYPE.OK, null, null); return; } this.Save(text); } public void Save(string file_name) { try { File.WriteAllBytes(file_name, this.saveObject.Serialize()); } catch { GameMain.Instance.SysDlg.Show("オブジェクトの保存に失敗しました", SystemDialog.TYPE.OK, null, null); return; } if (this.successCallBack != null) { this.successCallBack(file_name); } GameMain.Instance.SysDlg.Show("オブジェクトを保存しました\nオブジェクト管理ウィンドウのマイオブジェクトから選択できます", SystemDialog.TYPE.OK, delegate { GameMain.Instance.SysDlg.Close(); this.OnBtnCancel(); }, null); } public void OnBtnCancel() { this.InputPoseName.RemoveFocus(); if (this.is_fade_processed) { return; } TweenAlpha tweenAlpha = base.gameObject.AddComponent(); tweenAlpha.from = 1f; tweenAlpha.to = 0f; tweenAlpha.duration = 0.3f; tweenAlpha.PlayForward(); EventDelegate.Set(tweenAlpha.onFinished, delegate { TweenAlpha component = base.gameObject.GetComponent(); if (component != null) { UnityEngine.Object.DestroyImmediate(component); } base.gameObject.SetActive(false); }); } private bool is_fade_processed { get { TweenAlpha component = base.gameObject.GetComponent(); if (component != null && !component.enabled) { component.enabled = true; } return component != null; } } public PhotoWindowManager PhotoMgr; public UIInput InputPoseName; private BasePhotoCustomObject saveObject; private Action successCallBack; }