123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422 |
- 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>();
- string text = Product.isEnglish ? "tutorial_list_en.nei" : "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<KeyValuePair<string, string>> list = new List<KeyValuePair<string, string>>();
- 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<GameObject>(path);
- if (!gameObject)
- {
- NDebug.Warning("チュートリアルパネルのプレハブが見つかりませんでした。\n終了時のコールバックを実行します。");
- if (closeCallback != null)
- {
- closeCallback();
- }
- return;
- }
- GameObject gameObject2 = UnityEngine.Object.Instantiate<GameObject>(gameObject);
- uGUITutorialPanel.m_Instance = gameObject2.GetComponent<uGUITutorialPanel>();
- 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 = "Grocery";
- }
- }
- 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.<Initialize>c__AnonStorey1 <Initialize>c__AnonStorey = new uGUITutorialPanel.<Initialize>c__AnonStorey1();
- <Initialize>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<string, Sprite>();
- this.m_CallbackClose = callback;
- this.m_ButtonOK.interactable = true;
- this.m_ButtonOK.onClick.AddListener(delegate()
- {
- <Initialize>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<Toggle>(itemCount, delegate(int i, Toggle toggle)
- {
- KeyValuePair<string, string> keyValuePair = <Initialize>c__AnonStorey.$this.m_strFileNameArray[i];
- if (<Initialize>c__AnonStorey.$this.index == i)
- {
- toggle.isOn = true;
- }
- Text componentInChildren = toggle.GetComponentInChildren<Text>();
- 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;
- }
- <Initialize>c__AnonStorey.OpenPage(i);
- });
- });
- }
- else
- {
- this.m_ParentMultiMode.SetActive(false);
- this.m_ParentSingleMode.SetActive(true);
- }
- this.OpenPage(0);
- <Initialize>c__AnonStorey.fade = base.GetComponent<uGUICanvasFade>();
- <Initialize>c__AnonStorey.fade.alpha = 0f;
- <Initialize>c__AnonStorey.fade.interactable = false;
- <Initialize>c__AnonStorey.fade.FadeIn(0.5f, delegate
- {
- <Initialize>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<uGUICanvasFade>();
- 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 = Product.isEnglish ? "tutorial_list_en.nei" : "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<KeyValuePair<string, string>> list = new List<KeyValuePair<string, string>>();
- 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<string, string>(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<Sprite> list = new List<Sprite>(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<string, string>[] m_strFileNameArray;
- private bool[] m_IsOpenedPageArray;
- private readonly string strFileNamePath = "SceneTutorial/Sprites/";
- private Dictionary<string, Sprite> m_CacheSpriteArray;
- private Action m_CallbackClose;
- private static List<string> m_SceneNameArray;
- private static uGUITutorialPanel m_Instance;
- private bool m_IsQuittingApplication;
- }
|