123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550 |
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.Events;
- using UnityEngine.EventSystems;
- public class VRMiniGameManager : MonoBehaviour
- {
- public static VRMiniGameManager Instance
- {
- get
- {
- if (VRMiniGameManager.m_Instance == null)
- {
- VRMiniGameManager.m_Instance = UnityEngine.Object.FindObjectOfType<VRMiniGameManager>();
- }
- return VRMiniGameManager.m_Instance;
- }
- }
- public VRMiniGameScoreBoard ScoreBoard
- {
- get
- {
- return this.m_MiniGameScoreBoard;
- }
- }
- public int score
- {
- get
- {
- return this.m_MiniGameScoreBoard.score;
- }
- set
- {
- this.m_MiniGameScoreBoard.score = value;
- }
- }
- public int life
- {
- get
- {
- return this.m_MiniGameScoreBoard.life;
- }
- set
- {
- this.m_MiniGameScoreBoard.life = value;
- }
- }
- public AVRControllerButtons VRController
- {
- get
- {
- return this.m_VRController;
- }
- set
- {
- this.m_VRController = value;
- }
- }
- public VRMiniGameManager.VRMiniGameState MiniGameState
- {
- get
- {
- return this.m_MiniGameState;
- }
- }
- private void Start()
- {
- VRMiniGameManager.m_Instance = this;
- }
- public void Init(VRMiniGameManager.VRMiniGameType type)
- {
- if (this.m_MiniGameState != VRMiniGameManager.VRMiniGameState.None)
- {
- return;
- }
- Maid maid = GameMain.Instance.CharacterMgr.GetMaid(0);
- this.callScriptFile = ((!(maid == null)) ? ScriptManager.ReplacePersonal(maid, this.callScriptFile) : this.callScriptFile);
- string str = this.callScriptFile;
- GameMain.Instance.ScriptMgr.LoadAdvScenarioScript(str + ".ks", string.Empty);
- Dictionary<string, string> tag_backup = GameMain.Instance.ScriptMgr.adv_kag.tag_backup;
- string scriptArgFileEnd;
- string scriptArgLabelEnd;
- if (tag_backup != null && tag_backup.TryGetValue("file", out scriptArgFileEnd) && tag_backup.TryGetValue("label", out scriptArgLabelEnd))
- {
- this.m_ScriptArgLabelEnd = scriptArgLabelEnd;
- this.m_ScriptArgFileEnd = scriptArgFileEnd;
- }
- GameMain.Instance.OvrMgr.OvrCamera.HandLimitMode = AVRControllerBehavior.LIMIT_MODE.HAND_ONLY;
- this.m_MiniGameType = type;
- GameMain.VRDeviceType vrdeviceTypeID = GameMain.Instance.VRDeviceTypeID;
- if (vrdeviceTypeID == GameMain.VRDeviceType.NON || vrdeviceTypeID == GameMain.VRDeviceType.RIFT || vrdeviceTypeID == GameMain.VRDeviceType.FOVE)
- {
- this.m_MiniGameState = VRMiniGameManager.VRMiniGameState.Playing;
- }
- else
- {
- this.m_MiniGameState = VRMiniGameManager.VRMiniGameState.Setup;
- }
- }
- public void CreateScoreBoard(Vector3 ScoreBoardPosition, Quaternion ScoreBoardRot)
- {
- this.m_MiniGameScoreBoard = VRMiniGameScoreBoard.Create(ScoreBoardPosition, ScoreBoardRot);
- this.m_MiniGameScoreBoard.transform.position = ScoreBoardPosition;
- this.m_MiniGameScoreBoard.transform.rotation = ScoreBoardRot;
- }
- public void StartRightLeftHand(Vector3 UIPos, Quaternion UIRot, UnityAction<AVRController> callback)
- {
- GameMain.VRDeviceType vrdeviceTypeID = GameMain.Instance.VRDeviceTypeID;
- if (vrdeviceTypeID != GameMain.VRDeviceType.RIFT_TOUCH && vrdeviceTypeID != GameMain.VRDeviceType.VIVE)
- {
- this.ClearQueueVoice();
- this.m_MiniGameState = VRMiniGameManager.VRMiniGameState.Playing;
- callback(null);
- return;
- }
- VRDecideMiniGameHand ui = VRDecideMiniGameHand.Create(UIPos, UIRot);
- callback = (UnityAction<AVRController>)Delegate.Combine(callback, new UnityAction<AVRController>(delegate(AVRController controller)
- {
- if (controller)
- {
- this.m_VRController = controller.VRControllerButtons;
- }
- ui.textCountDown.text = "Start!";
- GameMain.Instance.SoundMgr.PlaySe("SE_vr0032.ogg", false);
- this.ClearQueueVoice();
- this.m_MiniGameState = VRMiniGameManager.VRMiniGameState.Playing;
- UICanvasFade component = ui.GetComponent<UICanvasFade>();
- component.FadeOut(0.5f, false, delegate
- {
- UnityEngine.Object.Destroy(ui.gameObject);
- });
- }));
- ui.StartDecideHand(callback);
- }
- public void Result(UnityAction callback)
- {
- if (this.m_MiniGameState == VRMiniGameManager.VRMiniGameState.Result)
- {
- return;
- }
- this.m_MiniGameState = VRMiniGameManager.VRMiniGameState.Result;
- base.StartCoroutine(this.Coroutine_WaitVoice(delegate
- {
- this.ResultJudge(callback);
- }));
- }
- private void ResultJudge(UnityAction callback)
- {
- int num = 0;
- if (this.m_MiniGameType == VRMiniGameManager.VRMiniGameType.Wanage)
- {
- num = 1;
- }
- else if (this.m_MiniGameType == VRMiniGameManager.VRMiniGameType.Darts)
- {
- num = 2;
- }
- else if (this.m_MiniGameType == VRMiniGameManager.VRMiniGameType.Kamihikouki)
- {
- num = 3;
- }
- GameMain.Instance.OvrMgr.OvrCamera.ForceHideUI(false);
- GameMain.VRDeviceType vrdeviceTypeID = GameMain.Instance.VRDeviceTypeID;
- if (vrdeviceTypeID != GameMain.VRDeviceType.NON)
- {
- GameMain.Instance.OvrMgr.OvrCamera.UIPosReset(0f);
- }
- VRCanvasManager.Instance.OpenVRCanvas(VRCanvasManager.VRCanvasType.NONE);
- this.m_MiniGameScoreBoard.transform.SetParent(VRCanvasManager.Instance.CanvasParent.transform, false);
- this.m_MiniGameScoreBoard.transform.localPosition = Vector3.zero;
- this.m_MiniGameScoreBoard.transform.localScale = Vector3.one * 0.001f;
- this.m_MiniGameScoreBoard.transform.localRotation = Quaternion.identity;
- this.m_MiniGameScoreBoard.GetComponent<CanvasGroup>().interactable = true;
- Camera componentInChildren = EventSystem.current.gameObject.GetComponentInChildren<Camera>();
- this.m_MiniGameScoreBoard.GetComponent<Canvas>().worldCamera = componentInChildren;
- List<VRMiniGameManager.MiniGameResultData> list = new List<VRMiniGameManager.MiniGameResultData>();
- string text = "vrcom_mini_game.nei";
- if (!GameUty.FileSystem.IsExistentFile(text))
- {
- NDebug.Assert("表がありません。" + text, false);
- }
- using (AFileBase afileBase = GameUty.FileSystem.FileOpen(text))
- {
- using (CsvParser csvParser = new CsvParser())
- {
- bool condition = csvParser.Open(afileBase);
- NDebug.Assert(condition, text + "\nopen failed.");
- for (int i = 1; i < csvParser.max_cell_y; i++)
- {
- if (csvParser.IsCellToExistData(0, i))
- {
- int num2 = 0;
- int cellAsInteger = csvParser.GetCellAsInteger(num2++, i);
- if (cellAsInteger == num)
- {
- int cellAsInteger2 = csvParser.GetCellAsInteger(num2++, i);
- int cellAsInteger3 = csvParser.GetCellAsInteger(num2++, i);
- string cellAsString = csvParser.GetCellAsString(num2++, i);
- string cellAsString2 = csvParser.GetCellAsString(num2++, i);
- string cellAsString3 = csvParser.GetCellAsString(num2++, i);
- list.Add(new VRMiniGameManager.MiniGameResultData(cellAsInteger2, cellAsInteger3, cellAsString, cellAsString3, cellAsInteger3 <= this.score, cellAsString2));
- }
- }
- }
- }
- }
- string message = string.Empty;
- bool flag = false;
- for (int j = 0; j < list.Count; j++)
- {
- if (list[j].IsGet)
- {
- flag = true;
- break;
- }
- }
- bool flag2 = false;
- if (this.m_MiniGameType == VRMiniGameManager.VRMiniGameType.Wanage)
- {
- flag2 = (this.score == 10);
- }
- else if (this.m_MiniGameType == VRMiniGameManager.VRMiniGameType.Darts)
- {
- flag2 = (this.score == 600);
- }
- else if (this.m_MiniGameType == VRMiniGameManager.VRMiniGameType.Kamihikouki)
- {
- flag2 = (this.score == 550);
- }
- List<VRMiniGameManager.MiniGameResultData> list2 = new List<VRMiniGameManager.MiniGameResultData>();
- for (int k = 0; k < list.Count; k++)
- {
- VRMiniGameManager.MiniGameResultData miniGameResultData = list[k];
- if (miniGameResultData.IsGet)
- {
- if (!string.IsNullOrEmpty(miniGameResultData.FileName))
- {
- bool flag3 = false;
- string[] array = miniGameResultData.FileName.Split(new char[]
- {
- ','
- });
- for (int l = 0; l < array.Length; l++)
- {
- if (GameMain.Instance.CharacterMgr.status.IsHavePartsItem(array[l] + ".menu"))
- {
- Debug.Log("[ミニゲーム\u3000リザルト]" + array[l] + "は既に持っている");
- flag3 = true;
- }
- }
- if (!flag3)
- {
- list2.Add(miniGameResultData);
- }
- }
- }
- }
- VRMiniGameManager.VoiceType voiceType = VRMiniGameManager.VoiceType.Result4;
- if (!flag)
- {
- voiceType = VRMiniGameManager.VoiceType.Result4;
- message = "何も獲得できませんでした……";
- }
- else if (list2.Count > 0)
- {
- voiceType = VRMiniGameManager.VoiceType.Result2;
- if (list2.Count == 1)
- {
- message = "衣装「" + list2[0].ItemName + "」をゲットしました!";
- }
- else
- {
- message = list2.Count.ToString() + "つの衣装をゲットしました!";
- }
- GameMain.Instance.SoundMgr.PlaySe("SE_vr0033.ogg", false);
- }
- else if (!flag2)
- {
- voiceType = VRMiniGameManager.VoiceType.Result3;
- message = "今回の点数は" + this.score.ToString() + "点でした。";
- GameMain.Instance.SoundMgr.PlaySe("SE_vr0032.ogg", false);
- }
- else
- {
- voiceType = VRMiniGameManager.VoiceType.Result1;
- message = "最高点数!今回の点数は" + this.score + "点でした!";
- GameMain.Instance.SoundMgr.PlaySe("SE_vr0034.ogg", false);
- }
- for (int m = 0; m < list2.Count; m++)
- {
- VRMiniGameManager.MiniGameResultData miniGameResultData2 = list2[m];
- if (!string.IsNullOrEmpty(miniGameResultData2.FileName))
- {
- string[] array2 = miniGameResultData2.FileName.Split(new char[]
- {
- ','
- });
- for (int n = 0; n < array2.Length; n++)
- {
- GameMain.Instance.CharacterMgr.status.AddHavePartsItem(array2[n] + ".menu");
- }
- }
- }
- if (flag)
- {
- for (int num3 = 0; num3 < list.Count; num3++)
- {
- if (list[num3].ItemScore <= this.score)
- {
- if (!string.IsNullOrEmpty(list[num3].ItemFlag))
- {
- GameMain.Instance.CharacterMgr.status.SetFlag(list[num3].ItemFlag, 1);
- }
- }
- }
- }
- callback = (UnityAction)Delegate.Combine(callback, new UnityAction(delegate
- {
- this.AddQueueVoice(voiceType);
- this.FinishMiniGame();
- }));
- this.m_MiniGameScoreBoard.Result(message, callback);
- }
- public void FinishMiniGame()
- {
- GameMain.Instance.OvrMgr.OvrCamera.HandLimitMode = AVRControllerBehavior.LIMIT_MODE.NORMAL;
- UnityEngine.Object.Destroy(this.m_MiniGameScoreBoard.gameObject);
- GameMain.Instance.OvrMgr.OvrCamera.ShowUI(false);
- VRCanvasManager.Instance.OpenVRCanvas(VRCanvasManager.VRCanvasType.MainMenu);
- this.m_MiniGameState = VRMiniGameManager.VRMiniGameState.None;
- base.StartCoroutine(this.Coroutine_WaitVoice(delegate
- {
- if (!string.IsNullOrEmpty(this.m_ScriptArgFileEnd) && !string.IsNullOrEmpty(this.m_ScriptArgLabelEnd))
- {
- Debug.Log("OnEndScene JumpTo " + this.m_ScriptArgLabelEnd);
- GameMain.Instance.ScriptMgr.LoadAdvScenarioScript(this.m_ScriptArgFileEnd + ".ks", string.Empty);
- GameMain.Instance.ScriptMgr.adv_kag.JumpLabel(this.m_ScriptArgLabelEnd);
- GameMain.Instance.ScriptMgr.adv_kag.Exec();
- }
- }));
- }
- private IEnumerator Coroutine_WaitVoice(UnityAction callback)
- {
- while (GameMain.Instance.SoundMgr.isVoicePlaying())
- {
- yield return null;
- }
- yield return new WaitForSeconds(0.75f);
- callback();
- yield break;
- }
- private void Update()
- {
- if (0 < this.voiceQueueList.Count && !GameMain.Instance.SoundMgr.isVoicePlaying())
- {
- string label_name = this.voiceQueueList[0];
- this.voiceQueueList.RemoveAt(0);
- GameMain.Instance.ScriptMgr.LoadAdvScenarioScript(this.callScriptFile + ".ks", label_name);
- GameMain.Instance.ScriptMgr.adv_kag.Exec();
- this.voicePlayTime = Time.time;
- }
- if (this.voiceQueueList.Count == 0 && !GameMain.Instance.SoundMgr.isVoicePlaying() && this.voicePlayTime + this.voiceWaitTime <= Time.time && this.m_MiniGameState == VRMiniGameManager.VRMiniGameState.Playing)
- {
- this.AddQueueVoice(VRMiniGameManager.VoiceType.Wait);
- this.voicePlayTime = Time.time + UnityEngine.Random.Range(0f, this.voiceWaitTime / 2f);
- }
- }
- public void AddQueueVoice(VRMiniGameManager.VoiceType type)
- {
- Debug.Log("[ ミニゲームマネージャ ]ボイス:" + type);
- string text = string.Empty;
- switch (type)
- {
- case VRMiniGameManager.VoiceType.Wait:
- text = "*game_random";
- break;
- case VRMiniGameManager.VoiceType.Hit:
- text = "*good_random";
- break;
- case VRMiniGameManager.VoiceType.Miss:
- text = "*bad_random";
- break;
- case VRMiniGameManager.VoiceType.Result1:
- text = "*result_1";
- break;
- case VRMiniGameManager.VoiceType.Result2:
- text = "*result_2";
- break;
- case VRMiniGameManager.VoiceType.Result3:
- text = "*result_3";
- break;
- case VRMiniGameManager.VoiceType.Result4:
- text = "*result_4";
- break;
- default:
- switch (type)
- {
- case VRMiniGameManager.VoiceType.StartKamihikouki:
- text = "*kamihikouki_start";
- break;
- case VRMiniGameManager.VoiceType.StartDarts:
- text = "*darts_start";
- break;
- case VRMiniGameManager.VoiceType.StartWanage:
- text = "*wanage_start";
- break;
- }
- break;
- }
- if (VRMiniGameManager.VoiceType.Remaining0 <= type && type <= VRMiniGameManager.VoiceType.Remaining10)
- {
- text = "*remaining_" + ((int)(VRMiniGameManager.VoiceType.Remaining7 - (VRMiniGameManager.VoiceType.Remaining10 - type))).ToString();
- }
- else
- {
- this.StopVoice();
- this.ClearQueueVoice();
- }
- if (string.IsNullOrEmpty(text))
- {
- Debug.LogError("ミニゲームにてAddQueueVoice関数が呼ばれましたが、タグの指定が不明です");
- return;
- }
- if (!GameMain.Instance.SoundMgr.isVoicePlaying() && this.voiceQueueList.Count == 0)
- {
- GameMain.Instance.ScriptMgr.LoadAdvScenarioScript(this.callScriptFile + ".ks", text);
- GameMain.Instance.ScriptMgr.adv_kag.Exec();
- }
- else
- {
- this.voiceQueueList.Add(text);
- }
- }
- private void ClearQueueVoice()
- {
- this.voiceQueueList.Clear();
- }
- private void StopVoice()
- {
- GameMain.Instance.SoundMgr.VoiceStopAll();
- }
- private static VRMiniGameManager m_Instance;
- private VRMiniGameScoreBoard m_MiniGameScoreBoard;
- private AVRControllerButtons m_VRController;
- private VRMiniGameManager.VRMiniGameType m_MiniGameType;
- private VRMiniGameManager.VRMiniGameState m_MiniGameState;
- private string m_ScriptArgLabelEnd = string.Empty;
- private string m_ScriptArgFileEnd = string.Empty;
- [SerializeField]
- [Tooltip("メイドスクリプトファイル")]
- private string callScriptFile = "001_?_minigame";
- private List<string> voiceQueueList = new List<string>();
- private float voicePlayTime;
- private float voiceWaitTime = 10f;
- public enum VRMiniGameType
- {
- Wanage,
- Darts,
- Kamihikouki
- }
- public enum VRMiniGameState
- {
- None,
- Setup,
- Playing,
- Result
- }
- private class MiniGameResultData
- {
- public MiniGameResultData(int itemID, int itemScore, string fileName, string itemFlag, bool isGet, string itemName)
- {
- this.ItemID = itemID;
- this.ItemScore = itemScore;
- this.FileName = fileName;
- this.ItemFlag = itemFlag;
- this.IsGet = isGet;
- this.ItemName = itemName;
- }
- public int ItemID;
- public int ItemScore;
- public string FileName;
- public string ItemFlag;
- public bool IsGet;
- public string ItemName;
- }
- public enum VoiceType
- {
- StartKamihikouki,
- StartDarts,
- StartWanage,
- Remaining0,
- Remaining1,
- Remaining2,
- Remaining3,
- Remaining4,
- Remaining5,
- Remaining6,
- Remaining7,
- Remaining8,
- Remaining9,
- Remaining10,
- Wait,
- Hit,
- Miss,
- Result1,
- Result2,
- Result3,
- Result4
- }
- }
|