uGUITutorialPanel.cs 10 KB

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