VRChoices.cs 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528
  1. using System;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.Events;
  5. public class VRChoices : MonoBehaviour
  6. {
  7. private void Start()
  8. {
  9. this.m_EventText = GameMain.Instance.OvrMgr.OvrCamera.OvrEventText;
  10. NDebug.Assert(this.m_EventText != null, "EventTextが取得できませんでした。");
  11. }
  12. public void Add(string f_strText, string f_strLabel, int f_nMaidNo, VRChoices.SelectPair.Type f_type, string f_strRegionSplitOfColon, float f_fTimeOut)
  13. {
  14. ushort num = 0;
  15. if (!string.IsNullOrEmpty(f_strRegionSplitOfColon))
  16. {
  17. VRChoices.<Add>c__AnonStorey0 <Add>c__AnonStorey = new VRChoices.<Add>c__AnonStorey0();
  18. <Add>c__AnonStorey.strSplit = f_strRegionSplitOfColon.Split(new char[]
  19. {
  20. ':'
  21. });
  22. int nS;
  23. for (nS = 0; nS < <Add>c__AnonStorey.strSplit.Length; nS++)
  24. {
  25. int num2 = Array.FindIndex<KeyValuePair<string, VRChoices.Region>>(this.m_RegionPair, (KeyValuePair<string, VRChoices.Region> a) => a.Key == <Add>c__AnonStorey.strSplit[nS]);
  26. if (num2 != -1)
  27. {
  28. num |= (ushort)this.m_RegionPair[num2].Value;
  29. }
  30. else
  31. {
  32. num |= (ushort)this.m_RegionPair[0].Value;
  33. Debug.LogError("選択肢個所:" + <Add>c__AnonStorey.strSplit[nS] + " はありません。");
  34. }
  35. }
  36. if (f_nMaidNo == -1)
  37. {
  38. f_nMaidNo = 0;
  39. }
  40. }
  41. if (GameMain.Instance.OvrMgr.OvrCamera.IsNoHandController && f_type == VRChoices.SelectPair.Type.Touch)
  42. {
  43. f_type = VRChoices.SelectPair.Type.TouchToLook;
  44. }
  45. this.m_listPair.Add(new VRChoices.SelectPair(f_strText, f_strLabel, f_nMaidNo, f_type, num, f_fTimeOut));
  46. }
  47. public void Clear()
  48. {
  49. if (this.m_TouchMgr != null)
  50. {
  51. this.m_TouchMgr.Clear();
  52. }
  53. if (this.m_LookMgr != null)
  54. {
  55. this.m_LookMgr.Clear();
  56. }
  57. this.m_listPair.Clear();
  58. this.m_dicMaidLookTouch.Clear();
  59. this.m_TextSelectPair.Clear();
  60. this.TouchLookTimeCountDownStop();
  61. this.m_bTimeOutCounting = false;
  62. this.m_nBackMaidNo = -1;
  63. this.m_BackRegion = VRChoices.Region.Non;
  64. this.m_BackType = VRChoices.SelectPair.Type.Text;
  65. this.m_PairNow = null;
  66. GameMain.Instance.OvrMgr.OvrCamera.HideDummyHand(OvrCamera.DUMMY_HAND.CHOICES_TOUCH);
  67. if (this.m_SelectorText != null)
  68. {
  69. this.m_SelectorText.SelectFinalize(null);
  70. this.m_SelectorText = null;
  71. }
  72. }
  73. public void Show(int f_nTimeOutMS, string f_strTimeOutLabel, int f_nRandom)
  74. {
  75. System.Random random = new System.Random((int)(Time.realtimeSinceStartup * 10000f));
  76. if (f_nRandom != 0)
  77. {
  78. int num = this.m_listPair.Count - f_nRandom;
  79. for (int i = num; i > 0; i--)
  80. {
  81. this.m_listPair.RemoveAt(random.Next(0, this.m_listPair.Count - 1));
  82. }
  83. }
  84. this.m_SelectorText = VRSelectorMenu.CreateSelector();
  85. NDebug.Assert(this.m_SelectorText != null, "VR選択肢が取得できませんでした。");
  86. bool flag = false;
  87. bool flag2 = false;
  88. for (int j = 0; j < this.m_listPair.Count; j++)
  89. {
  90. VRChoices.SelectPair selectPair = this.m_listPair[j];
  91. if (selectPair.type == VRChoices.SelectPair.Type.Look || selectPair.type == VRChoices.SelectPair.Type.Touch || selectPair.type == VRChoices.SelectPair.Type.TouchToLook)
  92. {
  93. if (selectPair.nMaidNo == -1)
  94. {
  95. NDebug.Assert("VR選択肢、見る触るなのにメイド番号が指定されていません。", false);
  96. }
  97. List<VRChoices.SelectPair> list;
  98. if (!this.m_dicMaidLookTouch.TryGetValue(selectPair.nMaidNo, out list))
  99. {
  100. this.m_dicMaidLookTouch.Add(selectPair.nMaidNo, list = new List<VRChoices.SelectPair>());
  101. }
  102. list.Add(selectPair);
  103. if (selectPair.type == VRChoices.SelectPair.Type.Touch)
  104. {
  105. flag = true;
  106. }
  107. if (selectPair.type == VRChoices.SelectPair.Type.Look || selectPair.type == VRChoices.SelectPair.Type.TouchToLook)
  108. {
  109. flag2 = true;
  110. }
  111. }
  112. else
  113. {
  114. this.m_TextSelectPair.Add(selectPair);
  115. }
  116. }
  117. if (this.m_dicMaidLookTouch.Count != 0)
  118. {
  119. foreach (KeyValuePair<int, List<VRChoices.SelectPair>> keyValuePair in this.m_dicMaidLookTouch)
  120. {
  121. int key = keyValuePair.Key;
  122. Maid maid = GameMain.Instance.CharacterMgr.GetMaid(key);
  123. if (maid == null || !maid.Visible)
  124. {
  125. NDebug.Assert("VR選択肢でメイドが居ないか、有効ではありません。", false);
  126. }
  127. else if (maid.IsBusy)
  128. {
  129. NDebug.Assert("VR選択肢でメイドがBusyです。", false);
  130. }
  131. if (maid.body0.IsCrcBody)
  132. {
  133. MaidColliderCollect.AddCollider(maid, MaidColliderCollect.ColliderType.Crc);
  134. }
  135. else
  136. {
  137. MaidColliderCollect.AddCollider(maid, MaidColliderCollect.ColliderType.Touch);
  138. }
  139. }
  140. if (flag)
  141. {
  142. if (GameMain.Instance.VRDeviceTypeID == GameMain.VRDeviceType.NON)
  143. {
  144. SelectMessage_UI.Message_Start(string.Empty);
  145. GameMain.Instance.OvrMgr.OvrCamera.ShowUI(false);
  146. }
  147. else
  148. {
  149. this.m_SelectorText.SetSelectType(VRChoices.SelectPair.Type.Touch);
  150. this.m_SelectorText.SelectStart(new List<VRChoices.SelectPair>(), new UnityAction<VRChoices.SelectPair>(this.OnLookTouchDummySelected));
  151. }
  152. this.m_TouchMgr = new VRTouchMgr();
  153. }
  154. if (flag2)
  155. {
  156. if (GameMain.Instance.VRDeviceTypeID == GameMain.VRDeviceType.NON)
  157. {
  158. SelectMessage_UI.Message_Start(string.Empty);
  159. GameMain.Instance.OvrMgr.OvrCamera.ShowUI(false);
  160. }
  161. else
  162. {
  163. this.m_SelectorText.SetSelectType(VRChoices.SelectPair.Type.Look);
  164. this.m_SelectorText.SelectStart(new List<VRChoices.SelectPair>(), new UnityAction<VRChoices.SelectPair>(this.OnLookTouchDummySelected));
  165. }
  166. this.m_LookMgr = new VRLookMgr();
  167. }
  168. }
  169. if (this.m_TextSelectPair.Count != 0)
  170. {
  171. this.m_SelectorText.SetSelectType(VRChoices.SelectPair.Type.Text);
  172. this.m_SelectorText.SelectStart(this.m_TextSelectPair, new UnityAction<VRChoices.SelectPair>(this.OnTextSelected));
  173. }
  174. if (f_nTimeOutMS != 0 && !string.IsNullOrEmpty(f_strTimeOutLabel))
  175. {
  176. this.TimeOutCountDownStart(f_nTimeOutMS, f_strTimeOutLabel);
  177. }
  178. this.m_bFinalizing = false;
  179. }
  180. private void OnTextSelected(VRChoices.SelectPair f_SelectedPair)
  181. {
  182. this.Finalize(f_SelectedPair.strLabel);
  183. }
  184. private void OnLookTouchDummySelected(VRChoices.SelectPair f_SelectedPair)
  185. {
  186. }
  187. public void Finalize(string f_strJumpLabel)
  188. {
  189. this.m_strSelectedLabel = f_strJumpLabel;
  190. this.m_bFinalizing = true;
  191. foreach (KeyValuePair<int, List<VRChoices.SelectPair>> keyValuePair in this.m_dicMaidLookTouch)
  192. {
  193. int key = keyValuePair.Key;
  194. Maid maid = GameMain.Instance.CharacterMgr.GetMaid(key);
  195. if (maid != null)
  196. {
  197. MaidColliderCollect.RemoveColliderAll(maid);
  198. }
  199. }
  200. this.Clear();
  201. this.OnFadeEnd();
  202. }
  203. private void OnFadeEnd()
  204. {
  205. if (!string.IsNullOrEmpty(this.m_strSelectedLabel))
  206. {
  207. GameMain.Instance.ScriptMgr.adv_kag.JumpLabel(this.m_strSelectedLabel);
  208. GameMain.Instance.ScriptMgr.adv_kag.Exec();
  209. }
  210. }
  211. private VRChoices.SelectPair GetLookTouchPos(out int f_nMaidNo, out VRChoices.Region f_region, out VRChoices.SelectPair.Type f_type)
  212. {
  213. f_nMaidNo = -1;
  214. f_region = VRChoices.Region.Non;
  215. f_type = VRChoices.SelectPair.Type.Text;
  216. if (this.m_TouchMgr != null)
  217. {
  218. this.m_TouchMgr.FrameStart();
  219. }
  220. if (this.m_LookMgr != null)
  221. {
  222. this.m_LookMgr.FrameStart();
  223. }
  224. foreach (KeyValuePair<int, List<VRChoices.SelectPair>> keyValuePair in this.m_dicMaidLookTouch)
  225. {
  226. int key = keyValuePair.Key;
  227. for (int i = 0; i < keyValuePair.Value.Count; i++)
  228. {
  229. VRChoices.SelectPair pair = keyValuePair.Value[i];
  230. if (pair.type == VRChoices.SelectPair.Type.Touch)
  231. {
  232. List<KeyValuePair<VRTouchMgr.ETouchPos, VRChoices.Region>> list = this.m_TouchPosPair.FindAll((KeyValuePair<VRTouchMgr.ETouchPos, VRChoices.Region> a) => ((ushort)a.Value & pair.uRegion) != 0);
  233. for (int j = 0; j < list.Count; j++)
  234. {
  235. KeyValuePair<VRTouchMgr.ETouchPos, VRChoices.Region> keyValuePair2 = list[j];
  236. if (!keyValuePair2.Equals(default(KeyValuePair<VRTouchMgr.ETouchPos, VRChoices.Region>)))
  237. {
  238. VRTouchMgr.ETouchPos key2 = keyValuePair2.Key;
  239. for (int k = 0; k <= 1; k++)
  240. {
  241. if (this.m_TouchMgr.GetBehaviorTouch((VRTouchMgr.EHand)k, key2, VRTouchMgr.ETouchBehavior.触る, key))
  242. {
  243. f_nMaidNo = key;
  244. f_region = keyValuePair2.Value;
  245. f_type = VRChoices.SelectPair.Type.Touch;
  246. this.m_TouchMgr.FrameEnd();
  247. return pair;
  248. }
  249. }
  250. }
  251. else
  252. {
  253. NDebug.Assert("Region指定が不正です。", false);
  254. }
  255. }
  256. }
  257. else if (pair.type == VRChoices.SelectPair.Type.Look || pair.type == VRChoices.SelectPair.Type.TouchToLook)
  258. {
  259. List<KeyValuePair<VRTouchMgr.ETouchPos, VRChoices.Region>> list2 = this.m_TouchPosPair.FindAll((KeyValuePair<VRTouchMgr.ETouchPos, VRChoices.Region> a) => ((ushort)a.Value & pair.uRegion) != 0);
  260. for (int l = 0; l < list2.Count; l++)
  261. {
  262. KeyValuePair<VRTouchMgr.ETouchPos, VRChoices.Region> keyValuePair3 = list2[l];
  263. if (!keyValuePair3.Equals(default(KeyValuePair<VRTouchMgr.ETouchPos, VRChoices.Region>)))
  264. {
  265. VRTouchMgr.ETouchPos key3 = keyValuePair3.Key;
  266. VRLookMgr.State state;
  267. if (this.m_LookMgr.GetBehaviorTouch(key3, VRLookMgr.ELookBehavior.見る, key, out state))
  268. {
  269. f_nMaidNo = key;
  270. f_region = keyValuePair3.Value;
  271. f_type = VRChoices.SelectPair.Type.Look;
  272. if (pair.type == VRChoices.SelectPair.Type.TouchToLook)
  273. {
  274. f_type = VRChoices.SelectPair.Type.TouchToLook;
  275. GameMain.Instance.OvrMgr.OvrCamera.ShowDummyHand(OvrCamera.DUMMY_HAND.CHOICES_TOUCH, state.vHitPos, false);
  276. }
  277. this.m_LookMgr.FrameEnd();
  278. return pair;
  279. }
  280. }
  281. else
  282. {
  283. NDebug.Assert("Region指定が不正です。", false);
  284. }
  285. }
  286. GameMain.Instance.OvrMgr.OvrCamera.HideDummyHand(OvrCamera.DUMMY_HAND.CHOICES_TOUCH);
  287. }
  288. }
  289. }
  290. if (this.m_TouchMgr != null)
  291. {
  292. this.m_TouchMgr.FrameEnd();
  293. }
  294. if (this.m_LookMgr != null)
  295. {
  296. this.m_LookMgr.FrameEnd();
  297. }
  298. return null;
  299. }
  300. private void TouchLookTimeCountDownStart(string f_strText, float f_fTimeOut)
  301. {
  302. if (f_fTimeOut < 0f)
  303. {
  304. this.m_fTouchLookNowTime = (this.m_fTouchLookMaxTime = this.m_fTouchLookDefaultMaxTime);
  305. }
  306. else
  307. {
  308. this.m_fTouchLookMaxTime = f_fTimeOut;
  309. this.m_fTouchLookNowTime = f_fTimeOut;
  310. }
  311. this.m_EventText.SetGaugeRate(0f);
  312. this.m_EventText.Show(VREventText.TYPE.CHOICES, f_strText, 0f);
  313. }
  314. private bool TouchLookTimeCountDown()
  315. {
  316. if (!this.m_bFinalizing)
  317. {
  318. this.m_fTouchLookNowTime -= Time.deltaTime;
  319. if (this.m_fTouchLookNowTime <= 0f)
  320. {
  321. this.m_fTouchLookNowTime = 0f;
  322. this.TouchLookTimeOut();
  323. this.m_EventText.SetGaugeRate(1f);
  324. return true;
  325. }
  326. this.m_EventText.SetGaugeRate(1f - this.m_fTouchLookNowTime / this.m_fTouchLookMaxTime);
  327. }
  328. return false;
  329. }
  330. private void TouchLookTimeCountDownStop()
  331. {
  332. this.m_EventText.Hide(VREventText.TYPE.CHOICES);
  333. }
  334. private void TouchLookTimeOut()
  335. {
  336. Debug.Log("VRChoices:TouchLookTimeOut");
  337. this.TouchLookTimeCountDownStop();
  338. this.Finalize(this.m_PairNow.strLabel);
  339. }
  340. private void TimeOutCountDownStart(int f_nTimeOutMS, string f_strTimeOutLabel)
  341. {
  342. this.m_strTimeOutLabel = f_strTimeOutLabel;
  343. this.m_fTimeOutMaxTime = (float)f_nTimeOutMS / 1000f;
  344. this.m_fTimeOutNowTime = this.m_fTimeOutMaxTime;
  345. this.m_bTimeOutCounting = true;
  346. }
  347. private bool TimeOutCountDown()
  348. {
  349. if (!this.m_bFinalizing && this.m_bTimeOutCounting)
  350. {
  351. this.m_fTimeOutNowTime -= Time.deltaTime;
  352. if (this.m_fTimeOutNowTime <= 0f)
  353. {
  354. Debug.Log("VRChoices:AllTimeOut");
  355. this.Finalize(this.m_strTimeOutLabel);
  356. return true;
  357. }
  358. }
  359. return false;
  360. }
  361. private void Update()
  362. {
  363. GameMain.Instance.OvrMgr.OvrCamera.HideDummyHand(OvrCamera.DUMMY_HAND.CHOICES_TOUCH);
  364. if (!this.m_bFinalizing)
  365. {
  366. if (this.m_bTimeOutCounting && this.TimeOutCountDown())
  367. {
  368. return;
  369. }
  370. int num = -1;
  371. VRChoices.Region region = VRChoices.Region.Non;
  372. VRChoices.SelectPair.Type type = VRChoices.SelectPair.Type.Text;
  373. this.m_PairNow = this.GetLookTouchPos(out num, out region, out type);
  374. if (this.m_PairNow != null)
  375. {
  376. if ((this.m_nBackMaidNo == -1 && num != -1) || this.m_nBackMaidNo != num || this.m_BackType != type || this.m_BackRegion != region)
  377. {
  378. this.TouchLookTimeCountDownStop();
  379. if (this.m_PairNow == null)
  380. {
  381. NDebug.Assert("VR選択肢の登録が不正です。", false);
  382. }
  383. this.TouchLookTimeCountDownStart(this.m_PairNow.strText, this.m_PairNow.fTimeOut);
  384. }
  385. else if (this.m_nBackMaidNo == num)
  386. {
  387. if (this.m_BackType == type && this.m_BackRegion == region)
  388. {
  389. if (this.TouchLookTimeCountDown())
  390. {
  391. return;
  392. }
  393. }
  394. else
  395. {
  396. NDebug.Assert("VR選択肢が不正です。", false);
  397. }
  398. }
  399. else if (this.m_nBackMaidNo != -1 && num == -1)
  400. {
  401. this.m_PairNow = null;
  402. this.TouchLookTimeCountDownStop();
  403. }
  404. }
  405. else
  406. {
  407. this.TouchLookTimeCountDownStop();
  408. }
  409. this.m_nBackMaidNo = num;
  410. this.m_BackRegion = region;
  411. this.m_BackType = type;
  412. }
  413. }
  414. private readonly KeyValuePair<string, VRChoices.Region>[] m_RegionPair = new KeyValuePair<string, VRChoices.Region>[]
  415. {
  416. new KeyValuePair<string, VRChoices.Region>("頭", VRChoices.Region.Head),
  417. new KeyValuePair<string, VRChoices.Region>("胸", VRChoices.Region.Bust),
  418. new KeyValuePair<string, VRChoices.Region>("尻", VRChoices.Region.Hip),
  419. new KeyValuePair<string, VRChoices.Region>("手", VRChoices.Region.Hand)
  420. };
  421. private readonly List<KeyValuePair<VRTouchMgr.ETouchPos, VRChoices.Region>> m_TouchPosPair = new List<KeyValuePair<VRTouchMgr.ETouchPos, VRChoices.Region>>
  422. {
  423. new KeyValuePair<VRTouchMgr.ETouchPos, VRChoices.Region>(VRTouchMgr.ETouchPos.頭頂部, VRChoices.Region.Head),
  424. new KeyValuePair<VRTouchMgr.ETouchPos, VRChoices.Region>(VRTouchMgr.ETouchPos.胸, VRChoices.Region.Bust),
  425. new KeyValuePair<VRTouchMgr.ETouchPos, VRChoices.Region>(VRTouchMgr.ETouchPos.お尻, VRChoices.Region.Hip),
  426. new KeyValuePair<VRTouchMgr.ETouchPos, VRChoices.Region>(VRTouchMgr.ETouchPos.手, VRChoices.Region.Hand)
  427. };
  428. private List<VRChoices.SelectPair> m_listPair = new List<VRChoices.SelectPair>();
  429. private Dictionary<int, List<VRChoices.SelectPair>> m_dicMaidLookTouch = new Dictionary<int, List<VRChoices.SelectPair>>();
  430. private List<VRChoices.SelectPair> m_TextSelectPair = new List<VRChoices.SelectPair>();
  431. private VRTouchMgr m_TouchMgr;
  432. private VRLookMgr m_LookMgr;
  433. private float m_fTouchLookDefaultMaxTime = 2f;
  434. private float m_fTouchLookMaxTime = 2f;
  435. private float m_fTouchLookNowTime;
  436. private VREventText m_EventText;
  437. private bool m_bFinalizing = true;
  438. private bool m_bTimeOutCounting;
  439. private float m_fTimeOutMaxTime;
  440. private float m_fTimeOutNowTime;
  441. private string m_strTimeOutLabel;
  442. private VRSelectorMenu m_SelectorText;
  443. private string m_strSelectedLabel;
  444. private int m_nBackMaidNo = -1;
  445. private VRChoices.Region m_BackRegion;
  446. private VRChoices.SelectPair.Type m_BackType;
  447. private VRChoices.SelectPair m_PairNow;
  448. public enum Region
  449. {
  450. Non,
  451. Head,
  452. Bust,
  453. Hip = 4,
  454. Hand = 8
  455. }
  456. public class SelectPair
  457. {
  458. public SelectPair(string f_strText, string f_strLabel, int f_nMaidNo, VRChoices.SelectPair.Type f_type, ushort f_sRegionFlag, float f_fTimeOut = -1f)
  459. {
  460. this.strText = f_strText;
  461. this.strLabel = f_strLabel;
  462. this.nMaidNo = f_nMaidNo;
  463. this.type = f_type;
  464. this.uRegion = f_sRegionFlag;
  465. this.fTimeOut = f_fTimeOut;
  466. }
  467. public string strText;
  468. public string strLabel;
  469. public VRChoices.SelectPair.Type type;
  470. public ushort uRegion;
  471. public int nMaidNo;
  472. public float fTimeOut;
  473. public enum Type
  474. {
  475. Text,
  476. Touch,
  477. Look,
  478. TouchToLook
  479. }
  480. }
  481. }