Note_Mgr.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using UnityEngine;
  6. public class Note_Mgr : PartsMgrBase
  7. {
  8. public int CellX
  9. {
  10. get
  11. {
  12. return this.m_CellX;
  13. }
  14. }
  15. public int CellY
  16. {
  17. get
  18. {
  19. return this.m_CellY;
  20. }
  21. }
  22. public static Note_Mgr Instance
  23. {
  24. get
  25. {
  26. return Note_Mgr.m_Instance;
  27. }
  28. }
  29. public int UIRootWidth { get; private set; }
  30. public int UIRootHeight { get; private set; }
  31. public GameObject NoteEffectPrefab { get; private set; }
  32. public int SpecialCombo
  33. {
  34. get
  35. {
  36. return this.m_SpecialCombo;
  37. }
  38. }
  39. public int GetSpecial
  40. {
  41. get
  42. {
  43. return this.m_GetSpecial;
  44. }
  45. }
  46. private float m_TotalAnimeTime
  47. {
  48. get
  49. {
  50. return this.m_TextJumpTime * (float)this.m_FullComboObj.childCount + this.m_AnimeLag * (float)(this.m_FullComboObj.childCount - 1) + this.m_DeleteWait;
  51. }
  52. }
  53. protected override void Start()
  54. {
  55. Note_Mgr.m_Instance = this;
  56. base.Start();
  57. if (!base.IsActive)
  58. {
  59. base.gameObject.SetActive(false);
  60. return;
  61. }
  62. this.m_FullComboSe = Resources.Load<AudioClip>("SceneDance/Rhythm_Action/Sound/" + this.m_FullcomSeStr);
  63. this.NoteEffectPrefab = Resources.Load<GameObject>("SceneDance/Rhythm_Action/Prefab/NoteEffect");
  64. this.m_SEAudioList = this.m_NoteSEAudio.GetComponents<AudioSource>();
  65. RhythmAction_Mgr.Instance.AddAudioMgr(this.m_SEAudioList);
  66. UIRoot component = GameObject.Find("UI Root").GetComponent<UIRoot>();
  67. this.UIRootWidth = component.manualWidth;
  68. this.UIRootHeight = component.manualHeight;
  69. this.m_FullComboObj.gameObject.SetActive(false);
  70. this.m_NoteCharaData.Add(DanceBattle_Mgr.CharaType.Player, new Note_Mgr.NoteCharaData());
  71. if (RhythmAction_Mgr.NowDance == RhythmAction_Mgr.DanceType.VS || RhythmAction_Mgr.NowDance == RhythmAction_Mgr.DanceType.BenchMark)
  72. {
  73. this.m_NoteCharaData.Add(DanceBattle_Mgr.CharaType.Enemy, new Note_Mgr.NoteCharaData());
  74. }
  75. this.m_NoteObj = Resources.Load<GameObject>("SceneDance/Rhythm_Action/Prefab/Note");
  76. Dance_Note component2 = this.m_NoteObj.GetComponent<Dance_Note>();
  77. this.m_JudgeStart_Time = component2.GetBeforeJudge(Dance_Note.Evaluation.BAD) + component2.NotJudgeTime;
  78. this.CSVRead();
  79. }
  80. private void CSVRead()
  81. {
  82. string text = RhythmAction_Mgr.Instance.MusicCSV_Path + "note_data.nei";
  83. if (!GameUty.FileSystem.IsExistentFile(text))
  84. {
  85. NDebug.Assert("表がありません。" + text, false);
  86. }
  87. using (AFileBase afileBase = GameUty.FileSystem.FileOpen(text))
  88. {
  89. using (CsvParser csvParser = new CsvParser())
  90. {
  91. bool condition = csvParser.Open(afileBase);
  92. NDebug.Assert(condition, text + "\nopen failed.");
  93. for (int i = 1; i < csvParser.max_cell_y; i++)
  94. {
  95. if (csvParser.IsCellToExistData(0, i))
  96. {
  97. Note_Mgr.NoteData noteData = new Note_Mgr.NoteData();
  98. for (int j = 1; j < csvParser.max_cell_x; j++)
  99. {
  100. this.DataParce(csvParser, j, i, noteData);
  101. }
  102. this.m_All_NoteData.Add(noteData);
  103. }
  104. }
  105. }
  106. }
  107. }
  108. private void DataParce(CsvParser csv, int cell_X, int cell_Y, Note_Mgr.NoteData data)
  109. {
  110. switch (cell_X)
  111. {
  112. case 1:
  113. data.Time = csv.GetCellAsReal(cell_X, cell_Y);
  114. break;
  115. case 2:
  116. {
  117. string cellAsString = csv.GetCellAsString(cell_X, cell_Y);
  118. string[] array = cellAsString.Split(new char[]
  119. {
  120. ','
  121. });
  122. data.DotX = int.Parse(array[0]);
  123. data.DotY = int.Parse(array[1]);
  124. break;
  125. }
  126. case 4:
  127. {
  128. string[] array2 = csv.GetCellAsString(cell_X, cell_Y).Split(new char[]
  129. {
  130. ':'
  131. });
  132. if (data.Voltage == null)
  133. {
  134. data.Voltage = new List<int>();
  135. }
  136. foreach (string s in array2)
  137. {
  138. data.Voltage.Add(int.Parse(s));
  139. }
  140. break;
  141. }
  142. case 5:
  143. if (csv.GetCellAsString(cell_X, cell_Y) == "エフェクト無し")
  144. {
  145. data.effectType = Note_Mgr.EffecctType.Nothing;
  146. }
  147. else if (csv.GetCellAsString(cell_X, cell_Y) == "小エフェクト")
  148. {
  149. data.effectType = Note_Mgr.EffecctType.Few;
  150. }
  151. break;
  152. case 6:
  153. data.RingSize = ((!csv.IsCellToExistData(cell_X, cell_Y)) ? -1f : csv.GetCellAsReal(cell_X, cell_Y));
  154. break;
  155. }
  156. }
  157. private float OccurTime(DanceBattle_Mgr.CharaType chara)
  158. {
  159. int dataUseCount = this.m_NoteCharaData[chara].DataUseCount;
  160. if (this.m_All_NoteData.Count <= dataUseCount)
  161. {
  162. return -1f;
  163. }
  164. if (chara == DanceBattle_Mgr.CharaType.Player)
  165. {
  166. return this.m_All_NoteData[dataUseCount].Time - this.m_JudgeStart_Time - DanceSetting.Settings.NoteJudgeTiming;
  167. }
  168. return this.m_All_NoteData[dataUseCount].Time;
  169. }
  170. private bool IsOccurOK(DanceBattle_Mgr.CharaType chara_type)
  171. {
  172. bool result = false;
  173. int voltage = 0;
  174. int dataUseCount = this.m_NoteCharaData[chara_type].DataUseCount;
  175. if (chara_type == DanceBattle_Mgr.CharaType.Player)
  176. {
  177. voltage = Voltage_Mgr.Instance.VoltageStage;
  178. }
  179. else if (chara_type == DanceBattle_Mgr.CharaType.Enemy)
  180. {
  181. voltage = DanceBattle_Mgr.EnemyData.UseVoltage;
  182. }
  183. if (this.m_All_NoteData.Count > dataUseCount)
  184. {
  185. result = this.m_All_NoteData[dataUseCount].Voltage.Any((int e) => e == voltage);
  186. }
  187. return result;
  188. }
  189. private bool IsExistKeyInput()
  190. {
  191. foreach (KeyCode key in this.m_AsClickKey)
  192. {
  193. if (Input.GetKeyDown(key))
  194. {
  195. return true;
  196. }
  197. }
  198. return false;
  199. }
  200. private IEnumerator NoteCheck()
  201. {
  202. float timer = 0f;
  203. bool input_check = true;
  204. for (;;)
  205. {
  206. if (!RhythmAction_Mgr.Instance.IsPause)
  207. {
  208. timer += RhythmAction_Mgr.Instance.DanceDeltaTime;
  209. foreach (KeyValuePair<DanceBattle_Mgr.CharaType, Note_Mgr.NoteCharaData> keyValuePair in this.m_NoteCharaData)
  210. {
  211. if (keyValuePair.Key == DanceBattle_Mgr.CharaType.Player)
  212. {
  213. if (keyValuePair.Value.NoteList.Count > 0)
  214. {
  215. keyValuePair.Value.NoteList.First<Dance_Note>().SetTargetNote();
  216. }
  217. bool flag = false;
  218. if (input_check)
  219. {
  220. if (GameMain.Instance.VRMode && !GameMain.Instance.OvrMgr.OvrCamera.IsNoHandController)
  221. {
  222. OvrMgr.OvrObject.Controller left_controller = GameMain.Instance.OvrMgr.ovr_obj.left_controller;
  223. OvrMgr.OvrObject.Controller right_controller = GameMain.Instance.OvrMgr.ovr_obj.right_controller;
  224. flag |= (left_controller.controller_buttons.GetPressDown(AVRControllerButtons.BTN.VIRTUAL_L_CLICK) && left_controller.controller.HandDanceMode);
  225. flag |= (right_controller.controller_buttons.GetPressDown(AVRControllerButtons.BTN.VIRTUAL_L_CLICK) && right_controller.controller.HandDanceMode);
  226. }
  227. else
  228. {
  229. flag = (NInput.GetMouseButtonDown(0) || this.IsExistKeyInput());
  230. }
  231. }
  232. else
  233. {
  234. input_check = true;
  235. }
  236. if (flag)
  237. {
  238. input_check = false;
  239. if (!Appeal_Mgr.Instance.IsActive || !Appeal_Mgr.Instance.GetPlayerData().IsAppealNow)
  240. {
  241. this.CheckStart(keyValuePair.Key);
  242. }
  243. }
  244. }
  245. if (this.OccurTime(keyValuePair.Key) > 0f && timer >= this.OccurTime(keyValuePair.Key))
  246. {
  247. bool flag2 = this.IsOccurOK(keyValuePair.Key);
  248. if (keyValuePair.Value.DataUseCount + 1 < this.m_All_NoteData.Count)
  249. {
  250. flag2 &= (timer < this.m_All_NoteData[keyValuePair.Value.DataUseCount + 1].Time);
  251. }
  252. if (flag2)
  253. {
  254. GameObject gameObject = UnityEngine.Object.Instantiate<GameObject>(this.m_NoteObj);
  255. gameObject.transform.SetParent(base.transform, false);
  256. int dotX = this.m_All_NoteData[keyValuePair.Value.DataUseCount].DotX;
  257. int dotY = this.m_All_NoteData[keyValuePair.Value.DataUseCount].DotY;
  258. gameObject.GetComponent<Dance_Note>().Init(this.m_All_NoteData[keyValuePair.Value.DataUseCount], keyValuePair.Key, keyValuePair.Value.DataUseCount);
  259. }
  260. keyValuePair.Value.DataUseCount++;
  261. }
  262. }
  263. }
  264. yield return null;
  265. }
  266. yield break;
  267. }
  268. private void FullComboAnim(float time)
  269. {
  270. for (int i = 0; i < this.m_FullComboObj.childCount; i++)
  271. {
  272. if (time < (float)i * this.m_AnimeLag)
  273. {
  274. break;
  275. }
  276. float current_time = Mathf.Clamp(time - this.m_AnimeLag * (float)i, 0f, this.m_TextJumpTime);
  277. Transform child = this.m_FullComboObj.GetChild(i);
  278. Vector3 localPosition = child.localPosition;
  279. localPosition.y = this.m_TextJump * KasaiUtility.SinRate01(current_time, this.m_TextJumpTime / 2f, false, true);
  280. child.localPosition = localPosition;
  281. }
  282. }
  283. public void CheckStart(DanceBattle_Mgr.CharaType chara)
  284. {
  285. if (this.m_NoteCharaData[chara].NoteList.Count > 0)
  286. {
  287. this.m_NoteCharaData[chara].NoteList.First<Dance_Note>().CheckNote();
  288. }
  289. }
  290. public void RemoveNote(DanceBattle_Mgr.CharaType chara)
  291. {
  292. if (this.m_NoteCharaData[chara].NoteList.Count > 0)
  293. {
  294. this.m_NoteCharaData[chara].NoteList.RemoveAt(0);
  295. }
  296. if (chara != DanceBattle_Mgr.CharaType.Player && RhythmAction_Mgr.NowDance != RhythmAction_Mgr.DanceType.VS)
  297. {
  298. return;
  299. }
  300. if (this.IsNoteEnd(chara) && !Score_Mgr.Instance.IsExistMiss)
  301. {
  302. Score_Mgr.Instance.NotMissClear();
  303. this.m_FullComboObj.gameObject.SetActive(true);
  304. this.NoteSEPlay(this.m_FullComboSe);
  305. base.StartCoroutine(RhythmAction_Mgr.Instance.DanceTimeCoroutine(this.m_TotalAnimeTime, new Action<float>(this.FullComboAnim), delegate
  306. {
  307. this.m_FullComboObj.gameObject.SetActive(false);
  308. }));
  309. }
  310. }
  311. public void AddNote(Dance_Note note, DanceBattle_Mgr.CharaType chara)
  312. {
  313. this.m_NoteCharaData[chara].NoteList.Add(note);
  314. if (note.IsAppealNow)
  315. {
  316. this.AddAppealNoteCount(chara);
  317. }
  318. }
  319. public void NoteSEPlay(AudioClip clip = null)
  320. {
  321. foreach (AudioSource audioSource in this.m_SEAudioList)
  322. {
  323. if (!audioSource.isPlaying)
  324. {
  325. if (clip)
  326. {
  327. audioSource.clip = clip;
  328. }
  329. audioSource.Play();
  330. break;
  331. }
  332. }
  333. }
  334. public bool IsNoteEnd(DanceBattle_Mgr.CharaType chara_type)
  335. {
  336. bool flag = this.m_NoteCharaData[chara_type].DataUseCount == this.m_All_NoteData.Count;
  337. bool flag2 = this.m_NoteCharaData[chara_type].NoteList.Count == 0;
  338. return flag && flag2;
  339. }
  340. public bool IsNoteSpecial(DanceBattle_Mgr.CharaType chara_type)
  341. {
  342. return this.m_NoteCharaData[chara_type].IsSpecialNote;
  343. }
  344. public void SetSpecialFlag(DanceBattle_Mgr.CharaType chara_type, bool flag_value)
  345. {
  346. this.m_NoteCharaData[chara_type].IsSpecialNote = flag_value;
  347. }
  348. public int AppealNoteCount(DanceBattle_Mgr.CharaType chara_type)
  349. {
  350. return this.m_NoteCharaData[chara_type].AppealNoteCount;
  351. }
  352. public void AddAppealNoteCount(DanceBattle_Mgr.CharaType chara_type)
  353. {
  354. this.m_NoteCharaData[chara_type].AppealNoteCount++;
  355. }
  356. public void RecetAppealCount(DanceBattle_Mgr.CharaType chara_type)
  357. {
  358. this.m_NoteCharaData[chara_type].AppealNoteCount = 0;
  359. }
  360. public bool CanNoteAppeal(DanceBattle_Mgr.CharaType chara_type)
  361. {
  362. return Appeal_Mgr.Instance.IsActive && Appeal_Mgr.Instance.GetAppealData(chara_type).IsAppealNow && this.m_NoteCharaData[chara_type].AppealNoteCount < Appeal_Mgr.Instance.AppealComboCount;
  363. }
  364. public override void StartAction()
  365. {
  366. base.StartCoroutine(this.NoteCheck());
  367. }
  368. public override void EndAction()
  369. {
  370. base.StopAllCoroutines();
  371. }
  372. private const string m_NoteEffectPath = "SceneDance/Rhythm_Action/Prefab/NoteEffect";
  373. private const string m_NotePath = "SceneDance/Rhythm_Action/Prefab/Note";
  374. [SerializeField]
  375. [Header("横マス数")]
  376. private int m_CellX = 27;
  377. [SerializeField]
  378. [Header("縦マス数")]
  379. private int m_CellY = 17;
  380. [SerializeField]
  381. [Header("ノートSE用のオーディオ")]
  382. private GameObject m_NoteSEAudio;
  383. private AudioSource[] m_SEAudioList;
  384. private Dictionary<DanceBattle_Mgr.CharaType, Note_Mgr.NoteCharaData> m_NoteCharaData = new Dictionary<DanceBattle_Mgr.CharaType, Note_Mgr.NoteCharaData>();
  385. private List<Note_Mgr.NoteData> m_All_NoteData = new List<Note_Mgr.NoteData>();
  386. private Vector2 m_DotSize = Vector2.zero;
  387. private GameObject m_NoteObj;
  388. private float m_JudgeStart_Time;
  389. private static Note_Mgr m_Instance;
  390. [SerializeField]
  391. [Header("フルコンボ時の設定")]
  392. private Transform m_FullComboObj;
  393. [SerializeField]
  394. private float m_TextJump = 90f;
  395. [SerializeField]
  396. private float m_TextJumpTime = 0.3f;
  397. [SerializeField]
  398. private float m_AnimeLag = 0.05f;
  399. [SerializeField]
  400. private float m_DeleteWait = 0.25f;
  401. [SerializeField]
  402. private string m_FullcomSeStr = "4_battle_win";
  403. [SerializeField]
  404. [Header("左クリックに割り当てるキー")]
  405. private List<KeyCode> m_AsClickKey = new List<KeyCode>();
  406. [SerializeField]
  407. [Header("このコンボ数毎に特殊なノート発生")]
  408. private int m_SpecialCombo = 50;
  409. [SerializeField]
  410. [Header("このコンボ数分の効果を得る")]
  411. private int m_GetSpecial = 10;
  412. private AudioClip m_FullComboSe;
  413. public enum EffecctType
  414. {
  415. ALL,
  416. Few,
  417. Nothing
  418. }
  419. public class NoteData
  420. {
  421. public float Time;
  422. public int DotX;
  423. public int DotY;
  424. public List<int> Voltage;
  425. public Note_Mgr.EffecctType effectType;
  426. public float RingSize;
  427. }
  428. private class NoteCharaData
  429. {
  430. public List<Dance_Note> NoteList = new List<Dance_Note>();
  431. public int DataUseCount;
  432. public bool IsSpecialNote;
  433. public int AppealNoteCount;
  434. }
  435. }