using System; using System.Collections.Generic; using PlayerStatus; using UnityEngine; using UnityEngine.UI; using wf; public class uGUITutorialPanel : MonoBehaviour { public int index { get; private set; } public static bool IsExistTutorial(string sceneName) { if (uGUITutorialPanel.m_SceneNameArray == null || uGUITutorialPanel.m_SceneNameArray.Count <= 0) { uGUITutorialPanel.m_SceneNameArray = new List(); string text = "tutorial_list.nei"; if (!GameUty.FileSystem.IsExistentFile(text)) { NDebug.Assert("表がありません。" + text, false); } using (AFileBase afileBase = GameUty.FileSystem.FileOpen(text)) { using (CsvParser csvParser = new CsvParser()) { bool condition = csvParser.Open(afileBase); NDebug.Assert(condition, text + "\nopen failed."); int i = 0; List> list = new List>(); for (i = 1; i < csvParser.max_cell_y; i++) { if (csvParser.IsCellToExistData(0, i)) { string cellAsString = csvParser.GetCellAsString(0, i); uGUITutorialPanel.m_SceneNameArray.Add(cellAsString); } } } } } return uGUITutorialPanel.m_SceneNameArray.Contains(sceneName); } public static void OpenTutorial(string sceneName, Action closeCallback = null, bool absoluteCall = false) { if (string.IsNullOrEmpty(sceneName)) { NDebug.Assert("チュートリアルの種類に空文字が指定されました", false); } if (uGUITutorialPanel.IsOpened()) { return; } if (!uGUITutorialPanel.IsExistTutorial(sceneName)) { if (closeCallback != null) { closeCallback(); } return; } if (!absoluteCall && uGUITutorialPanel.IsTutorialPassed(sceneName)) { Debug.Log("既に通過しているチュートリアルだったので、チュートリアル用UIは表示しません。\n終了時のコールバックを実行します。"); if (closeCallback != null) { closeCallback(); } return; } string path = "SceneTutorial/Canvas Tutorial Panel"; GameObject gameObject = Resources.Load(path); if (!gameObject) { NDebug.Warning("チュートリアルパネルのプレハブが見つかりませんでした。\n終了時のコールバックを実行します。"); if (closeCallback != null) { closeCallback(); } return; } GameObject gameObject2 = UnityEngine.Object.Instantiate(gameObject); uGUITutorialPanel.m_Instance = gameObject2.GetComponent(); uGUITutorialPanel.m_Instance.Initialize(sceneName, closeCallback); uGUITutorialPanel.SetTutorialFlag(sceneName); if (uGUITutorialPanel.m_Instance.m_TopTitle != null && sceneName.ToLower() == "WordDictionary".ToLower()) { uGUITutorialPanel.m_Instance.m_TopTitle.text = "TUTORIAL"; } } public static void CloseTutorial(bool immediate = false, bool enableCallback = true) { if (!uGUITutorialPanel.IsOpened()) { return; } uGUITutorialPanel.m_Instance.OnClose(immediate, enableCallback); } public static bool IsOpened() { return uGUITutorialPanel.m_Instance != null; } private void Initialize(string type, Action callback) { uGUITutorialPanel.c__AnonStorey1 c__AnonStorey = new uGUITutorialPanel.c__AnonStorey1(); c__AnonStorey.$this = this; Transform uirootTrans = this.GetUIRootTrans(); if (uirootTrans != null) { base.transform.SetParent(uirootTrans, false); } else { NDebug.Assert("SystemUI Rootが見つかりませんでした", false); } this.m_CacheSpriteArray = new Dictionary(); this.m_CallbackClose = callback; this.m_ButtonOK.interactable = true; this.m_ButtonOK.onClick.AddListener(delegate() { c__AnonStorey.$this.OnClose(false, true); }); this.ReadCSV(type); if (this.IsMultiMode()) { this.m_ParentMultiMode.SetActive(true); this.m_ParentSingleMode.SetActive(false); int itemCount = this.m_strFileNameArray.Length; this.m_ListViewerButtons.Show(itemCount, delegate(int i, Toggle toggle) { KeyValuePair keyValuePair = c__AnonStorey.$this.m_strFileNameArray[i]; if (c__AnonStorey.$this.index == i) { toggle.isOn = true; } Text componentInChildren = toggle.GetComponentInChildren(); if (!string.IsNullOrEmpty(keyValuePair.Value)) { componentInChildren.text = keyValuePair.Value; Utility.SetLocalizeTerm(componentInChildren, "Tutorial/項目名/" + keyValuePair.Value, false); } else { componentInChildren.text = string.Format("(!項目名無し).{1}", i); } toggle.onValueChanged.AddListener(delegate(bool value) { if (!value) { return; } c__AnonStorey.OpenPage(i); }); }); } else { this.m_ParentMultiMode.SetActive(false); this.m_ParentSingleMode.SetActive(true); } this.OpenPage(0); c__AnonStorey.fade = base.GetComponent(); c__AnonStorey.fade.alpha = 0f; c__AnonStorey.fade.interactable = false; c__AnonStorey.fade.FadeIn(0.5f, delegate { c__AnonStorey.fade.interactable = true; }); } private void OnClose(bool immediate = false, bool enableCallback = true) { if (immediate) { uGUITutorialPanel.m_Instance = null; UnityEngine.Object.Destroy(base.gameObject); if (enableCallback && this.m_CallbackClose != null) { this.m_CallbackClose(); } } else { uGUICanvasFade component = base.GetComponent(); component.interactable = false; component.FadeOut(0.5f, delegate { uGUITutorialPanel.m_Instance = null; UnityEngine.Object.Destroy(this.gameObject); if (enableCallback && this.m_CallbackClose != null) { this.m_CallbackClose(); } }); } } private bool OpenPage(int pageNumber) { if (!this.IsChangeIndex(pageNumber)) { Debug.LogFormat("{0} ページを開けなかった", new object[] { pageNumber }); return false; } this.SetImage(this.m_strFileNameArray[pageNumber].Key); this.m_IsOpenedPageArray[pageNumber] = true; return true; } private bool TryChangeIndex(int changeIndex) { if (!this.IsChangeIndex(changeIndex)) { return false; } this.index = changeIndex; return true; } private bool IsChangeIndex(int changeIndex) { int num = this.m_strFileNameArray.Length; return changeIndex >= 0 && changeIndex < num; } private void SetImage(string fileName) { Sprite sprite; if (this.m_CacheSpriteArray.ContainsKey(fileName)) { sprite = this.m_CacheSpriteArray[fileName]; } else { string text = this.strFileNamePath + fileName; sprite = this.CreateSprite(fileName + ".tex"); if (sprite != null) { this.m_CacheSpriteArray.Add(fileName, sprite); } else { NDebug.Warning(string.Format("[uGUITutorialPanel]チュートリアル画像「{0}」が見つかりませんでした", fileName)); } } if (this.IsMultiMode()) { this.m_ImageMultiTutorial.sprite = sprite; } else { this.m_ImageSingleTutorial.sprite = sprite; } } private bool IsMultiMode() { return this.m_strFileNameArray.Length > 1; } private static bool IsTutorialPassed(string tutorialName) { string flagName = "__チュートリアルフラグ_" + tutorialName; Status status = GameMain.Instance.CharacterMgr.status; return status.GetFlag(flagName) > 0; } private static void SetTutorialFlag(string tutorialName) { string flagName = "__チュートリアルフラグ_" + tutorialName; Status status = GameMain.Instance.CharacterMgr.status; status.SetFlag(flagName, 1); } private Transform GetUIRootTrans() { Transform result = null; GameObject gameObject = GameObject.Find("SystemUI Root"); if (gameObject) { result = gameObject.transform; } return result; } private void ReadCSV(string type) { string text = "tutorial_list.nei"; if (!GameUty.FileSystem.IsExistentFile(text)) { NDebug.Assert("表がありません。" + text, false); } using (AFileBase afileBase = GameUty.FileSystem.FileOpen(text)) { using (CsvParser csvParser = new CsvParser()) { bool condition = csvParser.Open(afileBase); NDebug.Assert(condition, text + "\nopen failed."); int i = 0; List> list = new List>(); for (i = 1; i < csvParser.max_cell_y; i++) { if (csvParser.IsCellToExistData(0, i)) { string cellAsString = csvParser.GetCellAsString(0, i); if (cellAsString == type) { break; } } } for (int j = 2; j < csvParser.max_cell_x; j += 2) { if (csvParser.IsCellToExistData(j, i)) { string cellAsString2 = csvParser.GetCellAsString(j, i); string cellAsString3 = csvParser.GetCellAsString(j + 1, i); if (!string.IsNullOrEmpty(cellAsString2)) { list.Add(new KeyValuePair(cellAsString2, cellAsString3)); } } } this.m_strFileNameArray = list.ToArray(); this.m_IsOpenedPageArray = new bool[this.m_strFileNameArray.Length]; } } if (this.m_strFileNameArray.Length <= 0) { NDebug.Warning(string.Format("チュートリアル「{0}」の表データが空でした", type)); } } private void OnApplicationQuit() { this.m_IsQuittingApplication = true; } private void OnDestroy() { if (this.m_IsQuittingApplication) { return; } if (uGUITutorialPanel.m_Instance != null && uGUITutorialPanel.m_Instance == this) { uGUITutorialPanel.m_Instance = null; } this.m_ImageMultiTutorial.sprite = null; this.m_ImageSingleTutorial.sprite = null; if (this.m_CacheSpriteArray != null) { int count = this.m_CacheSpriteArray.Count; List list = new List(this.m_CacheSpriteArray.Values); this.m_CacheSpriteArray.Clear(); for (int i = 0; i < count; i++) { UnityEngine.Object.DestroyImmediate(list[i].texture); UnityEngine.Object.DestroyImmediate(list[i]); } list.Clear(); } this.m_CallbackClose = null; } private Sprite CreateSprite(string fileName) { Sprite sprite = null; if (GameUty.FileSystem.IsExistentFile(fileName)) { Texture2D texture2D = ImportCM.CreateTexture(fileName); sprite = Sprite.Create(texture2D, new Rect(0f, 0f, (float)texture2D.width, (float)texture2D.height), default(Vector2)); sprite.name = fileName; } return sprite; } [SerializeField] private Button m_ButtonOK; [Header("ページ数単体時のオブジェクト")] [SerializeField] private GameObject m_ParentSingleMode; [SerializeField] private Image m_ImageSingleTutorial; [Header("ページ数複数時のオブジェクト")] [SerializeField] private GameObject m_ParentMultiMode; [SerializeField] private Image m_ImageMultiTutorial; [SerializeField] private uGUIListViewer m_ListViewerButtons; [SerializeField] private Text m_TopTitle; private KeyValuePair[] m_strFileNameArray; private bool[] m_IsOpenedPageArray; private readonly string strFileNamePath = "SceneTutorial/Sprites/"; private Dictionary m_CacheSpriteArray; private Action m_CallbackClose; private static List m_SceneNameArray; private static uGUITutorialPanel m_Instance; private bool m_IsQuittingApplication; }