VRVIPMenu.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using MaidStatus;
  5. using UnityEngine;
  6. using UnityEngine.Events;
  7. using UnityEngine.UI;
  8. public class VRVIPMenu : MonoBehaviour
  9. {
  10. private void Update()
  11. {
  12. for (int i = 0; i < this.m_VIPElementDataArray.Count; i++)
  13. {
  14. VRVIPMenu.ElementData elementData = this.m_VIPElementDataArray[i];
  15. if (elementData.isEnable)
  16. {
  17. MaskableGraphic[] componentsInChildren = elementData.Element.GetComponentsInChildren<MaskableGraphic>();
  18. Color color = Color.white;
  19. if (elementData.isPointerDown)
  20. {
  21. color *= 0.78f;
  22. color.a = 1f;
  23. for (int j = 0; j < componentsInChildren.Length; j++)
  24. {
  25. componentsInChildren[j].CrossFadeColor(color, 0.1f, false, true);
  26. }
  27. return;
  28. }
  29. if (elementData.isPointerStay)
  30. {
  31. for (int k = 0; k < componentsInChildren.Length; k++)
  32. {
  33. componentsInChildren[k].CrossFadeColor(color, 0.1f, false, true);
  34. }
  35. }
  36. else
  37. {
  38. color *= 0.75f;
  39. color.a = 1f;
  40. for (int l = 0; l < componentsInChildren.Length; l++)
  41. {
  42. componentsInChildren[l].CrossFadeColor(color, 0.1f, false, true);
  43. }
  44. }
  45. }
  46. }
  47. }
  48. private void UpdateVIPUI()
  49. {
  50. this.m_PrefabElement.SetActive(false);
  51. string text = "vrcom_vip.nei";
  52. if (!GameUty.FileSystem.IsExistentFile(text))
  53. {
  54. NDebug.Assert("表がありません。" + text, false);
  55. }
  56. using (AFileBase afileBase = GameUty.FileSystem.FileOpen(text))
  57. {
  58. using (CsvParser csvParser = new CsvParser())
  59. {
  60. bool condition = csvParser.Open(afileBase);
  61. NDebug.Assert(condition, text + "\nopen failed.");
  62. for (int i = 1; i < csvParser.max_cell_y; i++)
  63. {
  64. if (csvParser.IsCellToExistData(0, i))
  65. {
  66. int num = 0;
  67. int cellAsInteger = csvParser.GetCellAsInteger(num++, i);
  68. string cellAsString = csvParser.GetCellAsString(num++, i);
  69. string cellAsString2 = csvParser.GetCellAsString(num++, i);
  70. string cellAsString3 = csvParser.GetCellAsString(num++, i);
  71. string cellAsString4 = csvParser.GetCellAsString(num++, i);
  72. string cellAsString5 = csvParser.GetCellAsString(num++, i);
  73. string cellAsString6 = csvParser.GetCellAsString(num++, i);
  74. string cellAsString7 = csvParser.GetCellAsString(num++, i);
  75. string cellAsString8 = csvParser.GetCellAsString(num++, i);
  76. string cellAsString9 = csvParser.GetCellAsString(num++, i);
  77. string scriptName = csvParser.GetCellAsString(num++, i);
  78. string cellAsString10 = csvParser.GetCellAsString(num++, i);
  79. string cellAsString11 = csvParser.GetCellAsString(num++, i);
  80. string cellAsString12 = csvParser.GetCellAsString(num++, i);
  81. string cellAsString13 = csvParser.GetCellAsString(num++, i);
  82. string cellAsString14 = csvParser.GetCellAsString(num++, i);
  83. if (string.IsNullOrEmpty(cellAsString10) || GameMain.Instance.CharacterMgr.status.GetFlag(cellAsString10) > 0)
  84. {
  85. VRVIPMenu.ElementData data = this.CreateElement();
  86. data.TextName.text = cellAsString;
  87. data.TextFlag1.text = cellAsString3;
  88. data.TextFlag2.text = cellAsString4;
  89. data.TextFlag3.text = cellAsString5;
  90. data.TextFlag4.text = cellAsString6;
  91. data.TextHowToVIP.text = cellAsString9;
  92. data.TextFlag1.gameObject.SetActive(!string.IsNullOrEmpty(cellAsString3));
  93. data.TextFlag2.gameObject.SetActive(!string.IsNullOrEmpty(cellAsString4));
  94. data.TextFlag3.gameObject.SetActive(!string.IsNullOrEmpty(cellAsString5));
  95. data.TextFlag4.gameObject.SetActive(!string.IsNullOrEmpty(cellAsString6));
  96. Maid maid = GameMain.Instance.CharacterMgr.GetMaid(0);
  97. bool flag = true;
  98. if (maid)
  99. {
  100. if (!string.IsNullOrEmpty(cellAsString7))
  101. {
  102. flag &= (GameMain.Instance.CharacterMgr.status.GetFlag(cellAsString7) > 0);
  103. }
  104. if (!string.IsNullOrEmpty(cellAsString8))
  105. {
  106. flag &= (maid.status.GetFlag(cellAsString8) > 0);
  107. }
  108. if (cellAsString11.Equals("×"))
  109. {
  110. flag &= (maid.status.seikeiken != Seikeiken.No_No);
  111. }
  112. if (cellAsString12.Equals("×"))
  113. {
  114. flag &= (maid.status.seikeiken != Seikeiken.Yes_No);
  115. }
  116. if (cellAsString13.Equals("×"))
  117. {
  118. flag &= (maid.status.seikeiken != Seikeiken.No_Yes);
  119. }
  120. if (cellAsString14.Equals("×"))
  121. {
  122. flag &= (maid.status.seikeiken != Seikeiken.Yes_Yes);
  123. }
  124. }
  125. else
  126. {
  127. flag = false;
  128. }
  129. data.isEnable = flag;
  130. if (flag)
  131. {
  132. VRVIPMenuElement component = data.Element.GetComponent<VRVIPMenuElement>();
  133. VRVIPMenuElement vrvipmenuElement = component;
  134. vrvipmenuElement.m_CallbackPointerClick = (UnityAction)Delegate.Combine(vrvipmenuElement.m_CallbackPointerClick, new UnityAction(delegate
  135. {
  136. this.EventElementClick(data, scriptName);
  137. GameMain.Instance.SoundMgr.PlaySystem(SoundMgr.SeType.Click);
  138. }));
  139. VRVIPMenuElement vrvipmenuElement2 = component;
  140. vrvipmenuElement2.m_CallbackPointerDown = (UnityAction)Delegate.Combine(vrvipmenuElement2.m_CallbackPointerDown, new UnityAction(delegate
  141. {
  142. data.isPointerDown = true;
  143. }));
  144. VRVIPMenuElement vrvipmenuElement3 = component;
  145. vrvipmenuElement3.m_CallbackPointerUp = (UnityAction)Delegate.Combine(vrvipmenuElement3.m_CallbackPointerUp, new UnityAction(delegate
  146. {
  147. data.isPointerDown = false;
  148. }));
  149. VRVIPMenuElement vrvipmenuElement4 = component;
  150. vrvipmenuElement4.m_CallbackPointerEnter = (UnityAction)Delegate.Combine(vrvipmenuElement4.m_CallbackPointerEnter, new UnityAction(delegate
  151. {
  152. data.isPointerStay = true;
  153. GameMain.Instance.SoundMgr.PlaySystem(SoundMgr.SeType.Hover);
  154. }));
  155. VRVIPMenuElement vrvipmenuElement5 = component;
  156. vrvipmenuElement5.m_CallbackPointerExit = (UnityAction)Delegate.Combine(vrvipmenuElement5.m_CallbackPointerExit, new UnityAction(delegate
  157. {
  158. data.isPointerStay = false;
  159. data.isPointerDown = false;
  160. }));
  161. }
  162. else
  163. {
  164. MaskableGraphic[] componentsInChildren = data.Element.GetComponentsInChildren<MaskableGraphic>();
  165. Color color = Color.white;
  166. color *= 0.66f;
  167. color.a = 0.75f;
  168. for (int j = 0; j < componentsInChildren.Length; j++)
  169. {
  170. componentsInChildren[j].CrossFadeColor(color, 0f, false, true);
  171. }
  172. }
  173. string path = this.m_uGUIAtlasPath + cellAsString2;
  174. base.StartCoroutine(this.Coroutine_Load<Sprite>(path, delegate(ResourceRequest req)
  175. {
  176. data.ImageThumbnail.sprite = (req.asset as Sprite);
  177. }));
  178. this.m_VIPElementDataArray.Add(data);
  179. }
  180. }
  181. }
  182. }
  183. }
  184. }
  185. private VRVIPMenu.ElementData CreateElement()
  186. {
  187. GameObject gameObject = UnityEngine.Object.Instantiate<GameObject>(this.m_PrefabElement);
  188. gameObject.SetActive(true);
  189. gameObject.transform.SetParent(this.m_Content, false);
  190. return new VRVIPMenu.ElementData
  191. {
  192. Element = gameObject.GetComponent<RectTransform>(),
  193. TextName = gameObject.transform.Find("Text VIP Name").GetComponent<Text>(),
  194. ImageThumbnail = gameObject.transform.Find("Image VIP thumnail").GetComponent<Image>(),
  195. TextFlag1 = gameObject.transform.Find("Text VIP Flag 1").GetComponent<Text>(),
  196. TextFlag2 = gameObject.transform.Find("Text VIP Flag 2").GetComponent<Text>(),
  197. TextFlag3 = gameObject.transform.Find("Text VIP Flag 3").GetComponent<Text>(),
  198. TextFlag4 = gameObject.transform.Find("Text VIP Flag 4").GetComponent<Text>(),
  199. TextHowToVIP = gameObject.transform.Find("Text VIP Comment").GetComponent<Text>()
  200. };
  201. }
  202. private void EventElementClick(VRVIPMenu.ElementData element, string scriptName)
  203. {
  204. Debug.Log("項目がクリックされた。\n" + element.Element.name);
  205. VRDialogMenu dialog = VRDialogMenu.CreateDialog();
  206. VRDialogMenu.TYPE_STYLE style = (VRDialogMenu.TYPE_STYLE)12;
  207. dialog.OpenDialog("「" + element.TextName.text + "」を\n行います。", style, delegate(VRDialogMenu.TYPE_STYLE type)
  208. {
  209. dialog.CloseDialog();
  210. if (type == VRDialogMenu.TYPE_STYLE.OK)
  211. {
  212. VRCanvasManager.Instance.ClearCanvasStack();
  213. VRCanvasManager.Instance.OpenVRCanvas(VRCanvasManager.VRCanvasType.MainMenu);
  214. GameMain.Instance.ScriptMgr.LoadAdvScenarioScript(scriptName + ".ks", string.Empty);
  215. GameMain.Instance.ScriptMgr.adv_kag.Exec();
  216. }
  217. else
  218. {
  219. VRCanvasManager.Instance.ClearCanvasStack();
  220. VRCanvasManager.Instance.OpenVRCanvas(VRCanvasManager.VRCanvasType.VIP);
  221. }
  222. });
  223. }
  224. private void OnEnable()
  225. {
  226. this.UpdateVIPUI();
  227. }
  228. private void OnDisable()
  229. {
  230. if (base.gameObject == null)
  231. {
  232. return;
  233. }
  234. if (this.m_Content == null)
  235. {
  236. return;
  237. }
  238. if (this.m_PrefabElement == null)
  239. {
  240. return;
  241. }
  242. this.m_VIPElementDataArray.Clear();
  243. for (int i = 0; i < this.m_Content.childCount; i++)
  244. {
  245. GameObject gameObject = this.m_Content.GetChild(i).gameObject;
  246. if (!(gameObject == this.m_PrefabElement))
  247. {
  248. UnityEngine.Object.Destroy(gameObject);
  249. }
  250. }
  251. }
  252. public void ButtonEvent_Close()
  253. {
  254. SceneVRCommunication sceneVRCom = SceneVRCommunication.Instance;
  255. if (sceneVRCom == null)
  256. {
  257. return;
  258. }
  259. VRSelectorMenu selector = VRSelectorMenu.CreateSelector();
  260. selector.SetSelectType(VRChoices.SelectPair.Type.Text);
  261. List<VRChoices.SelectPair> list = new List<VRChoices.SelectPair>();
  262. list.Add(new VRChoices.SelectPair("VIPを続ける", "0", 0, VRChoices.SelectPair.Type.Text, 0, -1f));
  263. list.Add(new VRChoices.SelectPair("翌日ヘ進む", "1", 0, VRChoices.SelectPair.Type.Text, 0, -1f));
  264. selector.SelectStart(list, delegate(VRChoices.SelectPair choice)
  265. {
  266. selector.SelectFinalize(null);
  267. if (choice.strLabel == "0")
  268. {
  269. VRCanvasManager.Instance.OpenVRCanvas(VRCanvasManager.VRCanvasType.VIP);
  270. }
  271. else
  272. {
  273. VRCanvasManager.Instance.OpenVRCanvas(VRCanvasManager.VRCanvasType.MainMenu);
  274. sceneVRCom.KagDoNextTime();
  275. }
  276. });
  277. }
  278. private IEnumerator Coroutine_Load<T>(string path, UnityAction<ResourceRequest> callback) where T : UnityEngine.Object
  279. {
  280. ResourceRequest res = Resources.LoadAsync<T>(path);
  281. while (!res.isDone)
  282. {
  283. yield return null;
  284. }
  285. callback(res);
  286. yield break;
  287. }
  288. [SerializeField]
  289. [Tooltip("VIPの概要を表示する要素(プレハブ)")]
  290. private GameObject m_PrefabElement;
  291. [SerializeField]
  292. [Tooltip("説明する要素を並べるUI")]
  293. private RectTransform m_Content;
  294. private string m_uGUIAtlasPath = "SceneVRCommunication\\Tablet\\Sprite\\";
  295. private List<VRVIPMenu.ElementData> m_VIPElementDataArray = new List<VRVIPMenu.ElementData>();
  296. private class ElementData
  297. {
  298. public ElementData()
  299. {
  300. this.Element = null;
  301. this.TextName = null;
  302. this.ImageThumbnail = null;
  303. this.TextFlag1 = null;
  304. this.TextFlag2 = null;
  305. this.TextFlag3 = null;
  306. this.TextFlag4 = null;
  307. this.TextHowToVIP = null;
  308. this.isPointerStay = false;
  309. this.isPointerDown = false;
  310. this.isEnable = false;
  311. }
  312. public RectTransform Element;
  313. public Text TextName;
  314. public Image ImageThumbnail;
  315. public Text TextFlag1;
  316. public Text TextFlag2;
  317. public Text TextFlag3;
  318. public Text TextFlag4;
  319. public Text TextHowToVIP;
  320. public bool isPointerStay;
  321. public bool isPointerDown;
  322. public bool isEnable;
  323. }
  324. }