uGUITutorialPanel.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422
  1. using System;
  2. using System.Collections.Generic;
  3. using PlayerStatus;
  4. using UnityEngine;
  5. using UnityEngine.UI;
  6. using wf;
  7. public class uGUITutorialPanel : MonoBehaviour
  8. {
  9. public int index { get; private set; }
  10. public static bool IsExistTutorial(string sceneName)
  11. {
  12. if (uGUITutorialPanel.m_SceneNameArray == null || uGUITutorialPanel.m_SceneNameArray.Count <= 0)
  13. {
  14. uGUITutorialPanel.m_SceneNameArray = new List<string>();
  15. string text = Product.isEnglish ? "tutorial_list_en.nei" : "tutorial_list.nei";
  16. if (!GameUty.FileSystem.IsExistentFile(text))
  17. {
  18. NDebug.Assert("表がありません。" + text, false);
  19. }
  20. using (AFileBase afileBase = GameUty.FileSystem.FileOpen(text))
  21. {
  22. using (CsvParser csvParser = new CsvParser())
  23. {
  24. bool condition = csvParser.Open(afileBase);
  25. NDebug.Assert(condition, text + "\nopen failed.");
  26. int i = 0;
  27. List<KeyValuePair<string, string>> list = new List<KeyValuePair<string, string>>();
  28. for (i = 1; i < csvParser.max_cell_y; i++)
  29. {
  30. if (csvParser.IsCellToExistData(0, i))
  31. {
  32. string cellAsString = csvParser.GetCellAsString(0, i);
  33. uGUITutorialPanel.m_SceneNameArray.Add(cellAsString);
  34. }
  35. }
  36. }
  37. }
  38. }
  39. return uGUITutorialPanel.m_SceneNameArray.Contains(sceneName);
  40. }
  41. public static void OpenTutorial(string sceneName, Action closeCallback = null, bool absoluteCall = false)
  42. {
  43. if (string.IsNullOrEmpty(sceneName))
  44. {
  45. NDebug.Assert("チュートリアルの種類に空文字が指定されました", false);
  46. }
  47. if (uGUITutorialPanel.IsOpened())
  48. {
  49. return;
  50. }
  51. if (!uGUITutorialPanel.IsExistTutorial(sceneName))
  52. {
  53. if (closeCallback != null)
  54. {
  55. closeCallback();
  56. }
  57. return;
  58. }
  59. if (!absoluteCall && uGUITutorialPanel.IsTutorialPassed(sceneName))
  60. {
  61. Debug.Log("既に通過しているチュートリアルだったので、チュートリアル用UIは表示しません。\n終了時のコールバックを実行します。");
  62. if (closeCallback != null)
  63. {
  64. closeCallback();
  65. }
  66. return;
  67. }
  68. string path = "SceneTutorial/Canvas Tutorial Panel";
  69. GameObject gameObject = Resources.Load<GameObject>(path);
  70. if (!gameObject)
  71. {
  72. NDebug.Warning("チュートリアルパネルのプレハブが見つかりませんでした。\n終了時のコールバックを実行します。");
  73. if (closeCallback != null)
  74. {
  75. closeCallback();
  76. }
  77. return;
  78. }
  79. GameObject gameObject2 = UnityEngine.Object.Instantiate<GameObject>(gameObject);
  80. uGUITutorialPanel.m_Instance = gameObject2.GetComponent<uGUITutorialPanel>();
  81. uGUITutorialPanel.m_Instance.Initialize(sceneName, closeCallback);
  82. uGUITutorialPanel.SetTutorialFlag(sceneName);
  83. if (uGUITutorialPanel.m_Instance.m_TopTitle != null && sceneName.ToLower() == "WordDictionary".ToLower())
  84. {
  85. uGUITutorialPanel.m_Instance.m_TopTitle.text = "Glossary";
  86. }
  87. }
  88. public static void CloseTutorial(bool immediate = false, bool enableCallback = true)
  89. {
  90. if (!uGUITutorialPanel.IsOpened())
  91. {
  92. return;
  93. }
  94. uGUITutorialPanel.m_Instance.OnClose(immediate, enableCallback);
  95. }
  96. public static bool IsOpened()
  97. {
  98. return uGUITutorialPanel.m_Instance != null;
  99. }
  100. private void Initialize(string type, Action callback)
  101. {
  102. uGUITutorialPanel.<Initialize>c__AnonStorey1 <Initialize>c__AnonStorey = new uGUITutorialPanel.<Initialize>c__AnonStorey1();
  103. <Initialize>c__AnonStorey.$this = this;
  104. Transform uirootTrans = this.GetUIRootTrans();
  105. if (uirootTrans != null)
  106. {
  107. base.transform.SetParent(uirootTrans, false);
  108. }
  109. else
  110. {
  111. NDebug.Assert("SystemUI Rootが見つかりませんでした", false);
  112. }
  113. this.m_CacheSpriteArray = new Dictionary<string, Sprite>();
  114. this.m_CallbackClose = callback;
  115. this.m_ButtonOK.interactable = true;
  116. this.m_ButtonOK.onClick.AddListener(delegate()
  117. {
  118. <Initialize>c__AnonStorey.$this.OnClose(false, true);
  119. });
  120. this.ReadCSV(type);
  121. if (this.IsMultiMode())
  122. {
  123. this.m_ParentMultiMode.SetActive(true);
  124. this.m_ParentSingleMode.SetActive(false);
  125. int itemCount = this.m_strFileNameArray.Length;
  126. this.m_ListViewerButtons.Show<Toggle>(itemCount, delegate(int i, Toggle toggle)
  127. {
  128. KeyValuePair<string, string> keyValuePair = <Initialize>c__AnonStorey.$this.m_strFileNameArray[i];
  129. if (<Initialize>c__AnonStorey.$this.index == i)
  130. {
  131. toggle.isOn = true;
  132. }
  133. Text componentInChildren = toggle.GetComponentInChildren<Text>();
  134. if (!string.IsNullOrEmpty(keyValuePair.Value))
  135. {
  136. componentInChildren.text = keyValuePair.Value;
  137. Utility.SetLocalizeTerm(componentInChildren, "Tutorial/項目名/" + keyValuePair.Value, false);
  138. }
  139. else
  140. {
  141. componentInChildren.text = string.Format("(!項目名無し).{1}", i);
  142. }
  143. toggle.onValueChanged.AddListener(delegate(bool value)
  144. {
  145. if (!value)
  146. {
  147. return;
  148. }
  149. <Initialize>c__AnonStorey.OpenPage(i);
  150. });
  151. });
  152. }
  153. else
  154. {
  155. this.m_ParentMultiMode.SetActive(false);
  156. this.m_ParentSingleMode.SetActive(true);
  157. }
  158. this.OpenPage(0);
  159. <Initialize>c__AnonStorey.fade = base.GetComponent<uGUICanvasFade>();
  160. <Initialize>c__AnonStorey.fade.alpha = 0f;
  161. <Initialize>c__AnonStorey.fade.interactable = false;
  162. <Initialize>c__AnonStorey.fade.FadeIn(0.5f, delegate
  163. {
  164. <Initialize>c__AnonStorey.fade.interactable = true;
  165. });
  166. }
  167. private void OnClose(bool immediate = false, bool enableCallback = true)
  168. {
  169. if (immediate)
  170. {
  171. uGUITutorialPanel.m_Instance = null;
  172. UnityEngine.Object.Destroy(base.gameObject);
  173. if (enableCallback && this.m_CallbackClose != null)
  174. {
  175. this.m_CallbackClose();
  176. }
  177. }
  178. else
  179. {
  180. uGUICanvasFade component = base.GetComponent<uGUICanvasFade>();
  181. component.interactable = false;
  182. component.FadeOut(0.5f, delegate
  183. {
  184. uGUITutorialPanel.m_Instance = null;
  185. UnityEngine.Object.Destroy(this.gameObject);
  186. if (enableCallback && this.m_CallbackClose != null)
  187. {
  188. this.m_CallbackClose();
  189. }
  190. });
  191. }
  192. }
  193. private bool OpenPage(int pageNumber)
  194. {
  195. if (!this.IsChangeIndex(pageNumber))
  196. {
  197. Debug.LogFormat("{0} ページを開けなかった", new object[]
  198. {
  199. pageNumber
  200. });
  201. return false;
  202. }
  203. this.SetImage(this.m_strFileNameArray[pageNumber].Key);
  204. this.m_IsOpenedPageArray[pageNumber] = true;
  205. return true;
  206. }
  207. private bool TryChangeIndex(int changeIndex)
  208. {
  209. if (!this.IsChangeIndex(changeIndex))
  210. {
  211. return false;
  212. }
  213. this.index = changeIndex;
  214. return true;
  215. }
  216. private bool IsChangeIndex(int changeIndex)
  217. {
  218. int num = this.m_strFileNameArray.Length;
  219. return changeIndex >= 0 && changeIndex < num;
  220. }
  221. private void SetImage(string fileName)
  222. {
  223. Sprite sprite;
  224. if (this.m_CacheSpriteArray.ContainsKey(fileName))
  225. {
  226. sprite = this.m_CacheSpriteArray[fileName];
  227. }
  228. else
  229. {
  230. string text = this.strFileNamePath + fileName;
  231. sprite = this.CreateSprite(fileName + ".tex");
  232. if (sprite != null)
  233. {
  234. this.m_CacheSpriteArray.Add(fileName, sprite);
  235. }
  236. else
  237. {
  238. NDebug.Warning(string.Format("[uGUITutorialPanel]チュートリアル画像「{0}」が見つかりませんでした", fileName));
  239. }
  240. }
  241. if (this.IsMultiMode())
  242. {
  243. this.m_ImageMultiTutorial.sprite = sprite;
  244. }
  245. else
  246. {
  247. this.m_ImageSingleTutorial.sprite = sprite;
  248. }
  249. }
  250. private bool IsMultiMode()
  251. {
  252. return this.m_strFileNameArray.Length > 1;
  253. }
  254. private static bool IsTutorialPassed(string tutorialName)
  255. {
  256. string flagName = "__チュートリアルフラグ_" + tutorialName;
  257. Status status = GameMain.Instance.CharacterMgr.status;
  258. return status.GetFlag(flagName) > 0;
  259. }
  260. private static void SetTutorialFlag(string tutorialName)
  261. {
  262. string flagName = "__チュートリアルフラグ_" + tutorialName;
  263. Status status = GameMain.Instance.CharacterMgr.status;
  264. status.SetFlag(flagName, 1);
  265. }
  266. private Transform GetUIRootTrans()
  267. {
  268. Transform result = null;
  269. GameObject gameObject = GameObject.Find("SystemUI Root");
  270. if (gameObject)
  271. {
  272. result = gameObject.transform;
  273. }
  274. return result;
  275. }
  276. private void ReadCSV(string type)
  277. {
  278. string text = Product.isEnglish ? "tutorial_list_en.nei" : "tutorial_list.nei";
  279. if (!GameUty.FileSystem.IsExistentFile(text))
  280. {
  281. NDebug.Assert("表がありません。" + text, false);
  282. }
  283. using (AFileBase afileBase = GameUty.FileSystem.FileOpen(text))
  284. {
  285. using (CsvParser csvParser = new CsvParser())
  286. {
  287. bool condition = csvParser.Open(afileBase);
  288. NDebug.Assert(condition, text + "\nopen failed.");
  289. int i = 0;
  290. List<KeyValuePair<string, string>> list = new List<KeyValuePair<string, string>>();
  291. for (i = 1; i < csvParser.max_cell_y; i++)
  292. {
  293. if (csvParser.IsCellToExistData(0, i))
  294. {
  295. string cellAsString = csvParser.GetCellAsString(0, i);
  296. if (cellAsString == type)
  297. {
  298. break;
  299. }
  300. }
  301. }
  302. for (int j = 2; j < csvParser.max_cell_x; j += 2)
  303. {
  304. if (csvParser.IsCellToExistData(j, i))
  305. {
  306. string cellAsString2 = csvParser.GetCellAsString(j, i);
  307. string cellAsString3 = csvParser.GetCellAsString(j + 1, i);
  308. if (!string.IsNullOrEmpty(cellAsString2))
  309. {
  310. list.Add(new KeyValuePair<string, string>(cellAsString2, cellAsString3));
  311. }
  312. }
  313. }
  314. this.m_strFileNameArray = list.ToArray();
  315. this.m_IsOpenedPageArray = new bool[this.m_strFileNameArray.Length];
  316. }
  317. }
  318. if (this.m_strFileNameArray.Length <= 0)
  319. {
  320. NDebug.Warning(string.Format("チュートリアル「{0}」の表データが空でした", type));
  321. }
  322. }
  323. private void OnApplicationQuit()
  324. {
  325. this.m_IsQuittingApplication = true;
  326. }
  327. private void OnDestroy()
  328. {
  329. if (this.m_IsQuittingApplication)
  330. {
  331. return;
  332. }
  333. if (uGUITutorialPanel.m_Instance != null && uGUITutorialPanel.m_Instance == this)
  334. {
  335. uGUITutorialPanel.m_Instance = null;
  336. }
  337. this.m_ImageMultiTutorial.sprite = null;
  338. this.m_ImageSingleTutorial.sprite = null;
  339. if (this.m_CacheSpriteArray != null)
  340. {
  341. int count = this.m_CacheSpriteArray.Count;
  342. List<Sprite> list = new List<Sprite>(this.m_CacheSpriteArray.Values);
  343. this.m_CacheSpriteArray.Clear();
  344. for (int i = 0; i < count; i++)
  345. {
  346. UnityEngine.Object.DestroyImmediate(list[i].texture);
  347. UnityEngine.Object.DestroyImmediate(list[i]);
  348. }
  349. list.Clear();
  350. }
  351. this.m_CallbackClose = null;
  352. }
  353. private Sprite CreateSprite(string fileName)
  354. {
  355. Sprite sprite = null;
  356. if (GameUty.FileSystem.IsExistentFile(fileName))
  357. {
  358. Texture2D texture2D = ImportCM.CreateTexture(fileName);
  359. sprite = Sprite.Create(texture2D, new Rect(0f, 0f, (float)texture2D.width, (float)texture2D.height), default(Vector2));
  360. sprite.name = fileName;
  361. }
  362. return sprite;
  363. }
  364. [SerializeField]
  365. private Button m_ButtonOK;
  366. [Header("ページ数単体時のオブジェクト")]
  367. [SerializeField]
  368. private GameObject m_ParentSingleMode;
  369. [SerializeField]
  370. private Image m_ImageSingleTutorial;
  371. [Header("ページ数複数時のオブジェクト")]
  372. [SerializeField]
  373. private GameObject m_ParentMultiMode;
  374. [SerializeField]
  375. private Image m_ImageMultiTutorial;
  376. [SerializeField]
  377. private uGUIListViewer m_ListViewerButtons;
  378. [SerializeField]
  379. private Text m_TopTitle;
  380. private KeyValuePair<string, string>[] m_strFileNameArray;
  381. private bool[] m_IsOpenedPageArray;
  382. private readonly string strFileNamePath = "SceneTutorial/Sprites/";
  383. private Dictionary<string, Sprite> m_CacheSpriteArray;
  384. private Action m_CallbackClose;
  385. private static List<string> m_SceneNameArray;
  386. private static uGUITutorialPanel m_Instance;
  387. private bool m_IsQuittingApplication;
  388. }