VRMiniGameManager.cs 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5. using UnityEngine.Events;
  6. using UnityEngine.EventSystems;
  7. public class VRMiniGameManager : MonoBehaviour
  8. {
  9. public static VRMiniGameManager Instance
  10. {
  11. get
  12. {
  13. if (VRMiniGameManager.m_Instance == null)
  14. {
  15. VRMiniGameManager.m_Instance = UnityEngine.Object.FindObjectOfType<VRMiniGameManager>();
  16. }
  17. return VRMiniGameManager.m_Instance;
  18. }
  19. }
  20. public VRMiniGameScoreBoard ScoreBoard
  21. {
  22. get
  23. {
  24. return this.m_MiniGameScoreBoard;
  25. }
  26. }
  27. public int score
  28. {
  29. get
  30. {
  31. return this.m_MiniGameScoreBoard.score;
  32. }
  33. set
  34. {
  35. this.m_MiniGameScoreBoard.score = value;
  36. }
  37. }
  38. public int life
  39. {
  40. get
  41. {
  42. return this.m_MiniGameScoreBoard.life;
  43. }
  44. set
  45. {
  46. this.m_MiniGameScoreBoard.life = value;
  47. }
  48. }
  49. public AVRControllerButtons VRController
  50. {
  51. get
  52. {
  53. return this.m_VRController;
  54. }
  55. set
  56. {
  57. this.m_VRController = value;
  58. }
  59. }
  60. public VRMiniGameManager.VRMiniGameState MiniGameState
  61. {
  62. get
  63. {
  64. return this.m_MiniGameState;
  65. }
  66. }
  67. private void Start()
  68. {
  69. VRMiniGameManager.m_Instance = this;
  70. }
  71. public void Init(VRMiniGameManager.VRMiniGameType type)
  72. {
  73. if (this.m_MiniGameState != VRMiniGameManager.VRMiniGameState.None)
  74. {
  75. return;
  76. }
  77. Maid maid = GameMain.Instance.CharacterMgr.GetMaid(0);
  78. this.callScriptFile = ((!(maid == null)) ? ScriptManager.ReplacePersonal(maid, this.callScriptFile) : this.callScriptFile);
  79. string str = this.callScriptFile;
  80. GameMain.Instance.ScriptMgr.LoadAdvScenarioScript(str + ".ks", string.Empty);
  81. Dictionary<string, string> tag_backup = GameMain.Instance.ScriptMgr.adv_kag.tag_backup;
  82. string scriptArgFileEnd;
  83. string scriptArgLabelEnd;
  84. if (tag_backup != null && tag_backup.TryGetValue("file", out scriptArgFileEnd) && tag_backup.TryGetValue("label", out scriptArgLabelEnd))
  85. {
  86. this.m_ScriptArgLabelEnd = scriptArgLabelEnd;
  87. this.m_ScriptArgFileEnd = scriptArgFileEnd;
  88. }
  89. GameMain.Instance.OvrMgr.OvrCamera.HandLimitMode = AVRControllerBehavior.LIMIT_MODE.HAND_ONLY;
  90. this.m_MiniGameType = type;
  91. GameMain.VRDeviceType vrdeviceTypeID = GameMain.Instance.VRDeviceTypeID;
  92. if (vrdeviceTypeID == GameMain.VRDeviceType.NON || vrdeviceTypeID == GameMain.VRDeviceType.RIFT || vrdeviceTypeID == GameMain.VRDeviceType.FOVE)
  93. {
  94. this.m_MiniGameState = VRMiniGameManager.VRMiniGameState.Playing;
  95. }
  96. else
  97. {
  98. this.m_MiniGameState = VRMiniGameManager.VRMiniGameState.Setup;
  99. }
  100. }
  101. public void CreateScoreBoard(Vector3 ScoreBoardPosition, Quaternion ScoreBoardRot)
  102. {
  103. this.m_MiniGameScoreBoard = VRMiniGameScoreBoard.Create(ScoreBoardPosition, ScoreBoardRot);
  104. this.m_MiniGameScoreBoard.transform.position = ScoreBoardPosition;
  105. this.m_MiniGameScoreBoard.transform.rotation = ScoreBoardRot;
  106. }
  107. public void StartRightLeftHand(Vector3 UIPos, Quaternion UIRot, UnityAction<AVRController> callback)
  108. {
  109. GameMain.VRDeviceType vrdeviceTypeID = GameMain.Instance.VRDeviceTypeID;
  110. if (vrdeviceTypeID != GameMain.VRDeviceType.RIFT_TOUCH && vrdeviceTypeID != GameMain.VRDeviceType.VIVE)
  111. {
  112. this.ClearQueueVoice();
  113. this.m_MiniGameState = VRMiniGameManager.VRMiniGameState.Playing;
  114. callback(null);
  115. return;
  116. }
  117. VRDecideMiniGameHand ui = VRDecideMiniGameHand.Create(UIPos, UIRot);
  118. callback = (UnityAction<AVRController>)Delegate.Combine(callback, new UnityAction<AVRController>(delegate(AVRController controller)
  119. {
  120. if (controller)
  121. {
  122. this.m_VRController = controller.VRControllerButtons;
  123. }
  124. ui.textCountDown.text = "Start!";
  125. GameMain.Instance.SoundMgr.PlaySe("SE_vr0032.ogg", false);
  126. this.ClearQueueVoice();
  127. this.m_MiniGameState = VRMiniGameManager.VRMiniGameState.Playing;
  128. UICanvasFade component = ui.GetComponent<UICanvasFade>();
  129. component.FadeOut(0.5f, false, delegate
  130. {
  131. UnityEngine.Object.Destroy(ui.gameObject);
  132. });
  133. }));
  134. ui.StartDecideHand(callback);
  135. }
  136. public void Result(UnityAction callback)
  137. {
  138. if (this.m_MiniGameState == VRMiniGameManager.VRMiniGameState.Result)
  139. {
  140. return;
  141. }
  142. this.m_MiniGameState = VRMiniGameManager.VRMiniGameState.Result;
  143. base.StartCoroutine(this.Coroutine_WaitVoice(delegate
  144. {
  145. this.ResultJudge(callback);
  146. }));
  147. }
  148. private void ResultJudge(UnityAction callback)
  149. {
  150. int num = 0;
  151. if (this.m_MiniGameType == VRMiniGameManager.VRMiniGameType.Wanage)
  152. {
  153. num = 1;
  154. }
  155. else if (this.m_MiniGameType == VRMiniGameManager.VRMiniGameType.Darts)
  156. {
  157. num = 2;
  158. }
  159. else if (this.m_MiniGameType == VRMiniGameManager.VRMiniGameType.Kamihikouki)
  160. {
  161. num = 3;
  162. }
  163. GameMain.Instance.OvrMgr.OvrCamera.ForceHideUI(false);
  164. GameMain.VRDeviceType vrdeviceTypeID = GameMain.Instance.VRDeviceTypeID;
  165. if (vrdeviceTypeID != GameMain.VRDeviceType.NON)
  166. {
  167. GameMain.Instance.OvrMgr.OvrCamera.UIPosReset(0f);
  168. }
  169. VRCanvasManager.Instance.OpenVRCanvas(VRCanvasManager.VRCanvasType.NONE);
  170. this.m_MiniGameScoreBoard.transform.SetParent(VRCanvasManager.Instance.CanvasParent.transform, false);
  171. this.m_MiniGameScoreBoard.transform.localPosition = Vector3.zero;
  172. this.m_MiniGameScoreBoard.transform.localScale = Vector3.one * 0.001f;
  173. this.m_MiniGameScoreBoard.transform.localRotation = Quaternion.identity;
  174. this.m_MiniGameScoreBoard.GetComponent<CanvasGroup>().interactable = true;
  175. Camera componentInChildren = EventSystem.current.gameObject.GetComponentInChildren<Camera>();
  176. this.m_MiniGameScoreBoard.GetComponent<Canvas>().worldCamera = componentInChildren;
  177. List<VRMiniGameManager.MiniGameResultData> list = new List<VRMiniGameManager.MiniGameResultData>();
  178. string text = "vrcom_mini_game.nei";
  179. if (!GameUty.FileSystem.IsExistentFile(text))
  180. {
  181. NDebug.Assert("表がありません。" + text, false);
  182. }
  183. using (AFileBase afileBase = GameUty.FileSystem.FileOpen(text))
  184. {
  185. using (CsvParser csvParser = new CsvParser())
  186. {
  187. bool condition = csvParser.Open(afileBase);
  188. NDebug.Assert(condition, text + "\nopen failed.");
  189. for (int i = 1; i < csvParser.max_cell_y; i++)
  190. {
  191. if (csvParser.IsCellToExistData(0, i))
  192. {
  193. int num2 = 0;
  194. int cellAsInteger = csvParser.GetCellAsInteger(num2++, i);
  195. if (cellAsInteger == num)
  196. {
  197. int cellAsInteger2 = csvParser.GetCellAsInteger(num2++, i);
  198. int cellAsInteger3 = csvParser.GetCellAsInteger(num2++, i);
  199. string cellAsString = csvParser.GetCellAsString(num2++, i);
  200. string cellAsString2 = csvParser.GetCellAsString(num2++, i);
  201. string cellAsString3 = csvParser.GetCellAsString(num2++, i);
  202. list.Add(new VRMiniGameManager.MiniGameResultData(cellAsInteger2, cellAsInteger3, cellAsString, cellAsString3, cellAsInteger3 <= this.score, cellAsString2));
  203. }
  204. }
  205. }
  206. }
  207. }
  208. string message = string.Empty;
  209. bool flag = false;
  210. for (int j = 0; j < list.Count; j++)
  211. {
  212. if (list[j].IsGet)
  213. {
  214. flag = true;
  215. break;
  216. }
  217. }
  218. bool flag2 = false;
  219. if (this.m_MiniGameType == VRMiniGameManager.VRMiniGameType.Wanage)
  220. {
  221. flag2 = (this.score == 10);
  222. }
  223. else if (this.m_MiniGameType == VRMiniGameManager.VRMiniGameType.Darts)
  224. {
  225. flag2 = (this.score == 600);
  226. }
  227. else if (this.m_MiniGameType == VRMiniGameManager.VRMiniGameType.Kamihikouki)
  228. {
  229. flag2 = (this.score == 550);
  230. }
  231. List<VRMiniGameManager.MiniGameResultData> list2 = new List<VRMiniGameManager.MiniGameResultData>();
  232. for (int k = 0; k < list.Count; k++)
  233. {
  234. VRMiniGameManager.MiniGameResultData miniGameResultData = list[k];
  235. if (miniGameResultData.IsGet)
  236. {
  237. if (!string.IsNullOrEmpty(miniGameResultData.FileName))
  238. {
  239. bool flag3 = false;
  240. string[] array = miniGameResultData.FileName.Split(new char[]
  241. {
  242. ','
  243. });
  244. for (int l = 0; l < array.Length; l++)
  245. {
  246. if (GameMain.Instance.CharacterMgr.status.IsHavePartsItem(array[l] + ".menu"))
  247. {
  248. Debug.Log("[ミニゲーム\u3000リザルト]" + array[l] + "は既に持っている");
  249. flag3 = true;
  250. }
  251. }
  252. if (!flag3)
  253. {
  254. list2.Add(miniGameResultData);
  255. }
  256. }
  257. }
  258. }
  259. VRMiniGameManager.VoiceType voiceType = VRMiniGameManager.VoiceType.Result4;
  260. if (!flag)
  261. {
  262. voiceType = VRMiniGameManager.VoiceType.Result4;
  263. message = "何も獲得できませんでした……";
  264. }
  265. else if (list2.Count > 0)
  266. {
  267. voiceType = VRMiniGameManager.VoiceType.Result2;
  268. if (list2.Count == 1)
  269. {
  270. message = "衣装「" + list2[0].ItemName + "」をゲットしました!";
  271. }
  272. else
  273. {
  274. message = list2.Count.ToString() + "つの衣装をゲットしました!";
  275. }
  276. GameMain.Instance.SoundMgr.PlaySe("SE_vr0033.ogg", false);
  277. }
  278. else if (!flag2)
  279. {
  280. voiceType = VRMiniGameManager.VoiceType.Result3;
  281. message = "今回の点数は" + this.score.ToString() + "点でした。";
  282. GameMain.Instance.SoundMgr.PlaySe("SE_vr0032.ogg", false);
  283. }
  284. else
  285. {
  286. voiceType = VRMiniGameManager.VoiceType.Result1;
  287. message = "最高点数!今回の点数は" + this.score + "点でした!";
  288. GameMain.Instance.SoundMgr.PlaySe("SE_vr0034.ogg", false);
  289. }
  290. for (int m = 0; m < list2.Count; m++)
  291. {
  292. VRMiniGameManager.MiniGameResultData miniGameResultData2 = list2[m];
  293. if (!string.IsNullOrEmpty(miniGameResultData2.FileName))
  294. {
  295. string[] array2 = miniGameResultData2.FileName.Split(new char[]
  296. {
  297. ','
  298. });
  299. for (int n = 0; n < array2.Length; n++)
  300. {
  301. GameMain.Instance.CharacterMgr.status.AddHavePartsItem(array2[n] + ".menu");
  302. }
  303. }
  304. }
  305. if (flag)
  306. {
  307. for (int num3 = 0; num3 < list.Count; num3++)
  308. {
  309. if (list[num3].ItemScore <= this.score)
  310. {
  311. if (!string.IsNullOrEmpty(list[num3].ItemFlag))
  312. {
  313. GameMain.Instance.CharacterMgr.status.SetFlag(list[num3].ItemFlag, 1);
  314. }
  315. }
  316. }
  317. }
  318. callback = (UnityAction)Delegate.Combine(callback, new UnityAction(delegate
  319. {
  320. this.AddQueueVoice(voiceType);
  321. this.FinishMiniGame();
  322. }));
  323. this.m_MiniGameScoreBoard.Result(message, callback);
  324. }
  325. public void FinishMiniGame()
  326. {
  327. GameMain.Instance.OvrMgr.OvrCamera.HandLimitMode = AVRControllerBehavior.LIMIT_MODE.NORMAL;
  328. UnityEngine.Object.Destroy(this.m_MiniGameScoreBoard.gameObject);
  329. GameMain.Instance.OvrMgr.OvrCamera.ShowUI(false);
  330. VRCanvasManager.Instance.OpenVRCanvas(VRCanvasManager.VRCanvasType.MainMenu);
  331. this.m_MiniGameState = VRMiniGameManager.VRMiniGameState.None;
  332. base.StartCoroutine(this.Coroutine_WaitVoice(delegate
  333. {
  334. if (!string.IsNullOrEmpty(this.m_ScriptArgFileEnd) && !string.IsNullOrEmpty(this.m_ScriptArgLabelEnd))
  335. {
  336. Debug.Log("OnEndScene JumpTo " + this.m_ScriptArgLabelEnd);
  337. GameMain.Instance.ScriptMgr.LoadAdvScenarioScript(this.m_ScriptArgFileEnd + ".ks", string.Empty);
  338. GameMain.Instance.ScriptMgr.adv_kag.JumpLabel(this.m_ScriptArgLabelEnd);
  339. GameMain.Instance.ScriptMgr.adv_kag.Exec();
  340. }
  341. }));
  342. }
  343. private IEnumerator Coroutine_WaitVoice(UnityAction callback)
  344. {
  345. while (GameMain.Instance.SoundMgr.isVoicePlaying())
  346. {
  347. yield return null;
  348. }
  349. yield return new WaitForSeconds(0.75f);
  350. callback();
  351. yield break;
  352. }
  353. private void Update()
  354. {
  355. if (0 < this.voiceQueueList.Count && !GameMain.Instance.SoundMgr.isVoicePlaying())
  356. {
  357. string label_name = this.voiceQueueList[0];
  358. this.voiceQueueList.RemoveAt(0);
  359. GameMain.Instance.ScriptMgr.LoadAdvScenarioScript(this.callScriptFile + ".ks", label_name);
  360. GameMain.Instance.ScriptMgr.adv_kag.Exec();
  361. this.voicePlayTime = Time.time;
  362. }
  363. if (this.voiceQueueList.Count == 0 && !GameMain.Instance.SoundMgr.isVoicePlaying() && this.voicePlayTime + this.voiceWaitTime <= Time.time && this.m_MiniGameState == VRMiniGameManager.VRMiniGameState.Playing)
  364. {
  365. this.AddQueueVoice(VRMiniGameManager.VoiceType.Wait);
  366. this.voicePlayTime = Time.time + UnityEngine.Random.Range(0f, this.voiceWaitTime / 2f);
  367. }
  368. }
  369. public void AddQueueVoice(VRMiniGameManager.VoiceType type)
  370. {
  371. Debug.Log("[ ミニゲームマネージャ ]ボイス:" + type);
  372. string text = string.Empty;
  373. switch (type)
  374. {
  375. case VRMiniGameManager.VoiceType.Wait:
  376. text = "*game_random";
  377. break;
  378. case VRMiniGameManager.VoiceType.Hit:
  379. text = "*good_random";
  380. break;
  381. case VRMiniGameManager.VoiceType.Miss:
  382. text = "*bad_random";
  383. break;
  384. case VRMiniGameManager.VoiceType.Result1:
  385. text = "*result_1";
  386. break;
  387. case VRMiniGameManager.VoiceType.Result2:
  388. text = "*result_2";
  389. break;
  390. case VRMiniGameManager.VoiceType.Result3:
  391. text = "*result_3";
  392. break;
  393. case VRMiniGameManager.VoiceType.Result4:
  394. text = "*result_4";
  395. break;
  396. default:
  397. switch (type)
  398. {
  399. case VRMiniGameManager.VoiceType.StartKamihikouki:
  400. text = "*kamihikouki_start";
  401. break;
  402. case VRMiniGameManager.VoiceType.StartDarts:
  403. text = "*darts_start";
  404. break;
  405. case VRMiniGameManager.VoiceType.StartWanage:
  406. text = "*wanage_start";
  407. break;
  408. }
  409. break;
  410. }
  411. if (VRMiniGameManager.VoiceType.Remaining0 <= type && type <= VRMiniGameManager.VoiceType.Remaining10)
  412. {
  413. text = "*remaining_" + ((int)(VRMiniGameManager.VoiceType.Remaining7 - (VRMiniGameManager.VoiceType.Remaining10 - type))).ToString();
  414. }
  415. else
  416. {
  417. this.StopVoice();
  418. this.ClearQueueVoice();
  419. }
  420. if (string.IsNullOrEmpty(text))
  421. {
  422. Debug.LogError("ミニゲームにてAddQueueVoice関数が呼ばれましたが、タグの指定が不明です");
  423. return;
  424. }
  425. if (!GameMain.Instance.SoundMgr.isVoicePlaying() && this.voiceQueueList.Count == 0)
  426. {
  427. GameMain.Instance.ScriptMgr.LoadAdvScenarioScript(this.callScriptFile + ".ks", text);
  428. GameMain.Instance.ScriptMgr.adv_kag.Exec();
  429. }
  430. else
  431. {
  432. this.voiceQueueList.Add(text);
  433. }
  434. }
  435. private void ClearQueueVoice()
  436. {
  437. this.voiceQueueList.Clear();
  438. }
  439. private void StopVoice()
  440. {
  441. GameMain.Instance.SoundMgr.VoiceStopAll();
  442. }
  443. private static VRMiniGameManager m_Instance;
  444. private VRMiniGameScoreBoard m_MiniGameScoreBoard;
  445. private AVRControllerButtons m_VRController;
  446. private VRMiniGameManager.VRMiniGameType m_MiniGameType;
  447. private VRMiniGameManager.VRMiniGameState m_MiniGameState;
  448. private string m_ScriptArgLabelEnd = string.Empty;
  449. private string m_ScriptArgFileEnd = string.Empty;
  450. [SerializeField]
  451. [Tooltip("メイドスクリプトファイル")]
  452. private string callScriptFile = "001_?_minigame";
  453. private List<string> voiceQueueList = new List<string>();
  454. private float voicePlayTime;
  455. private float voiceWaitTime = 10f;
  456. public enum VRMiniGameType
  457. {
  458. Wanage,
  459. Darts,
  460. Kamihikouki
  461. }
  462. public enum VRMiniGameState
  463. {
  464. None,
  465. Setup,
  466. Playing,
  467. Result
  468. }
  469. private class MiniGameResultData
  470. {
  471. public MiniGameResultData(int itemID, int itemScore, string fileName, string itemFlag, bool isGet, string itemName)
  472. {
  473. this.ItemID = itemID;
  474. this.ItemScore = itemScore;
  475. this.FileName = fileName;
  476. this.ItemFlag = itemFlag;
  477. this.IsGet = isGet;
  478. this.ItemName = itemName;
  479. }
  480. public int ItemID;
  481. public int ItemScore;
  482. public string FileName;
  483. public string ItemFlag;
  484. public bool IsGet;
  485. public string ItemName;
  486. }
  487. public enum VoiceType
  488. {
  489. StartKamihikouki,
  490. StartDarts,
  491. StartWanage,
  492. Remaining0,
  493. Remaining1,
  494. Remaining2,
  495. Remaining3,
  496. Remaining4,
  497. Remaining5,
  498. Remaining6,
  499. Remaining7,
  500. Remaining8,
  501. Remaining9,
  502. Remaining10,
  503. Wait,
  504. Hit,
  505. Miss,
  506. Result1,
  507. Result2,
  508. Result3,
  509. Result4
  510. }
  511. }