VRManualMenu.cs 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  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 VRManualMenu : MonoBehaviour
  8. {
  9. private void Start()
  10. {
  11. this.Init();
  12. }
  13. private void Init()
  14. {
  15. List<VRManualMenu.ManualData> list = new List<VRManualMenu.ManualData>();
  16. string text = "vrcom_config.nei";
  17. if (!GameUty.FileSystem.IsExistentFile(text))
  18. {
  19. NDebug.Assert("表がありません。" + text, false);
  20. }
  21. using (AFileBase afileBase = GameUty.FileSystem.FileOpen(text))
  22. {
  23. using (CsvParser csvParser = new CsvParser())
  24. {
  25. bool condition = csvParser.Open(afileBase);
  26. NDebug.Assert(condition, text + "\nopen failed.");
  27. for (int i = 1; i < csvParser.max_cell_y; i++)
  28. {
  29. if (csvParser.IsCellToExistData(0, i))
  30. {
  31. int num = 0;
  32. int cellAsInteger = csvParser.GetCellAsInteger(num++, i);
  33. string cellAsString = csvParser.GetCellAsString(num++, i);
  34. string cellAsString2 = csvParser.GetCellAsString(num++, i);
  35. char[] array = csvParser.GetCellAsString(num++, i).ToCharArray();
  36. string cellAsString3 = csvParser.GetCellAsString(num++, i);
  37. bool flag = false;
  38. for (int j = 0; j < array.Length; j++)
  39. {
  40. if (array[j] == ((int)GameMain.Instance.VRDeviceTypeID).ToString().ToCharArray()[0])
  41. {
  42. flag = true;
  43. }
  44. }
  45. if (flag)
  46. {
  47. if (string.IsNullOrEmpty(cellAsString))
  48. {
  49. list.Add(new VRManualMenu.ManualData(cellAsInteger, -1, cellAsString2, cellAsString3, null));
  50. }
  51. else
  52. {
  53. list.Add(new VRManualMenu.ManualData(cellAsInteger, int.Parse(cellAsString), cellAsString2, cellAsString3, null));
  54. }
  55. }
  56. }
  57. }
  58. }
  59. }
  60. for (int k = 0; k < list.Count; k++)
  61. {
  62. VRManualMenu.ManualData data = list[k];
  63. if (data.BeforeID != -1)
  64. {
  65. this.m_ManualDataArray.Add(data);
  66. }
  67. else
  68. {
  69. GameObject gameObject = UnityEngine.Object.Instantiate<GameObject>(this.m_PrefabButton);
  70. gameObject.transform.SetParent(this.m_ScrollArea, false);
  71. gameObject.SetActive(true);
  72. data.ButtonPair = gameObject.GetComponent<Button>();
  73. this.m_ManualDataArray.Add(data);
  74. gameObject.GetComponentInChildren<Text>().text = data.ButtonName;
  75. gameObject.GetComponent<Button>().onClick.RemoveAllListeners();
  76. gameObject.GetComponent<Button>().onClick.AddListener(delegate
  77. {
  78. this.ChangeManualImage(data.ImageName);
  79. this.ButtonClickEvent(data);
  80. });
  81. if (k == 0)
  82. {
  83. gameObject.GetComponent<Button>().onClick.Invoke();
  84. }
  85. }
  86. }
  87. }
  88. private void ButtonClickEvent(VRManualMenu.ManualData data)
  89. {
  90. Debug.Log(data.ButtonName);
  91. VRManualMenu.ManualData beforeButton = this.GetBeforePageID(data.BeforeID);
  92. this.m_LeftButton.onClick.RemoveAllListeners();
  93. this.m_LeftButton.interactable = false;
  94. if (beforeButton != null)
  95. {
  96. this.m_LeftButton.interactable = true;
  97. this.m_LeftButton.onClick.AddListener(delegate
  98. {
  99. this.ChangeManualImage(beforeButton.ImageName);
  100. this.ButtonClickEvent(beforeButton);
  101. });
  102. }
  103. VRManualMenu.ManualData nextButton = this.GetNextPageID(data.ID);
  104. this.m_RightButton.onClick.RemoveAllListeners();
  105. this.m_RightButton.interactable = false;
  106. if (nextButton != null)
  107. {
  108. this.m_RightButton.interactable = true;
  109. this.m_RightButton.onClick.AddListener(delegate
  110. {
  111. this.ChangeManualImage(nextButton.ImageName);
  112. this.ButtonClickEvent(nextButton);
  113. });
  114. }
  115. }
  116. private VRManualMenu.ManualData GetBeforePageID(int beforePageID)
  117. {
  118. if (beforePageID == -1)
  119. {
  120. return null;
  121. }
  122. for (int i = 0; i < this.m_ManualDataArray.Count; i++)
  123. {
  124. VRManualMenu.ManualData manualData = this.m_ManualDataArray[i];
  125. if (manualData.ID == beforePageID)
  126. {
  127. return manualData;
  128. }
  129. }
  130. return null;
  131. }
  132. private VRManualMenu.ManualData GetNextPageID(int pageID)
  133. {
  134. if (pageID == -1)
  135. {
  136. return null;
  137. }
  138. for (int i = 0; i < this.m_ManualDataArray.Count; i++)
  139. {
  140. VRManualMenu.ManualData manualData = this.m_ManualDataArray[i];
  141. if (manualData.BeforeID == pageID)
  142. {
  143. return manualData;
  144. }
  145. }
  146. return null;
  147. }
  148. private void ChangeManualImage(string ImageName)
  149. {
  150. string path = this.m_uGUIAtlasPath + ImageName;
  151. base.StartCoroutine(this.Coroutine_Load<Sprite>(path, delegate(ResourceRequest req)
  152. {
  153. this.m_ImageManual.sprite = (req.asset as Sprite);
  154. }));
  155. }
  156. private IEnumerator Coroutine_Load<T>(string path, UnityAction<ResourceRequest> callback) where T : UnityEngine.Object
  157. {
  158. ResourceRequest res = Resources.LoadAsync<T>(path);
  159. while (!res.isDone)
  160. {
  161. yield return null;
  162. }
  163. callback(res);
  164. yield break;
  165. }
  166. [SerializeField]
  167. private Image m_ImageManual;
  168. [SerializeField]
  169. private Text m_TextPageNumber;
  170. [SerializeField]
  171. private Button m_LeftButton;
  172. [SerializeField]
  173. private Button m_RightButton;
  174. private string m_uGUIAtlasPath = "SceneVRCommunication\\Tablet\\Sprite\\";
  175. [SerializeField]
  176. [Tooltip("ボタンを並べるエリア")]
  177. private RectTransform m_ScrollArea;
  178. [SerializeField]
  179. [Tooltip("左に並ぶボタンのプレハブ")]
  180. private GameObject m_PrefabButton;
  181. private List<VRManualMenu.ManualData> m_ManualDataArray = new List<VRManualMenu.ManualData>();
  182. private class ManualData
  183. {
  184. public ManualData(int id, int beforeID, string imageName, string buttonName, Button button)
  185. {
  186. this.ID = id;
  187. this.BeforeID = beforeID;
  188. this.ImageName = imageName;
  189. this.ButtonName = buttonName;
  190. this.ButtonPair = button;
  191. }
  192. public int ID;
  193. public int BeforeID;
  194. public string ImageName;
  195. public string ButtonName;
  196. public Button ButtonPair;
  197. }
  198. }