VRTutorialMenu.cs 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5. using UnityEngine.Events;
  6. using UnityEngine.UI;
  7. public class VRTutorialMenu : MonoBehaviour
  8. {
  9. public void Init(UnityAction callback, string fileName = "vrcom_tutorial.nei")
  10. {
  11. this.m_ManualDataArray.Clear();
  12. this.m_IndexPage = 0;
  13. if (!GameUty.FileSystem.IsExistentFile(fileName))
  14. {
  15. NDebug.Assert("表がありません。" + fileName, false);
  16. }
  17. using (AFileBase afileBase = GameUty.FileSystem.FileOpen(fileName))
  18. {
  19. using (CsvParser csvParser = new CsvParser())
  20. {
  21. bool condition = csvParser.Open(afileBase);
  22. NDebug.Assert(condition, fileName + "\nopen failed.");
  23. for (int i = 1; i < csvParser.max_cell_y; i++)
  24. {
  25. if (csvParser.IsCellToExistData(0, i))
  26. {
  27. int num = 0;
  28. int cellAsInteger = csvParser.GetCellAsInteger(num++, i);
  29. string cellAsString = csvParser.GetCellAsString(num++, i);
  30. char[] array = csvParser.GetCellAsString(num++, i).ToCharArray();
  31. bool flag = false;
  32. for (int j = 0; j < array.Length; j++)
  33. {
  34. if (array[j] == ((int)GameMain.Instance.VRDeviceTypeID).ToString().ToCharArray()[0])
  35. {
  36. flag = true;
  37. }
  38. }
  39. if (flag)
  40. {
  41. this.m_ManualDataArray.Add(new VRTutorialMenu.ManualData(cellAsInteger, cellAsString));
  42. }
  43. }
  44. }
  45. }
  46. }
  47. this.m_ButtonReturn.onClick.RemoveAllListeners();
  48. if (callback != null)
  49. {
  50. this.m_ButtonReturn.onClick.AddListener(callback);
  51. }
  52. this.m_ButtonReturn.onClick.AddListener(delegate
  53. {
  54. VRCanvasManager.Instance.OpenVRCanvas(VRCanvasManager.VRCanvasType.MainMenu);
  55. });
  56. this.m_ButtonReturn.interactable = false;
  57. this.ButtonEvent_PageChange(false);
  58. }
  59. public void ButtonEvent_PageChange(bool isNextPage)
  60. {
  61. this.m_IndexPage += ((!isNextPage) ? -1 : 1);
  62. this.m_IndexPage = ((this.m_ManualDataArray.Count > this.m_IndexPage) ? this.m_IndexPage : (this.m_ManualDataArray.Count - 1));
  63. this.m_IndexPage = ((this.m_IndexPage >= 0) ? this.m_IndexPage : 0);
  64. VRTutorialMenu.ManualData manualData = this.m_ManualDataArray[this.m_IndexPage];
  65. string path = this.m_uGUIAtlasPath + manualData.ImageName;
  66. base.StartCoroutine(this.Coroutine_Load<Sprite>(path, delegate(ResourceRequest req)
  67. {
  68. this.m_ImageManual.sprite = (req.asset as Sprite);
  69. }));
  70. this.m_TextPageNumber.text = (this.m_IndexPage + 1).ToString() + " / " + this.m_ManualDataArray.Count.ToString();
  71. this.m_ButtonRight.interactable = (this.m_IndexPage < this.m_ManualDataArray.Count - 1);
  72. this.m_ButtonLeft.interactable = (this.m_IndexPage > 0);
  73. manualData.IsDisplayed = true;
  74. bool flag = true;
  75. for (int i = 0; i < this.m_ManualDataArray.Count; i++)
  76. {
  77. flag &= this.m_ManualDataArray[i].IsDisplayed;
  78. }
  79. this.m_ButtonReturn.interactable = flag;
  80. }
  81. private IEnumerator Coroutine_Load<T>(string path, UnityAction<ResourceRequest> callback) where T : UnityEngine.Object
  82. {
  83. ResourceRequest res = Resources.LoadAsync<T>(path);
  84. while (!res.isDone)
  85. {
  86. yield return null;
  87. }
  88. callback(res);
  89. yield break;
  90. }
  91. [SerializeField]
  92. private Image m_ImageManual;
  93. [SerializeField]
  94. private Button m_ButtonReturn;
  95. [SerializeField]
  96. private Button m_ButtonRight;
  97. [SerializeField]
  98. private Button m_ButtonLeft;
  99. [SerializeField]
  100. private Text m_TextPageNumber;
  101. private List<VRTutorialMenu.ManualData> m_ManualDataArray = new List<VRTutorialMenu.ManualData>();
  102. private int m_IndexPage;
  103. private string m_uGUIAtlasPath = "SceneVRCommunication\\Tablet\\Sprite\\";
  104. private class ManualData
  105. {
  106. public ManualData(int id, string imageName)
  107. {
  108. this.ID = id;
  109. this.ImageName = imageName;
  110. this.IsDisplayed = false;
  111. }
  112. public int ID;
  113. public string ImageName;
  114. public bool IsDisplayed;
  115. }
  116. }