VRTouchMgr.cs 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. using System;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. public class VRTouchMgr
  5. {
  6. public VRTouchMgr()
  7. {
  8. this.m_hand[0] = new VRTouchMgr.Hand(VRTouchMgr.EHand.Left);
  9. this.m_hand[1] = new VRTouchMgr.Hand(VRTouchMgr.EHand.Right);
  10. }
  11. public void Clear()
  12. {
  13. this.m_hand[0].Clear();
  14. this.m_hand[1].Clear();
  15. }
  16. public void FrameStart()
  17. {
  18. for (int i = 0; i < 2; i++)
  19. {
  20. this.m_hand[i].FrameStart();
  21. }
  22. }
  23. public void FrameEnd()
  24. {
  25. for (int i = 0; i < 2; i++)
  26. {
  27. this.m_hand[i].FrameEnd();
  28. }
  29. }
  30. public bool GetBehaviorTouchDown(VRTouchMgr.EHand f_eHand, VRTouchMgr.ETouchPos f_checkPos, VRTouchMgr.ETouchBehavior f_checkBeh, int f_nMaidNo = 0)
  31. {
  32. return this.m_hand[(int)f_eHand].GetBehaviorTouchDown(f_checkPos, f_checkBeh, f_nMaidNo);
  33. }
  34. public bool GetBehaviorTouch(VRTouchMgr.EHand f_eHand, VRTouchMgr.ETouchPos f_checkPos, VRTouchMgr.ETouchBehavior f_checkBeh, int f_nMaidNo = 0)
  35. {
  36. return this.m_hand[(int)f_eHand].GetBehaviorTouch(f_checkPos, f_checkBeh, f_nMaidNo);
  37. }
  38. public bool GetBehaviorTouchOrGrab(VRTouchMgr.EHand f_eHand, VRTouchMgr.ETouchPos f_checkPos, int f_nMaidNo = 0)
  39. {
  40. return this.m_hand[(int)f_eHand].GetBehaviorTouchOrGrab(f_checkPos, f_nMaidNo);
  41. }
  42. private VRTouchMgr.Hand[] m_hand = new VRTouchMgr.Hand[2];
  43. public enum ETouchPos
  44. {
  45. 無し,
  46. 頭頂部,
  47. 髪の毛,
  48. 胸,
  49. お腹,
  50. 手,
  51. お尻,
  52. 腿,
  53. リボン,
  54. スカ\u30FCト,
  55. MAX
  56. }
  57. public enum ETouchBehavior
  58. {
  59. 無し,
  60. 触る,
  61. 掴む,
  62. MAX
  63. }
  64. public class State
  65. {
  66. public VRTouchMgr.ETouchBehavior behBef;
  67. public VRTouchMgr.ETouchBehavior behNow;
  68. }
  69. public enum EHand
  70. {
  71. Non = -1,
  72. Left,
  73. Right,
  74. MAX
  75. }
  76. private class Hand
  77. {
  78. public Hand(VRTouchMgr.EHand f_HandSide)
  79. {
  80. if (f_HandSide == VRTouchMgr.EHand.Left)
  81. {
  82. this.m_vr_obj = GameMain.Instance.OvrMgr.ovr_obj.left_controller;
  83. }
  84. else if (f_HandSide == VRTouchMgr.EHand.Right)
  85. {
  86. this.m_vr_obj = GameMain.Instance.OvrMgr.ovr_obj.right_controller;
  87. }
  88. this.m_CtrlBtn = this.m_vr_obj.controller_buttons;
  89. this.m_vr_obj.grip_collider.ClearColliderList();
  90. this.m_listCollider = this.m_vr_obj.grip_collider.collider_list;
  91. }
  92. public void Clear()
  93. {
  94. if (this.m_vr_obj != null)
  95. {
  96. this.m_vr_obj.grip_collider.ClearColliderList();
  97. }
  98. }
  99. public void FrameStart()
  100. {
  101. foreach (KeyValuePair<int, Dictionary<VRTouchMgr.ETouchPos, VRTouchMgr.State>> keyValuePair in this.m_dicState)
  102. {
  103. foreach (KeyValuePair<VRTouchMgr.ETouchPos, VRTouchMgr.State> keyValuePair2 in keyValuePair.Value)
  104. {
  105. keyValuePair2.Value.behNow = VRTouchMgr.ETouchBehavior.無し;
  106. }
  107. }
  108. VRTouchMgr.ETouchBehavior behNow = VRTouchMgr.ETouchBehavior.触る;
  109. if (this.m_CtrlBtn != null && this.m_CtrlBtn.GetPress(AVRControllerButtons.BTN.TRIGGER))
  110. {
  111. behNow = VRTouchMgr.ETouchBehavior.掴む;
  112. }
  113. OvrMgr.OvrObject ovr_obj = GameMain.Instance.OvrMgr.ovr_obj;
  114. List<GameObject> listCollider = this.m_listCollider;
  115. foreach (GameObject gameObject in listCollider)
  116. {
  117. if (!(gameObject == null))
  118. {
  119. if (gameObject.layer == 19)
  120. {
  121. bool flag = false;
  122. VRTouchMgr.ETouchPos key = VRTouchMgr.ETouchPos.無し;
  123. if (gameObject.name == "OvrTouchHit_Bip01 Spine_SCL_" || gameObject.name == "OvrGrabHit_Bip01 Spine0a_SCL_")
  124. {
  125. flag = true;
  126. key = VRTouchMgr.ETouchPos.お腹;
  127. }
  128. else if (gameObject.name == "OvrTouchHit_Mune_L_sub" || gameObject.name == "OvrTouchHit_Mune_R_sub")
  129. {
  130. flag = true;
  131. key = VRTouchMgr.ETouchPos.胸;
  132. }
  133. else if (gameObject.name == "OvrTouchHit_Bip01 Head")
  134. {
  135. flag = true;
  136. key = VRTouchMgr.ETouchPos.頭頂部;
  137. }
  138. else if (gameObject.name == "OvrTouchHit_Bip01 L Hand" || gameObject.name == "OvrTouchHit_Bip01 R Hand")
  139. {
  140. flag = true;
  141. key = VRTouchMgr.ETouchPos.手;
  142. }
  143. else if (gameObject.name == "OvrTouchHit_Bip01 Pelvis_SCL_")
  144. {
  145. flag = true;
  146. key = VRTouchMgr.ETouchPos.お尻;
  147. }
  148. if (flag)
  149. {
  150. Maid componentInParent = gameObject.GetComponentInParent<Maid>();
  151. int activeSlotNo = componentInParent.ActiveSlotNo;
  152. Dictionary<VRTouchMgr.ETouchPos, VRTouchMgr.State> dictionary;
  153. if (!this.m_dicState.TryGetValue(activeSlotNo, out dictionary))
  154. {
  155. Dictionary<VRTouchMgr.ETouchPos, VRTouchMgr.State> dictionary2 = new Dictionary<VRTouchMgr.ETouchPos, VRTouchMgr.State>();
  156. this.m_dicState[activeSlotNo] = dictionary2;
  157. dictionary = dictionary2;
  158. }
  159. VRTouchMgr.State state;
  160. if (!dictionary.TryGetValue(key, out state))
  161. {
  162. VRTouchMgr.State state2 = new VRTouchMgr.State();
  163. dictionary[key] = state2;
  164. state = state2;
  165. }
  166. state.behNow = behNow;
  167. }
  168. }
  169. }
  170. }
  171. }
  172. public void FrameEnd()
  173. {
  174. foreach (KeyValuePair<int, Dictionary<VRTouchMgr.ETouchPos, VRTouchMgr.State>> keyValuePair in this.m_dicState)
  175. {
  176. foreach (KeyValuePair<VRTouchMgr.ETouchPos, VRTouchMgr.State> keyValuePair2 in keyValuePair.Value)
  177. {
  178. keyValuePair2.Value.behBef = keyValuePair2.Value.behNow;
  179. }
  180. }
  181. }
  182. private bool GetState(int f_nMaidNo, VRTouchMgr.ETouchPos f_checkPos, out VRTouchMgr.State f_outState)
  183. {
  184. f_outState = null;
  185. Dictionary<VRTouchMgr.ETouchPos, VRTouchMgr.State> dictionary;
  186. return this.m_dicState.TryGetValue(f_nMaidNo, out dictionary) && dictionary.TryGetValue(f_checkPos, out f_outState);
  187. }
  188. public bool GetBehaviorTouchDown(VRTouchMgr.ETouchPos f_checkPos, VRTouchMgr.ETouchBehavior f_checkBeh, int f_nMaidNo = 0)
  189. {
  190. VRTouchMgr.State state;
  191. return this.GetState(f_nMaidNo, f_checkPos, out state) && (state.behNow == f_checkBeh && state.behBef != state.behNow);
  192. }
  193. public bool GetBehaviorTouch(VRTouchMgr.ETouchPos f_checkPos, VRTouchMgr.ETouchBehavior f_checkBeh, int f_nMaidNo = 0)
  194. {
  195. VRTouchMgr.State state;
  196. return this.GetState(f_nMaidNo, f_checkPos, out state) && state.behNow == f_checkBeh;
  197. }
  198. public bool GetBehaviorTouchOrGrab(VRTouchMgr.ETouchPos f_checkPos, int f_nMaidNo = 0)
  199. {
  200. VRTouchMgr.State state;
  201. return this.GetState(f_nMaidNo, f_checkPos, out state) && (state.behNow == VRTouchMgr.ETouchBehavior.触る || state.behNow == VRTouchMgr.ETouchBehavior.掴む);
  202. }
  203. private AVRControllerButtons m_CtrlBtn;
  204. private List<GameObject> m_listCollider;
  205. private Dictionary<int, Dictionary<VRTouchMgr.ETouchPos, VRTouchMgr.State>> m_dicState = new Dictionary<int, Dictionary<VRTouchMgr.ETouchPos, VRTouchMgr.State>>();
  206. private OvrMgr.OvrObject.Controller m_vr_obj;
  207. }
  208. }