MotionAction_Mgr.cs 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using UnityEngine;
  6. using wf;
  7. public class MotionAction_Mgr : PartsMgrBase
  8. {
  9. public static bool IsCaptureOK
  10. {
  11. get
  12. {
  13. return GameMain.Instance.CharacterMgr.status.GetFlag("モーションキャプチャ成功") == 1;
  14. }
  15. private set
  16. {
  17. GameMain.Instance.CharacterMgr.status.SetFlag("モーションキャプチャ成功", (!value) ? 0 : 1);
  18. }
  19. }
  20. public static MotionAction_Mgr Instance { get; private set; }
  21. protected override void Start()
  22. {
  23. MotionAction_Mgr.Instance = this;
  24. base.Start();
  25. int tmpGenericFlag = GameMain.Instance.CMSystem.GetTmpGenericFlag("ダンスOVRカメラタイプ");
  26. if ((!base.IsActive || !GameMain.Instance.VRMode || tmpGenericFlag == 1) && !this.m_IsMotionCheckOnly)
  27. {
  28. base.IsActive = false;
  29. base.gameObject.SetActive(false);
  30. return;
  31. }
  32. if (!this.m_IsMotionCheckOnly)
  33. {
  34. string text = RhythmAction_Mgr.Instance.MusicCSV_Path + "action_data.nei";
  35. if (!GameUty.FileSystem.IsExistentFile(text))
  36. {
  37. NDebug.Assert("表がありません。" + text, false);
  38. }
  39. using (AFileBase afileBase = GameUty.FileSystem.FileOpen(text))
  40. {
  41. using (CsvParser csvParser = new CsvParser())
  42. {
  43. bool condition = csvParser.Open(afileBase);
  44. NDebug.Assert(condition, text + "\nopen failed.");
  45. for (int i = 1; i < csvParser.max_cell_y; i++)
  46. {
  47. if (csvParser.IsCellToExistData(0, i))
  48. {
  49. ActionCase item = new ActionCase();
  50. for (int j = 1; j < csvParser.max_cell_x; j++)
  51. {
  52. this.ReadActionData(csvParser, j, i, ref item);
  53. }
  54. this.m_ActionAllCase.Add(item);
  55. }
  56. }
  57. }
  58. }
  59. this.Initialize();
  60. }
  61. }
  62. private void Initialize()
  63. {
  64. MotionAction_Mgr.GuidUIInfo.CurrentActionCount = 0;
  65. foreach (MotionAction_Mgr.GuidUIInfo guidUIInfo in this.m_GuidUIList)
  66. {
  67. guidUIInfo.GuidUI.fillAmount = 0f;
  68. guidUIInfo.GuidUI.gameObject.SetActive(false);
  69. this.m_AllGuidUIInfo.Add(guidUIInfo.Type, guidUIInfo);
  70. }
  71. if (!GameMain.Instance.VRMode || GameMain.Instance.OvrMgr.OvrCamera.IsNoHandController || this.m_IsForceMouseCheck)
  72. {
  73. this.m_CheckHand = UnityEngine.Object.Instantiate<GameObject>(Resources.Load<GameObject>("SceneDance/Rhythm_Action/Prefab/" + this.m_strHandName));
  74. this.m_CheckHand.transform.localScale = this.m_HandSize;
  75. Transform realHeadTransform = GameMain.Instance.MainCamera.GetRealHeadTransform();
  76. this.m_CheckHand.transform.parent = ((!GameMain.Instance.VRMode) ? realHeadTransform : GameMain.Instance.OvrMgr.OvrCamera.m_goOvrUiScreen.transform);
  77. this.m_CheckHand.transform.localEulerAngles = this.m_HandAngle;
  78. this.m_CheckHand.transform.localPosition = this.m_HandRelatePos;
  79. }
  80. else
  81. {
  82. OvrMgr.OvrObject.Controller left_controller = GameMain.Instance.OvrMgr.ovr_obj.left_controller;
  83. OvrMgr.OvrObject.Controller right_controller = GameMain.Instance.OvrMgr.ovr_obj.right_controller;
  84. this.m_ControllerParent = right_controller.hand_trans.parent;
  85. if (!this.m_MotionCheckDataVR.ContainsKey(left_controller))
  86. {
  87. this.m_MotionCheckDataVR.Add(left_controller, new MotionAction_Mgr.NeedCheckData());
  88. }
  89. if (!this.m_MotionCheckDataVR.ContainsKey(right_controller))
  90. {
  91. this.m_MotionCheckDataVR.Add(right_controller, new MotionAction_Mgr.NeedCheckData());
  92. }
  93. }
  94. }
  95. private void ReadActionData(CsvParser csv, int cx, int cy, ref ActionCase case_data)
  96. {
  97. switch (cx)
  98. {
  99. case 1:
  100. {
  101. string[] array = csv.GetCellAsString(cx, cy).Split(new char[]
  102. {
  103. ':'
  104. });
  105. case_data.StartTime = float.Parse(array[0]);
  106. case_data.EndTime = float.Parse(array[1]);
  107. break;
  108. }
  109. case 2:
  110. {
  111. string[] array2 = csv.GetCellAsString(cx, cy).Split(new char[]
  112. {
  113. '.'
  114. });
  115. case_data.Trigger = array2[0];
  116. foreach (string s in array2[1].Split(new char[]
  117. {
  118. ':'
  119. }))
  120. {
  121. case_data.TargetMaidNo.Add(int.Parse(s) - 1);
  122. }
  123. break;
  124. }
  125. case 3:
  126. foreach (string value in csv.GetCellAsString(cx, cy).Split(new char[]
  127. {
  128. ':'
  129. }))
  130. {
  131. case_data.Action.Add((ActionCase.ActionType)Enum.Parse(typeof(ActionCase.ActionType), value));
  132. }
  133. break;
  134. case 4:
  135. {
  136. string[] array5 = csv.GetCellAsString(cx, cy).Split(new char[]
  137. {
  138. ':'
  139. });
  140. foreach (string text in array5)
  141. {
  142. string[] array7 = text.Split(new char[]
  143. {
  144. '.'
  145. });
  146. ActionCase.ReactionParam reactionParam = new ActionCase.ReactionParam();
  147. reactionParam.IsFaceBlend = (array7[0].IndexOf("頬") > 0);
  148. reactionParam.Name = array7[0];
  149. reactionParam.SetTime = float.Parse(array7[1]);
  150. case_data.Reaction.Add(reactionParam);
  151. }
  152. break;
  153. }
  154. case 5:
  155. {
  156. string[] array8 = csv.GetCellAsString(cx, cy).Split(new char[]
  157. {
  158. ':'
  159. });
  160. case_data.Effect = Resources.Load<GameObject>("SceneDance/Rhythm_Action/Prefab/" + array8[0]);
  161. case_data.EffectTime = float.Parse(array8[1]);
  162. break;
  163. }
  164. }
  165. }
  166. private void Update()
  167. {
  168. int currentActionCount = MotionAction_Mgr.GuidUIInfo.CurrentActionCount;
  169. int num = 0;
  170. foreach (MotionAction_Mgr.GuidUIInfo guidUIInfo in this.m_AllGuidUIInfo.Values)
  171. {
  172. if (guidUIInfo.NeedGuid)
  173. {
  174. float d = 0f;
  175. if (currentActionCount > 1)
  176. {
  177. d = -(float)(currentActionCount - 1) / 2f + (float)num;
  178. }
  179. guidUIInfo.GuidUI.transform.localPosition = Vector3.right * d * this.m_SetGuidSpace;
  180. num++;
  181. guidUIInfo.GuidUI.transform.GetChild(0).gameObject.SetActive(num != currentActionCount);
  182. }
  183. }
  184. }
  185. private IEnumerator CheckActionCase()
  186. {
  187. float timer = 0f;
  188. for (;;)
  189. {
  190. yield return null;
  191. if (!RhythmAction_Mgr.Instance.IsPause)
  192. {
  193. timer += RhythmAction_Mgr.Instance.DanceDeltaTime;
  194. List<ActionCase> list = new List<ActionCase>();
  195. foreach (ActionCase actionCase in this.m_ActionAllCase)
  196. {
  197. if (timer >= actionCase.StartTime && timer < actionCase.EndTime)
  198. {
  199. if (!TouchAction_Mgr.Instance.IsMaidTouch() && this.IsTriggerOn(actionCase))
  200. {
  201. base.StartCoroutine(this.MotionCheck(actionCase, timer));
  202. list.Add(actionCase);
  203. }
  204. }
  205. else if (timer > actionCase.EndTime)
  206. {
  207. list.Add(actionCase);
  208. }
  209. }
  210. if (list.Count > 0)
  211. {
  212. foreach (ActionCase item in list)
  213. {
  214. this.m_ActionAllCase.Remove(item);
  215. }
  216. if (this.m_ActionAllCase.Count <= 0)
  217. {
  218. break;
  219. }
  220. }
  221. }
  222. }
  223. yield break;
  224. yield break;
  225. }
  226. private bool IsTriggerOn(ActionCase action_case)
  227. {
  228. if (action_case.Trigger == "non")
  229. {
  230. return true;
  231. }
  232. if (action_case.Trigger == "foundP")
  233. {
  234. bool flag = false;
  235. foreach (int nMaidNo in action_case.TargetMaidNo)
  236. {
  237. Maid maid = GameMain.Instance.CharacterMgr.GetMaid(nMaidNo);
  238. if (!maid)
  239. {
  240. return false;
  241. }
  242. Vector3 position = GameMain.Instance.MainCamera.GetRealHeadTransform().position;
  243. Transform obj_tr = maid.body0.GetSlot(1).obj_tr;
  244. Vector3 vector = obj_tr.rotation * Vector3.forward;
  245. flag = (Vector3.Dot((position - obj_tr.position).normalized, vector.normalized) > Mathf.Cos(0.7853982f));
  246. if (flag)
  247. {
  248. break;
  249. }
  250. }
  251. return flag;
  252. }
  253. return false;
  254. }
  255. private IEnumerator MotionCheck(ActionCase case_data, float start_time)
  256. {
  257. Func<bool> play_voice = delegate()
  258. {
  259. for (int i = 0; i < GameMain.Instance.CharacterMgr.GetMaidCount(); i++)
  260. {
  261. Maid maid = GameMain.Instance.CharacterMgr.GetMaid(i);
  262. if (maid && maid.AudioMan && maid.AudioMan.isPlay())
  263. {
  264. return true;
  265. }
  266. }
  267. return false;
  268. };
  269. while (play_voice())
  270. {
  271. yield return null;
  272. }
  273. float timer = start_time;
  274. bool cursole_visible = false;
  275. CursorLockMode cursole_state = CursorLockMode.None;
  276. if (this.m_MotionCheckDataVR.Count > 0)
  277. {
  278. foreach (KeyValuePair<OvrMgr.OvrObject.Controller, MotionAction_Mgr.NeedCheckData> keyValuePair in this.m_MotionCheckDataVR)
  279. {
  280. keyValuePair.Value.FirstPos = keyValuePair.Key.hand_trans.localPosition;
  281. keyValuePair.Value.Controller = keyValuePair.Key;
  282. keyValuePair.Value.Init();
  283. keyValuePair.Value.MotionEffect.transform.parent = keyValuePair.Value.Controller.hand_trans;
  284. }
  285. }
  286. else
  287. {
  288. this.m_MotionCheckDataMouse.Init();
  289. this.m_MotionCheckDataMouse.MotionEffect.transform.parent = this.m_CheckHand.transform;
  290. if (!GameMain.Instance.VRMode)
  291. {
  292. this.m_MotionCheckDataMouse.FirstPos = Input.mousePosition;
  293. cursole_visible = Cursor.visible;
  294. cursole_state = Cursor.lockState;
  295. }
  296. else
  297. {
  298. this.m_MotionCheckDataMouse.FirstPos = GameMain.Instance.OvrMgr.SystemUICamera.GetOvrVirtualMouseCurrentSidePos();
  299. this.m_MotionCheckDataMouse.CurrentPos = this.m_MotionCheckDataMouse.FirstPos;
  300. }
  301. }
  302. bool isOK;
  303. for (;;)
  304. {
  305. if (!RhythmAction_Mgr.Instance || !RhythmAction_Mgr.Instance.IsPause)
  306. {
  307. timer += ((!RhythmAction_Mgr.Instance) ? Time.deltaTime : RhythmAction_Mgr.Instance.DanceDeltaTime);
  308. isOK = false;
  309. bool isEnd = false;
  310. if (!this.m_IsMotionCheckOnly)
  311. {
  312. isEnd = TouchAction_Mgr.Instance.IsMaidTouch();
  313. }
  314. Vector3 pos = Vector3.zero;
  315. foreach (ActionCase.ActionType actionType in case_data.Action)
  316. {
  317. if (isOK || isEnd)
  318. {
  319. break;
  320. }
  321. this.m_AllGuidUIInfo[actionType].NeedGuid = true;
  322. if (this.m_MotionCheckDataVR.Count > 0)
  323. {
  324. foreach (MotionAction_Mgr.NeedCheckData needCheckData in this.m_MotionCheckDataVR.Values)
  325. {
  326. pos = needCheckData.Controller.hand_trans.localPosition;
  327. needCheckData.CurrentPos = pos;
  328. needCheckData.MotionEffect.transform.localPosition = Vector3.forward * this.m_EffectAdjust;
  329. Vector3 vector = needCheckData.LastPos;
  330. if (actionType == ActionCase.ActionType.swing || actionType == ActionCase.ActionType.shake)
  331. {
  332. pos += needCheckData.Controller.hand_trans.localRotation * Vector3.forward * this.m_ControllerAdjust;
  333. vector += needCheckData.LastRot * Vector3.forward * this.m_ControllerAdjust;
  334. }
  335. if (this.ActionJudge(needCheckData, vector, pos, actionType))
  336. {
  337. isOK = true;
  338. break;
  339. }
  340. }
  341. }
  342. else
  343. {
  344. if (actionType == case_data.Action.First<ActionCase.ActionType>())
  345. {
  346. if (!GameMain.Instance.VRMode)
  347. {
  348. Cursor.lockState = CursorLockMode.Confined;
  349. pos = (this.m_MotionCheckDataMouse.CurrentPos = Input.mousePosition);
  350. }
  351. else
  352. {
  353. this.m_MotionCheckDataMouse.CurrentPos += (Vector3.right * NInput.GetAxis("Mouse X") + Vector3.up * NInput.GetAxis("Mouse Y")) * this.m_HandMoveSpeed;
  354. this.m_MotionCheckDataMouse.CurrentPos.x = Mathf.Clamp(this.m_MotionCheckDataMouse.CurrentPos.x, 0f, (float)UICamera.ScreenWidth);
  355. this.m_MotionCheckDataMouse.CurrentPos.y = Mathf.Clamp(this.m_MotionCheckDataMouse.CurrentPos.y, 0f, (float)UICamera.ScreenHeight);
  356. pos = this.m_MotionCheckDataMouse.CurrentPos;
  357. }
  358. }
  359. Vector3 lastPos = this.m_MotionCheckDataMouse.LastPos;
  360. isOK = this.ActionJudge(this.m_MotionCheckDataMouse, lastPos, pos, actionType);
  361. if (actionType == case_data.Action.First<ActionCase.ActionType>())
  362. {
  363. Vector3 vector2 = Vector3.zero;
  364. if (!GameMain.Instance.VRMode)
  365. {
  366. Vector3 zero = Vector3.zero;
  367. zero.x = (float)Screen.width;
  368. zero.y = (float)Screen.height;
  369. zero.z = this.m_HandRelatePos.z;
  370. Vector3 position = GameMain.Instance.MainCamera.camera.ScreenToWorldPoint(zero);
  371. position = GameMain.Instance.MainCamera.GetRealHeadTransform().InverseTransformPoint(position);
  372. float min = -position.x + this.m_HandRelatePos.x;
  373. float max = position.x + this.m_HandRelatePos.x;
  374. float min2 = -position.y + this.m_HandRelatePos.y;
  375. float max2 = position.y + this.m_HandRelatePos.y;
  376. vector2 = this.m_MotionCheckDataMouse.CurrentPos;
  377. vector2.z = this.m_HandRelatePos.z;
  378. vector2 = GameMain.Instance.MainCamera.camera.ScreenToWorldPoint(vector2);
  379. vector2 = GameMain.Instance.MainCamera.GetRealHeadTransform().InverseTransformPoint(vector2);
  380. vector2.x = Mathf.Clamp(vector2.x, min, max);
  381. vector2.y = Mathf.Clamp(vector2.y, min2, max2);
  382. this.m_CheckHand.transform.localPosition = vector2;
  383. }
  384. else
  385. {
  386. float num = 1f - Mathf.Clamp01(pos.x / (float)UICamera.ScreenWidth);
  387. float num2 = 1f - Mathf.Clamp01(pos.y / (float)UICamera.ScreenHeight);
  388. vector2.x = Mathf.Cos(num * 180f * 0.017453292f) * this.m_HandMoveWidth;
  389. vector2.y = Mathf.Cos(num2 * 180f * 0.017453292f) * this.m_HandMoveHeight;
  390. this.m_CheckHand.transform.localPosition = vector2 + this.m_HandRelatePos;
  391. }
  392. this.m_MotionCheckDataMouse.MotionEffect.transform.localPosition = Vector3.forward * this.m_EffectAdjust;
  393. }
  394. }
  395. }
  396. if (this.m_MotionCheckDataVR.Count > 0)
  397. {
  398. foreach (MotionAction_Mgr.NeedCheckData needCheckData2 in this.m_MotionCheckDataVR.Values)
  399. {
  400. needCheckData2.LastRot = needCheckData2.Controller.hand_trans.localRotation;
  401. needCheckData2.LastPos = needCheckData2.Controller.hand_trans.localPosition;
  402. needCheckData2.LastVec = needCheckData2.NowVec;
  403. needCheckData2.EmmitAdjust(this.m_HorizontalColor, this.m_VerticalColor);
  404. }
  405. }
  406. else
  407. {
  408. this.m_MotionCheckDataMouse.LastPos = this.m_MotionCheckDataMouse.CurrentPos;
  409. this.m_MotionCheckDataMouse.LastVec = this.m_MotionCheckDataMouse.NowVec;
  410. this.m_MotionCheckDataMouse.EmmitAdjust(this.m_HorizontalColor, this.m_VerticalColor);
  411. }
  412. if (isOK || isEnd || timer >= case_data.EndTime || this.ForceEnd)
  413. {
  414. break;
  415. }
  416. }
  417. yield return null;
  418. }
  419. foreach (ActionCase.ActionType key in case_data.Action)
  420. {
  421. this.m_AllGuidUIInfo[key].NeedGuid = false;
  422. }
  423. if (this.m_MotionCheckDataVR.Count > 0)
  424. {
  425. foreach (KeyValuePair<OvrMgr.OvrObject.Controller, MotionAction_Mgr.NeedCheckData> keyValuePair2 in this.m_MotionCheckDataVR)
  426. {
  427. UnityEngine.Object.Destroy(keyValuePair2.Value.MotionEffect.gameObject);
  428. }
  429. }
  430. else
  431. {
  432. UnityEngine.Object.Destroy(this.m_CheckHand);
  433. }
  434. if (!this.m_IsMotionCheckOnly)
  435. {
  436. if (isOK)
  437. {
  438. base.StartCoroutine(this.FaceChange(case_data, timer));
  439. base.StartCoroutine(this.EffectCheck(case_data, true));
  440. }
  441. }
  442. else
  443. {
  444. if (!GameMain.Instance.VRMode)
  445. {
  446. Cursor.lockState = cursole_state;
  447. Cursor.visible = cursole_visible;
  448. }
  449. this.m_IsMotionCheckOnly = false;
  450. MotionAction_Mgr.IsCaptureOK = isOK;
  451. if (isOK)
  452. {
  453. GameMain.Instance.SoundMgr.PlaySe("SE008.ogg", false);
  454. Utility.CreatePrefab(base.transform.parent.gameObject, "SceneDance/Rhythm_Action/Prefab/" + this.m_EffectName, true);
  455. yield return new WaitForSeconds(this.m_WaitTime);
  456. }
  457. NDebug.Assert(!string.IsNullOrEmpty(this.m_CheckEndLabel), "MotionAction_Mgr.cs:判定終了後に飛ぶラベルが設定されてません");
  458. if (!this.ForceEnd)
  459. {
  460. GameMain.Instance.ScriptMgr.adv_kag.JumpLabel(this.m_CheckEndLabel);
  461. GameMain.Instance.ScriptMgr.adv_kag.Exec();
  462. }
  463. }
  464. yield break;
  465. yield break;
  466. }
  467. private bool ActionJudge(MotionAction_Mgr.NeedCheckData checkdata, Vector3 last_pos, Vector3 pos, ActionCase.ActionType action)
  468. {
  469. bool result = false;
  470. checkdata.IsExistMovement = ((pos - last_pos).magnitude >= this.m_MovementRange);
  471. Vector3 vector = Vector3.zero;
  472. if (this.m_ControllerParent)
  473. {
  474. vector = this.m_ControllerParent.InverseTransformPoint(GameMain.Instance.MainCamera.GetRealHeadTransform().position);
  475. }
  476. switch (action)
  477. {
  478. case ActionCase.ActionType.wave:
  479. if (this.m_MotionCheckDataVR.Count > 0)
  480. {
  481. if (checkdata.FirstPos.x > this.m_WaveLength)
  482. {
  483. if (pos.x < 0f)
  484. {
  485. checkdata.FirstPos.x = pos.x;
  486. }
  487. }
  488. else
  489. {
  490. if (checkdata.IsExistMovement)
  491. {
  492. result = (pos.x >= this.m_WaveLength);
  493. }
  494. this.m_AllGuidUIInfo[action].GuidUI.fillAmount = 1f - (this.m_WaveLength - pos.x) / (this.m_WaveLength + Mathf.Abs(checkdata.FirstPos.x));
  495. }
  496. }
  497. else if (checkdata.FirstPos.x > (float)UICamera.ScreenWidth * (1f - this.m_MouseWaveRate))
  498. {
  499. if (pos.x < (float)UICamera.ScreenWidth * (1f - this.m_MouseWaveRate))
  500. {
  501. checkdata.FirstPos.x = pos.x;
  502. }
  503. }
  504. else
  505. {
  506. if (checkdata.IsExistMovement)
  507. {
  508. result = (pos.x - checkdata.FirstPos.x >= (float)UICamera.ScreenWidth * this.m_MouseWaveRate);
  509. }
  510. this.m_AllGuidUIInfo[action].GuidUI.fillAmount = (pos.x - checkdata.FirstPos.x) / ((float)UICamera.ScreenWidth * this.m_MouseWaveRate);
  511. }
  512. break;
  513. case ActionCase.ActionType.up:
  514. if (this.m_MotionCheckDataVR.Count > 0)
  515. {
  516. if (checkdata.FirstPos.y - vector.y >= this.m_UpLength)
  517. {
  518. if (pos.y - vector.y < -this.m_UpLength)
  519. {
  520. checkdata.FirstPos.y = pos.y;
  521. }
  522. }
  523. else
  524. {
  525. if (checkdata.IsExistMovement)
  526. {
  527. result = (pos.y - vector.y >= this.m_UpLength);
  528. }
  529. float num = vector.y + this.m_UpLength - checkdata.FirstPos.y;
  530. this.m_AllGuidUIInfo[action].GuidUI.fillAmount = 1f - (vector.y + this.m_UpLength - pos.y) / num;
  531. }
  532. }
  533. else if (checkdata.FirstPos.y > (float)UICamera.ScreenHeight * (1f - this.m_MouseUpRate))
  534. {
  535. if (pos.y < (float)UICamera.ScreenHeight * (1f - this.m_MouseUpRate))
  536. {
  537. checkdata.FirstPos.y = pos.y;
  538. }
  539. }
  540. else
  541. {
  542. if (checkdata.IsExistMovement)
  543. {
  544. result = (pos.y - checkdata.FirstPos.y >= (float)UICamera.ScreenHeight * this.m_MouseUpRate);
  545. }
  546. this.m_AllGuidUIInfo[action].GuidUI.fillAmount = (pos.y - checkdata.FirstPos.y) / ((float)UICamera.ScreenHeight * this.m_MouseUpRate);
  547. }
  548. break;
  549. case ActionCase.ActionType.swing:
  550. case ActionCase.ActionType.shake:
  551. {
  552. checkdata.NowVec = (pos - last_pos).normalized;
  553. if (!checkdata.IsExistMovement)
  554. {
  555. return false;
  556. }
  557. float num2 = Vector3.Dot(checkdata.NowVec, checkdata.LastVec);
  558. if (num2 < 0f)
  559. {
  560. float num3 = Mathf.Cos(this.m_JudgeLine * 0.017453292f);
  561. bool flag;
  562. if (this.m_MotionCheckDataVR.Count > 0)
  563. {
  564. Vector3 lhs = checkdata.Controller.hand_trans.localRotation * Vector3.right;
  565. lhs.Normalize();
  566. if (action == ActionCase.ActionType.swing)
  567. {
  568. flag = (Mathf.Abs(Vector3.Dot(lhs, checkdata.NowVec)) > num3);
  569. }
  570. else
  571. {
  572. flag = (Mathf.Abs(Vector3.Dot(lhs, checkdata.NowVec)) <= num3);
  573. }
  574. }
  575. else if (action == ActionCase.ActionType.swing)
  576. {
  577. flag = (Mathf.Abs(NInput.GetAxis("Mouse X")) > Mathf.Abs(NInput.GetAxis("Mouse Y")));
  578. }
  579. else
  580. {
  581. flag = (Mathf.Abs(NInput.GetAxis("Mouse X")) <= Mathf.Abs(NInput.GetAxis("Mouse Y")));
  582. }
  583. if (flag)
  584. {
  585. if (action == ActionCase.ActionType.swing)
  586. {
  587. if (checkdata.ShakeCount[action] >= this.m_SwingCount)
  588. {
  589. result = true;
  590. }
  591. }
  592. else if (action == ActionCase.ActionType.shake && checkdata.ShakeCount[action] >= this.m_ShakeCount)
  593. {
  594. result = true;
  595. }
  596. Dictionary<ActionCase.ActionType, int> shakeCount;
  597. (shakeCount = checkdata.ShakeCount)[action] = shakeCount[action] + 1;
  598. }
  599. }
  600. if (action == ActionCase.ActionType.swing)
  601. {
  602. this.m_AllGuidUIInfo[action].GuidUI.fillAmount = 1f - (float)checkdata.ShakeCount[action] / (float)this.m_SwingCount;
  603. }
  604. else if (action == ActionCase.ActionType.shake)
  605. {
  606. this.m_AllGuidUIInfo[action].GuidUI.fillAmount = 1f - (float)checkdata.ShakeCount[action] / (float)this.m_ShakeCount;
  607. }
  608. break;
  609. }
  610. }
  611. return result;
  612. }
  613. private IEnumerator FaceChange(ActionCase case_data, float start_time)
  614. {
  615. float timer = start_time;
  616. List<Maid> target_maid = new List<Maid>();
  617. foreach (int nMaidNo in case_data.TargetMaidNo)
  618. {
  619. if (GameMain.Instance.CharacterMgr.GetMaid(nMaidNo))
  620. {
  621. target_maid.Add(GameMain.Instance.CharacterMgr.GetMaid(nMaidNo));
  622. }
  623. }
  624. bool isTouch;
  625. for (;;)
  626. {
  627. if (!RhythmAction_Mgr.Instance.IsPause)
  628. {
  629. timer += RhythmAction_Mgr.Instance.DanceDeltaTime;
  630. }
  631. bool face_allend = true;
  632. isTouch = TouchAction_Mgr.Instance.IsMaidTouch();
  633. foreach (ActionCase.ReactionParam reactionParam in case_data.Reaction)
  634. {
  635. if (isTouch)
  636. {
  637. break;
  638. }
  639. if (timer <= reactionParam.SetTime)
  640. {
  641. face_allend = false;
  642. if (reactionParam.IsFaceBlend)
  643. {
  644. foreach (Maid maid in target_maid)
  645. {
  646. maid.FaceBlend(reactionParam.Name);
  647. RhythmAction_Mgr.Instance.SetMaidFaceBlendStop(maid, true);
  648. TouchAction_Mgr.Instance.GetTouchParam(maid).MotionFaceBlendChange = true;
  649. }
  650. }
  651. else
  652. {
  653. foreach (Maid maid2 in target_maid)
  654. {
  655. maid2.FaceAnime(reactionParam.Name, 1f, 0);
  656. RhythmAction_Mgr.Instance.SetMaidFaceStop(maid2, true);
  657. TouchAction_Mgr.Instance.GetTouchParam(maid2).MotionFaceChange = true;
  658. }
  659. }
  660. }
  661. else if (reactionParam.IsFaceBlend)
  662. {
  663. foreach (Maid maid3 in target_maid)
  664. {
  665. RhythmAction_Mgr.Instance.SetMaidFaceBlendStop(maid3, false);
  666. TouchAction_Mgr.Instance.GetTouchParam(maid3).MotionFaceBlendChange = false;
  667. }
  668. }
  669. else
  670. {
  671. foreach (Maid maid4 in target_maid)
  672. {
  673. RhythmAction_Mgr.Instance.SetMaidFaceStop(maid4, false);
  674. TouchAction_Mgr.Instance.GetTouchParam(maid4).MotionFaceChange = false;
  675. }
  676. }
  677. }
  678. if (face_allend || isTouch)
  679. {
  680. break;
  681. }
  682. yield return null;
  683. }
  684. foreach (Maid maid5 in target_maid)
  685. {
  686. if (!isTouch)
  687. {
  688. RhythmAction_Mgr.Instance.SetMaidFaceBlendStop(maid5, false);
  689. RhythmAction_Mgr.Instance.SetMaidFaceStop(maid5, false);
  690. }
  691. TouchAction_Mgr.Instance.GetTouchParam(maid5).MotionFaceBlendChange = false;
  692. TouchAction_Mgr.Instance.GetTouchParam(maid5).MotionFaceChange = false;
  693. }
  694. yield break;
  695. yield break;
  696. }
  697. private IEnumerator EffectCheck(ActionCase case_data, bool is_specifytime = true)
  698. {
  699. float timer = 0f;
  700. GameObject effect = UnityEngine.Object.Instantiate<GameObject>(case_data.Effect);
  701. effect.transform.parent = RhythmAction_Mgr.Instance.transform;
  702. effect.transform.localPosition = Vector3.zero;
  703. List<ParticleSystem> effect_part = new List<ParticleSystem>();
  704. IEnumerator enumerator = effect.transform.GetEnumerator();
  705. try
  706. {
  707. while (enumerator.MoveNext())
  708. {
  709. object obj = enumerator.Current;
  710. Transform transform = (Transform)obj;
  711. if (transform.GetComponent<ParticleSystem>())
  712. {
  713. effect_part.Add(transform.GetComponent<ParticleSystem>());
  714. RhythmAction_Mgr.Instance.AddParticleSystem(effect_part.Last<ParticleSystem>());
  715. }
  716. }
  717. }
  718. finally
  719. {
  720. IDisposable disposable;
  721. if ((disposable = (enumerator as IDisposable)) != null)
  722. {
  723. disposable.Dispose();
  724. }
  725. }
  726. for (;;)
  727. {
  728. if (!RhythmAction_Mgr.Instance.IsPause)
  729. {
  730. if (is_specifytime)
  731. {
  732. timer += RhythmAction_Mgr.Instance.DanceDeltaTime;
  733. }
  734. bool flag;
  735. if (is_specifytime)
  736. {
  737. flag = (timer >= case_data.EffectTime);
  738. }
  739. else
  740. {
  741. flag = effect_part.All((ParticleSystem particle) => !particle.isPlaying);
  742. }
  743. bool flag2 = flag;
  744. if (flag2)
  745. {
  746. break;
  747. }
  748. }
  749. yield return null;
  750. }
  751. UnityEngine.Object.Destroy(effect);
  752. foreach (ParticleSystem particle2 in effect_part)
  753. {
  754. RhythmAction_Mgr.Instance.RemoveParticleSystem(particle2);
  755. }
  756. yield break;
  757. yield break;
  758. }
  759. public override void StartAction()
  760. {
  761. base.StartCoroutine(this.CheckActionCase());
  762. }
  763. public override void EndAction()
  764. {
  765. base.StopAllCoroutines();
  766. }
  767. public void ResponceInit(KagTagSupport tag_data)
  768. {
  769. if (tag_data.IsValid("label"))
  770. {
  771. this.m_CheckEndLabel = tag_data.GetTagProperty("label").AsString();
  772. }
  773. if (tag_data.IsValid("forcemouse"))
  774. {
  775. this.m_IsForceMouseCheck = tag_data.GetTagProperty("forcemouse").AsBool();
  776. }
  777. this.Initialize();
  778. ActionCase actionCase = new ActionCase();
  779. this.m_IsMotionCheckOnly = true;
  780. if (tag_data.IsValid("action"))
  781. {
  782. foreach (string value in tag_data.GetTagProperty("action").AsString().Split(new char[]
  783. {
  784. ':'
  785. }))
  786. {
  787. actionCase.Action.Add((ActionCase.ActionType)Enum.Parse(typeof(ActionCase.ActionType), value));
  788. }
  789. }
  790. if (tag_data.IsValid("time"))
  791. {
  792. actionCase.EndTime = tag_data.GetTagProperty("time").AsReal();
  793. }
  794. base.StartCoroutine(this.MotionCheck(actionCase, 0f));
  795. }
  796. public static void ResponceStart(KagTagSupport tag_data)
  797. {
  798. GameObject gameObject = Utility.CreatePrefab(null, "SceneDance/Rhythm_Action/Prefab/MCMotionCapture", false);
  799. gameObject.GetComponentInChildren<MotionAction_Mgr>().ResponceInit(tag_data);
  800. }
  801. public static void CaptureFlagRecet()
  802. {
  803. MotionAction_Mgr.IsCaptureOK = false;
  804. }
  805. private List<ActionCase> m_ActionAllCase = new List<ActionCase>();
  806. [SerializeField]
  807. [Header("これ以上の動きがなかった場合は無視")]
  808. [Range(0f, 1f)]
  809. private float m_MovementRange = 0.1f;
  810. [SerializeField]
  811. [Header("コントローラーの補正値(高いほどswingやshakeを満たしやすくなる)")]
  812. [Range(0f, 15f)]
  813. private float m_ControllerAdjust = 4f;
  814. [SerializeField]
  815. [Header("この距離分手を横に動かすとアクション「wave」を満たす")]
  816. private float m_WaveLength = 10f;
  817. [SerializeField]
  818. [Header("この距離分手を上げるとアクション「up」を満たす")]
  819. private float m_UpLength = 10f;
  820. [SerializeField]
  821. [Header("この回数分手を横に振るとアクション「swing」を満たす")]
  822. private int m_SwingCount = 20;
  823. [SerializeField]
  824. [Header("この回数分手を縦に振るとアクション「shake」を満たす")]
  825. private int m_ShakeCount = 20;
  826. [SerializeField]
  827. [Header("縦振りか横振りかの判定基準")]
  828. [Range(0f, 90f)]
  829. private float m_JudgeLine = 30f;
  830. [SerializeField]
  831. [Header("アクションガイドUIの設置間隔")]
  832. private float m_SetGuidSpace = 384f;
  833. private Dictionary<OvrMgr.OvrObject.Controller, MotionAction_Mgr.NeedCheckData> m_MotionCheckDataVR = new Dictionary<OvrMgr.OvrObject.Controller, MotionAction_Mgr.NeedCheckData>();
  834. private MotionAction_Mgr.NeedCheckData m_MotionCheckDataMouse = new MotionAction_Mgr.NeedCheckData();
  835. private Transform m_ControllerParent;
  836. [SerializeField]
  837. [Header("各アクション毎のガイドUI")]
  838. private List<MotionAction_Mgr.GuidUIInfo> m_GuidUIList;
  839. private Dictionary<ActionCase.ActionType, MotionAction_Mgr.GuidUIInfo> m_AllGuidUIInfo = new Dictionary<ActionCase.ActionType, MotionAction_Mgr.GuidUIInfo>();
  840. [SerializeField]
  841. private string m_strHandName = "Sticklight";
  842. [SerializeField]
  843. [Header("マウスでモーション判定する時の手の相対位置")]
  844. private Vector3 m_HandRelatePos;
  845. [SerializeField]
  846. [Header("手の初期角度")]
  847. private Vector3 m_HandAngle;
  848. [SerializeField]
  849. [Header("手のサイズ")]
  850. private Vector3 m_HandSize = Vector3.one * 0.5f;
  851. private GameObject m_CheckHand;
  852. [SerializeField]
  853. [Header("手の横移動範囲(VR時)")]
  854. private float m_HandMoveWidth = 0.25f;
  855. [SerializeField]
  856. [Header("手の縦移動範囲(VR時)")]
  857. private float m_HandMoveHeight = 0.15f;
  858. [SerializeField]
  859. [Range(0f, 1f)]
  860. [Header("解像度のこの割合分マウスを横に動かすとアクション「wave」を満たす")]
  861. private float m_MouseWaveRate = 0.25f;
  862. [SerializeField]
  863. [Range(0f, 1f)]
  864. [Header("解像度のこの割合分マウスを上げるとアクション「up」を満たす")]
  865. private float m_MouseUpRate = 0.5f;
  866. [SerializeField]
  867. [Header("手の移動速度(VR時)")]
  868. private float m_HandMoveSpeed = 20f;
  869. [SerializeField]
  870. [Header("エフェクト位置の補正値")]
  871. [Range(0f, 1f)]
  872. private float m_EffectAdjust = 0.125f;
  873. [SerializeField]
  874. private Color m_HorizontalColor = Color.green;
  875. [SerializeField]
  876. private Color m_VerticalColor = Color.red;
  877. [SerializeField]
  878. private float m_WaitTime = 2.5f;
  879. private bool m_IsMotionCheckOnly;
  880. private string m_CheckEndLabel = string.Empty;
  881. [SerializeField]
  882. private bool m_IsForceMouseCheck;
  883. [SerializeField]
  884. private string m_EffectName = "love";
  885. [HideInInspector]
  886. public bool ForceEnd;
  887. private class NeedCheckData
  888. {
  889. public ParticleSystem MotionEffect { get; private set; }
  890. public void Init()
  891. {
  892. this.ShakeCount.Add(ActionCase.ActionType.shake, 0);
  893. this.ShakeCount.Add(ActionCase.ActionType.swing, 0);
  894. GameObject gameObject = Resources.Load<GameObject>("SceneDance/Rhythm_Action/Prefab/MotionEffect");
  895. gameObject = UnityEngine.Object.Instantiate<GameObject>(gameObject);
  896. this.MotionEffect = gameObject.GetComponent<ParticleSystem>();
  897. if (!GameMain.Instance.VRMode)
  898. {
  899. ParticleSystem.MainModule mainModule;
  900. this.MotionEffect.main.startSizeMultiplier = mainModule.startSizeMultiplier / 2f;
  901. }
  902. }
  903. public void EmmitAdjust(Color horizontal, Color vertical)
  904. {
  905. Vector3 nowVec = this.NowVec;
  906. if (this.IsExistMovement)
  907. {
  908. nowVec.z = 0f;
  909. nowVec.Normalize();
  910. nowVec.x = Mathf.Abs(nowVec.x);
  911. nowVec.y = Mathf.Abs(nowVec.y);
  912. }
  913. else
  914. {
  915. nowVec.x = (nowVec.y = 0f);
  916. }
  917. float num = nowVec.x / (nowVec.x + nowVec.y);
  918. this.MotionEffect.main.startColor = num * horizontal + (1f - num) * vertical;
  919. }
  920. public Vector3 LastVec = Vector3.zero;
  921. public Vector3 NowVec = Vector3.zero;
  922. public Vector3 LastPos = Vector3.zero;
  923. public Dictionary<ActionCase.ActionType, int> ShakeCount = new Dictionary<ActionCase.ActionType, int>();
  924. public Quaternion LastRot = Quaternion.identity;
  925. public Vector3 FirstPos = Vector3.zero;
  926. public Vector3 CurrentPos = Vector3.zero;
  927. public OvrMgr.OvrObject.Controller Controller;
  928. public bool IsExistMovement;
  929. }
  930. [Serializable]
  931. private class GuidUIInfo
  932. {
  933. public bool NeedGuid
  934. {
  935. get
  936. {
  937. return this.m_GuidActive;
  938. }
  939. set
  940. {
  941. if (this.m_GuidActive == value)
  942. {
  943. return;
  944. }
  945. this.m_GuidActive = value;
  946. this.GuidUI.gameObject.SetActive(value);
  947. int a = (!this.m_GuidActive) ? (MotionAction_Mgr.GuidUIInfo.CurrentActionCount - 1) : (MotionAction_Mgr.GuidUIInfo.CurrentActionCount + 1);
  948. MotionAction_Mgr.GuidUIInfo.CurrentActionCount = Mathf.Max(a, 0);
  949. }
  950. }
  951. public static int CurrentActionCount;
  952. public ActionCase.ActionType Type;
  953. public UIBasicSprite GuidUI;
  954. private bool m_GuidActive;
  955. }
  956. }