VRChoices.cs 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521
  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. MaidColliderCollect.AddCollider(maid, MaidColliderCollect.ColliderType.Touch);
  132. }
  133. if (flag)
  134. {
  135. if (GameMain.Instance.VRDeviceTypeID == GameMain.VRDeviceType.NON)
  136. {
  137. SelectMessage_UI.Message_Start(string.Empty);
  138. GameMain.Instance.OvrMgr.OvrCamera.ShowUI(false);
  139. }
  140. else
  141. {
  142. this.m_SelectorText.SetSelectType(VRChoices.SelectPair.Type.Touch);
  143. this.m_SelectorText.SelectStart(new List<VRChoices.SelectPair>(), new UnityAction<VRChoices.SelectPair>(this.OnLookTouchDummySelected));
  144. }
  145. this.m_TouchMgr = new VRTouchMgr();
  146. }
  147. if (flag2)
  148. {
  149. if (GameMain.Instance.VRDeviceTypeID == GameMain.VRDeviceType.NON)
  150. {
  151. SelectMessage_UI.Message_Start(string.Empty);
  152. GameMain.Instance.OvrMgr.OvrCamera.ShowUI(false);
  153. }
  154. else
  155. {
  156. this.m_SelectorText.SetSelectType(VRChoices.SelectPair.Type.Look);
  157. this.m_SelectorText.SelectStart(new List<VRChoices.SelectPair>(), new UnityAction<VRChoices.SelectPair>(this.OnLookTouchDummySelected));
  158. }
  159. this.m_LookMgr = new VRLookMgr();
  160. }
  161. }
  162. if (this.m_TextSelectPair.Count != 0)
  163. {
  164. this.m_SelectorText.SetSelectType(VRChoices.SelectPair.Type.Text);
  165. this.m_SelectorText.SelectStart(this.m_TextSelectPair, new UnityAction<VRChoices.SelectPair>(this.OnTextSelected));
  166. }
  167. if (f_nTimeOutMS != 0 && !string.IsNullOrEmpty(f_strTimeOutLabel))
  168. {
  169. this.TimeOutCountDownStart(f_nTimeOutMS, f_strTimeOutLabel);
  170. }
  171. this.m_bFinalizing = false;
  172. }
  173. private void OnTextSelected(VRChoices.SelectPair f_SelectedPair)
  174. {
  175. this.Finalize(f_SelectedPair.strLabel);
  176. }
  177. private void OnLookTouchDummySelected(VRChoices.SelectPair f_SelectedPair)
  178. {
  179. }
  180. public void Finalize(string f_strJumpLabel)
  181. {
  182. this.m_strSelectedLabel = f_strJumpLabel;
  183. this.m_bFinalizing = true;
  184. foreach (KeyValuePair<int, List<VRChoices.SelectPair>> keyValuePair in this.m_dicMaidLookTouch)
  185. {
  186. int key = keyValuePair.Key;
  187. Maid maid = GameMain.Instance.CharacterMgr.GetMaid(key);
  188. if (maid != null)
  189. {
  190. MaidColliderCollect.RemoveColliderAll(maid);
  191. }
  192. }
  193. this.Clear();
  194. this.OnFadeEnd();
  195. }
  196. private void OnFadeEnd()
  197. {
  198. if (!string.IsNullOrEmpty(this.m_strSelectedLabel))
  199. {
  200. GameMain.Instance.ScriptMgr.adv_kag.JumpLabel(this.m_strSelectedLabel);
  201. GameMain.Instance.ScriptMgr.adv_kag.Exec();
  202. }
  203. }
  204. private VRChoices.SelectPair GetLookTouchPos(out int f_nMaidNo, out VRChoices.Region f_region, out VRChoices.SelectPair.Type f_type)
  205. {
  206. f_nMaidNo = -1;
  207. f_region = VRChoices.Region.Non;
  208. f_type = VRChoices.SelectPair.Type.Text;
  209. if (this.m_TouchMgr != null)
  210. {
  211. this.m_TouchMgr.FrameStart();
  212. }
  213. if (this.m_LookMgr != null)
  214. {
  215. this.m_LookMgr.FrameStart();
  216. }
  217. foreach (KeyValuePair<int, List<VRChoices.SelectPair>> keyValuePair in this.m_dicMaidLookTouch)
  218. {
  219. int key = keyValuePair.Key;
  220. for (int i = 0; i < keyValuePair.Value.Count; i++)
  221. {
  222. VRChoices.SelectPair pair = keyValuePair.Value[i];
  223. if (pair.type == VRChoices.SelectPair.Type.Touch)
  224. {
  225. List<KeyValuePair<VRTouchMgr.ETouchPos, VRChoices.Region>> list = this.m_TouchPosPair.FindAll((KeyValuePair<VRTouchMgr.ETouchPos, VRChoices.Region> a) => ((ushort)a.Value & pair.uRegion) != 0);
  226. for (int j = 0; j < list.Count; j++)
  227. {
  228. KeyValuePair<VRTouchMgr.ETouchPos, VRChoices.Region> keyValuePair2 = list[j];
  229. if (!keyValuePair2.Equals(default(KeyValuePair<VRTouchMgr.ETouchPos, VRChoices.Region>)))
  230. {
  231. VRTouchMgr.ETouchPos key2 = keyValuePair2.Key;
  232. for (int k = 0; k <= 1; k++)
  233. {
  234. if (this.m_TouchMgr.GetBehaviorTouch((VRTouchMgr.EHand)k, key2, VRTouchMgr.ETouchBehavior.触る, key))
  235. {
  236. f_nMaidNo = key;
  237. f_region = keyValuePair2.Value;
  238. f_type = VRChoices.SelectPair.Type.Touch;
  239. this.m_TouchMgr.FrameEnd();
  240. return pair;
  241. }
  242. }
  243. }
  244. else
  245. {
  246. NDebug.Assert("Region指定が不正です。", false);
  247. }
  248. }
  249. }
  250. else if (pair.type == VRChoices.SelectPair.Type.Look || pair.type == VRChoices.SelectPair.Type.TouchToLook)
  251. {
  252. List<KeyValuePair<VRTouchMgr.ETouchPos, VRChoices.Region>> list2 = this.m_TouchPosPair.FindAll((KeyValuePair<VRTouchMgr.ETouchPos, VRChoices.Region> a) => ((ushort)a.Value & pair.uRegion) != 0);
  253. for (int l = 0; l < list2.Count; l++)
  254. {
  255. KeyValuePair<VRTouchMgr.ETouchPos, VRChoices.Region> keyValuePair3 = list2[l];
  256. if (!keyValuePair3.Equals(default(KeyValuePair<VRTouchMgr.ETouchPos, VRChoices.Region>)))
  257. {
  258. VRTouchMgr.ETouchPos key3 = keyValuePair3.Key;
  259. VRLookMgr.State state;
  260. if (this.m_LookMgr.GetBehaviorTouch(key3, VRLookMgr.ELookBehavior.見る, key, out state))
  261. {
  262. f_nMaidNo = key;
  263. f_region = keyValuePair3.Value;
  264. f_type = VRChoices.SelectPair.Type.Look;
  265. if (pair.type == VRChoices.SelectPair.Type.TouchToLook)
  266. {
  267. f_type = VRChoices.SelectPair.Type.TouchToLook;
  268. GameMain.Instance.OvrMgr.OvrCamera.ShowDummyHand(OvrCamera.DUMMY_HAND.CHOICES_TOUCH, state.vHitPos, false);
  269. }
  270. this.m_LookMgr.FrameEnd();
  271. return pair;
  272. }
  273. }
  274. else
  275. {
  276. NDebug.Assert("Region指定が不正です。", false);
  277. }
  278. }
  279. GameMain.Instance.OvrMgr.OvrCamera.HideDummyHand(OvrCamera.DUMMY_HAND.CHOICES_TOUCH);
  280. }
  281. }
  282. }
  283. if (this.m_TouchMgr != null)
  284. {
  285. this.m_TouchMgr.FrameEnd();
  286. }
  287. if (this.m_LookMgr != null)
  288. {
  289. this.m_LookMgr.FrameEnd();
  290. }
  291. return null;
  292. }
  293. private void TouchLookTimeCountDownStart(string f_strText, float f_fTimeOut)
  294. {
  295. if (f_fTimeOut < 0f)
  296. {
  297. this.m_fTouchLookNowTime = (this.m_fTouchLookMaxTime = this.m_fTouchLookDefaultMaxTime);
  298. }
  299. else
  300. {
  301. this.m_fTouchLookMaxTime = f_fTimeOut;
  302. this.m_fTouchLookNowTime = f_fTimeOut;
  303. }
  304. this.m_EventText.SetGaugeRate(0f);
  305. this.m_EventText.Show(VREventText.TYPE.CHOICES, f_strText, 0f);
  306. }
  307. private bool TouchLookTimeCountDown()
  308. {
  309. if (!this.m_bFinalizing)
  310. {
  311. this.m_fTouchLookNowTime -= Time.deltaTime;
  312. if (this.m_fTouchLookNowTime <= 0f)
  313. {
  314. this.m_fTouchLookNowTime = 0f;
  315. this.TouchLookTimeOut();
  316. this.m_EventText.SetGaugeRate(1f);
  317. return true;
  318. }
  319. this.m_EventText.SetGaugeRate(1f - this.m_fTouchLookNowTime / this.m_fTouchLookMaxTime);
  320. }
  321. return false;
  322. }
  323. private void TouchLookTimeCountDownStop()
  324. {
  325. this.m_EventText.Hide(VREventText.TYPE.CHOICES);
  326. }
  327. private void TouchLookTimeOut()
  328. {
  329. Debug.Log("VRChoices:TouchLookTimeOut");
  330. this.TouchLookTimeCountDownStop();
  331. this.Finalize(this.m_PairNow.strLabel);
  332. }
  333. private void TimeOutCountDownStart(int f_nTimeOutMS, string f_strTimeOutLabel)
  334. {
  335. this.m_strTimeOutLabel = f_strTimeOutLabel;
  336. this.m_fTimeOutMaxTime = (float)f_nTimeOutMS / 1000f;
  337. this.m_fTimeOutNowTime = this.m_fTimeOutMaxTime;
  338. this.m_bTimeOutCounting = true;
  339. }
  340. private bool TimeOutCountDown()
  341. {
  342. if (!this.m_bFinalizing && this.m_bTimeOutCounting)
  343. {
  344. this.m_fTimeOutNowTime -= Time.deltaTime;
  345. if (this.m_fTimeOutNowTime <= 0f)
  346. {
  347. Debug.Log("VRChoices:AllTimeOut");
  348. this.Finalize(this.m_strTimeOutLabel);
  349. return true;
  350. }
  351. }
  352. return false;
  353. }
  354. private void Update()
  355. {
  356. GameMain.Instance.OvrMgr.OvrCamera.HideDummyHand(OvrCamera.DUMMY_HAND.CHOICES_TOUCH);
  357. if (!this.m_bFinalizing)
  358. {
  359. if (this.m_bTimeOutCounting && this.TimeOutCountDown())
  360. {
  361. return;
  362. }
  363. int num = -1;
  364. VRChoices.Region region = VRChoices.Region.Non;
  365. VRChoices.SelectPair.Type type = VRChoices.SelectPair.Type.Text;
  366. this.m_PairNow = this.GetLookTouchPos(out num, out region, out type);
  367. if (this.m_PairNow != null)
  368. {
  369. if ((this.m_nBackMaidNo == -1 && num != -1) || this.m_nBackMaidNo != num || this.m_BackType != type || this.m_BackRegion != region)
  370. {
  371. this.TouchLookTimeCountDownStop();
  372. if (this.m_PairNow == null)
  373. {
  374. NDebug.Assert("VR選択肢の登録が不正です。", false);
  375. }
  376. this.TouchLookTimeCountDownStart(this.m_PairNow.strText, this.m_PairNow.fTimeOut);
  377. }
  378. else if (this.m_nBackMaidNo == num)
  379. {
  380. if (this.m_BackType == type && this.m_BackRegion == region)
  381. {
  382. if (this.TouchLookTimeCountDown())
  383. {
  384. return;
  385. }
  386. }
  387. else
  388. {
  389. NDebug.Assert("VR選択肢が不正です。", false);
  390. }
  391. }
  392. else if (this.m_nBackMaidNo != -1 && num == -1)
  393. {
  394. this.m_PairNow = null;
  395. this.TouchLookTimeCountDownStop();
  396. }
  397. }
  398. else
  399. {
  400. this.TouchLookTimeCountDownStop();
  401. }
  402. this.m_nBackMaidNo = num;
  403. this.m_BackRegion = region;
  404. this.m_BackType = type;
  405. }
  406. }
  407. private readonly KeyValuePair<string, VRChoices.Region>[] m_RegionPair = new KeyValuePair<string, VRChoices.Region>[]
  408. {
  409. new KeyValuePair<string, VRChoices.Region>("頭", VRChoices.Region.Head),
  410. new KeyValuePair<string, VRChoices.Region>("胸", VRChoices.Region.Bust),
  411. new KeyValuePair<string, VRChoices.Region>("尻", VRChoices.Region.Hip),
  412. new KeyValuePair<string, VRChoices.Region>("手", VRChoices.Region.Hand)
  413. };
  414. private readonly List<KeyValuePair<VRTouchMgr.ETouchPos, VRChoices.Region>> m_TouchPosPair = new List<KeyValuePair<VRTouchMgr.ETouchPos, VRChoices.Region>>
  415. {
  416. new KeyValuePair<VRTouchMgr.ETouchPos, VRChoices.Region>(VRTouchMgr.ETouchPos.頭頂部, VRChoices.Region.Head),
  417. new KeyValuePair<VRTouchMgr.ETouchPos, VRChoices.Region>(VRTouchMgr.ETouchPos.胸, VRChoices.Region.Bust),
  418. new KeyValuePair<VRTouchMgr.ETouchPos, VRChoices.Region>(VRTouchMgr.ETouchPos.お尻, VRChoices.Region.Hip),
  419. new KeyValuePair<VRTouchMgr.ETouchPos, VRChoices.Region>(VRTouchMgr.ETouchPos.手, VRChoices.Region.Hand)
  420. };
  421. private List<VRChoices.SelectPair> m_listPair = new List<VRChoices.SelectPair>();
  422. private Dictionary<int, List<VRChoices.SelectPair>> m_dicMaidLookTouch = new Dictionary<int, List<VRChoices.SelectPair>>();
  423. private List<VRChoices.SelectPair> m_TextSelectPair = new List<VRChoices.SelectPair>();
  424. private VRTouchMgr m_TouchMgr;
  425. private VRLookMgr m_LookMgr;
  426. private float m_fTouchLookDefaultMaxTime = 2f;
  427. private float m_fTouchLookMaxTime = 2f;
  428. private float m_fTouchLookNowTime;
  429. private VREventText m_EventText;
  430. private bool m_bFinalizing = true;
  431. private bool m_bTimeOutCounting;
  432. private float m_fTimeOutMaxTime;
  433. private float m_fTimeOutNowTime;
  434. private string m_strTimeOutLabel;
  435. private VRSelectorMenu m_SelectorText;
  436. private string m_strSelectedLabel;
  437. private int m_nBackMaidNo = -1;
  438. private VRChoices.Region m_BackRegion;
  439. private VRChoices.SelectPair.Type m_BackType;
  440. private VRChoices.SelectPair m_PairNow;
  441. public enum Region
  442. {
  443. Non,
  444. Head,
  445. Bust,
  446. Hip = 4,
  447. Hand = 8
  448. }
  449. public class SelectPair
  450. {
  451. public SelectPair(string f_strText, string f_strLabel, int f_nMaidNo, VRChoices.SelectPair.Type f_type, ushort f_sRegionFlag, float f_fTimeOut = -1f)
  452. {
  453. this.strText = f_strText;
  454. this.strLabel = f_strLabel;
  455. this.nMaidNo = f_nMaidNo;
  456. this.type = f_type;
  457. this.uRegion = f_sRegionFlag;
  458. this.fTimeOut = f_fTimeOut;
  459. }
  460. public string strText;
  461. public string strLabel;
  462. public VRChoices.SelectPair.Type type;
  463. public ushort uRegion;
  464. public int nMaidNo;
  465. public float fTimeOut;
  466. public enum Type
  467. {
  468. Text,
  469. Touch,
  470. Look,
  471. TouchToLook
  472. }
  473. }
  474. }