OvrControllerBehavior.cs 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584
  1. using System;
  2. using System.Collections;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. public class OvrControllerBehavior : AVRControllerBehavior
  6. {
  7. public override AVRControllerBehavior.BEH_TYPE BehaviourType
  8. {
  9. get
  10. {
  11. return AVRControllerBehavior.BEH_TYPE.LEGACY;
  12. }
  13. }
  14. public override bool HandCameraMode
  15. {
  16. get
  17. {
  18. return this.m_eMode == OvrControllerBehavior.OvrControllerMode.CAMERA;
  19. }
  20. set
  21. {
  22. if (value)
  23. {
  24. this.ChangeMode(OvrControllerBehavior.OvrControllerMode.CAMERA);
  25. }
  26. }
  27. }
  28. public override bool IsHandCameraMode
  29. {
  30. get
  31. {
  32. return this.m_eMode == OvrControllerBehavior.OvrControllerMode.CAMERA;
  33. }
  34. }
  35. public override bool IsHandPenMode
  36. {
  37. get
  38. {
  39. return false;
  40. }
  41. }
  42. public override bool HandDanceMode
  43. {
  44. get
  45. {
  46. return this.m_bHandDanceMode && this.m_eMode == OvrControllerBehavior.OvrControllerMode.DANCE;
  47. }
  48. set
  49. {
  50. this.m_bHandDanceMode = value;
  51. if (value)
  52. {
  53. this.ChangeMode(OvrControllerBehavior.OvrControllerMode.DANCE);
  54. }
  55. else if (!value && this.m_eMode == OvrControllerBehavior.OvrControllerMode.DANCE)
  56. {
  57. this.ChangeMode(OvrControllerBehavior.OvrControllerMode.MOUSE_POINTER);
  58. }
  59. }
  60. }
  61. public override bool HandVRIKMode
  62. {
  63. get
  64. {
  65. return false;
  66. }
  67. set
  68. {
  69. }
  70. }
  71. public override bool HandYotogiMode
  72. {
  73. get
  74. {
  75. return false;
  76. }
  77. set
  78. {
  79. }
  80. }
  81. protected override void Awake()
  82. {
  83. base.Awake();
  84. GameMain.Instance.CMSystem.OvrPointerMode = Mathf.Max(Mathf.Min(0, GameMain.Instance.CMSystem.OvrPointerMode), 0);
  85. GameMain.Instance.CMSystem.OvrMoveMode = Mathf.Max(Mathf.Min(2, GameMain.Instance.CMSystem.OvrMoveMode), 0);
  86. this.m_txMode = base.transform.Find("UI/Canvas/Text").GetComponent<Text>();
  87. this.m_goHandCamera = base.transform.Find("HandCamera").gameObject;
  88. this.m_HandCamera = this.m_goHandCamera.GetComponent<OvrHandCamera>();
  89. this.m_HandCamera.m_ctrl = this;
  90. this.m_goHandModel = base.transform.Find("HandPlayer").gameObject;
  91. this.m_HandAnim = this.m_goHandModel.GetComponent<OvrHandAnimator>();
  92. NDebug.Assert(this.m_HandAnim != null);
  93. this.m_HandAnim.Init(this.m_buttons);
  94. this.m_HandItem = base.transform.Find("HandItem").GetComponent<OvrHandItemMgr>();
  95. this.m_HandItem.m_ctrl = this;
  96. this.m_HandItem.gameObject.SetActive(false);
  97. this.m_ArcTeleport = base.transform.Find("ArcTeleport").GetComponentInChildren<ArcTeleport>(true);
  98. this.m_ArcTeleport.SetCallBackOnMove(new ArcTeleport.dgOnMove(this.OnWarpMove));
  99. this.m_fCursorEasing = GameMain.Instance.CMSystem.OvrCursorStabilization;
  100. this.m_fCursorBoost = GameMain.Instance.CMSystem.OvrCursorBoostSpeed;
  101. this.m_fCursorLaserEasing = GameMain.Instance.CMSystem.OvrViveCursorLaserEasing;
  102. }
  103. private void Start()
  104. {
  105. GameMain.Instance.OvrMgr.OvrCamera.m_bWheelToZoom = false;
  106. if (this.m_bHandL)
  107. {
  108. this.ChangeMode(OvrControllerBehavior.OvrControllerMode.MOVE);
  109. }
  110. else
  111. {
  112. this.ChangeMode(OvrControllerBehavior.OvrControllerMode.MOUSE_POINTER);
  113. }
  114. }
  115. private void OnEnable()
  116. {
  117. this.ChangeMode(this.m_eMode);
  118. }
  119. private void OnDisable()
  120. {
  121. this.m_HandItem.gameObject.SetActive(false);
  122. }
  123. private void ChangeMode(OvrControllerBehavior.OvrControllerMode f_eNewMode)
  124. {
  125. if (f_eNewMode == OvrControllerBehavior.OvrControllerMode.GRAB)
  126. {
  127. this.m_obj_controller.grip_collider.enabled = true;
  128. }
  129. else
  130. {
  131. this.m_obj_controller.grip_collider.enabled = false;
  132. }
  133. bool flag = false;
  134. if (f_eNewMode == OvrControllerBehavior.OvrControllerMode.CAMERA)
  135. {
  136. this.m_goHandCamera.SetActive(true);
  137. flag = true;
  138. }
  139. else
  140. {
  141. this.m_goHandCamera.SetActive(false);
  142. }
  143. if (f_eNewMode == OvrControllerBehavior.OvrControllerMode.ITEM)
  144. {
  145. this.m_HandItem.gameObject.SetActive(true);
  146. flag = true;
  147. }
  148. else
  149. {
  150. this.m_HandItem.gameObject.SetActive(false);
  151. }
  152. if (flag)
  153. {
  154. this.m_goHandModel.SetActive(false);
  155. this.m_txMode.enabled = false;
  156. }
  157. else
  158. {
  159. this.m_goHandModel.SetActive(true);
  160. this.m_txMode.enabled = true;
  161. }
  162. GameMain.Instance.OvrMgr.SystemUICamera.SetActiveVirtualCursorObjByNocurrent((!this.m_bHandL) ? UICamera.VCURSOR.RIGHT : UICamera.VCURSOR.LEFT, f_eNewMode == OvrControllerBehavior.OvrControllerMode.MOUSE_POINTER);
  163. this.m_txMode.text = this.m_strMode[(int)f_eNewMode];
  164. if (f_eNewMode == OvrControllerBehavior.OvrControllerMode.MOUSE_POINTER)
  165. {
  166. Text txMode = this.m_txMode;
  167. txMode.text += this.m_strPointerMode[GameMain.Instance.CMSystem.OvrPointerMode];
  168. }
  169. else if (f_eNewMode == OvrControllerBehavior.OvrControllerMode.MOVE)
  170. {
  171. Text txMode2 = this.m_txMode;
  172. txMode2.text += this.m_strMoveMode[GameMain.Instance.CMSystem.OvrMoveMode];
  173. }
  174. this.m_eMode = f_eNewMode;
  175. Debug.Log("コントローラモード変更:" + this.m_eMode.ToString());
  176. }
  177. private void ChangePointerMode(OvrControllerBehavior.PointerSubMode f_ePMode)
  178. {
  179. GameMain.Instance.CMSystem.OvrPointerMode = (int)f_ePMode;
  180. this.ChangeMode(OvrControllerBehavior.OvrControllerMode.MOUSE_POINTER);
  181. }
  182. private void ChangeMoveMode(OvrControllerBehavior.MoveSubMode f_eSubMode)
  183. {
  184. GameMain.Instance.CMSystem.OvrMoveMode = (int)f_eSubMode;
  185. this.ChangeMode(OvrControllerBehavior.OvrControllerMode.MOVE);
  186. }
  187. private void TouchPadToClick()
  188. {
  189. if (this.m_buttons.GetPressDown(AVRControllerButtons.BTN.VIRTUAL_L_CLICK) || this.m_buttons.GetPressDown(AVRControllerButtons.BTN.VIRTUAL_R_CLICK))
  190. {
  191. this.m_bCursorMoveEnable = false;
  192. GameMain.Instance.OvrMgr.SystemUICamera.SetCurrentCursorSide((!this.m_bHandL) ? UICamera.VCURSOR.RIGHT : UICamera.VCURSOR.LEFT);
  193. if (this.m_buttons.GetPressDown(AVRControllerButtons.BTN.VIRTUAL_L_CLICK))
  194. {
  195. NUty.EmurateMouseButton(2);
  196. this.m_bPressLeft = true;
  197. }
  198. else if (this.m_buttons.GetPressDown(AVRControllerButtons.BTN.VIRTUAL_R_CLICK))
  199. {
  200. NUty.EmurateMouseButton(8);
  201. this.m_bPressLeft = false;
  202. }
  203. if (this.m_coCursorMoveWait != null)
  204. {
  205. base.StopCoroutine(this.m_coCursorMoveWait);
  206. }
  207. this.m_coCursorMoveWait = base.StartCoroutine(this.CoCursorMoveWait());
  208. }
  209. else if (this.m_buttons.GetPressUp(AVRControllerButtons.BTN.VIRTUAL_L_CLICK) || this.m_buttons.GetPressUp(AVRControllerButtons.BTN.VIRTUAL_R_CLICK))
  210. {
  211. if (this.m_bPressLeft)
  212. {
  213. NUty.EmurateMouseButton(4);
  214. }
  215. else
  216. {
  217. NUty.EmurateMouseButton(16);
  218. }
  219. }
  220. }
  221. private IEnumerator CoCursorMoveWait()
  222. {
  223. yield return new WaitForSeconds(0.3f);
  224. this.m_bCursorMoveEnable = true;
  225. yield break;
  226. }
  227. private void TouchPadWheel()
  228. {
  229. float y = this.m_buttons.GetAxis().y;
  230. if (0.1f < Mathf.Abs(y))
  231. {
  232. if (this.m_bWheelFirst)
  233. {
  234. NUty.EmurateMouseWheel((y >= 0f) ? 1 : -1);
  235. this.m_fWheel = 0f;
  236. this.m_bWheelFirst = false;
  237. }
  238. else
  239. {
  240. this.m_fWheel += y * (Time.deltaTime * 5f);
  241. if (this.m_fWheel <= -1f || 1f <= this.m_fWheel)
  242. {
  243. NUty.EmurateMouseWheel((int)this.m_fWheel);
  244. this.m_fWheel = 0f;
  245. }
  246. }
  247. }
  248. else
  249. {
  250. this.m_bWheelFirst = true;
  251. }
  252. }
  253. private void OnWarpMove(Vector3 f_vPosWorld, Vector3 f_vRotWorld)
  254. {
  255. GameMain.Instance.MainCamera.SetFootPos(f_vPosWorld, CameraMain.STAND_SIT.STAND);
  256. GameMain.Instance.MainCamera.SetRealHeadRot(f_vRotWorld, true);
  257. }
  258. protected virtual void Update()
  259. {
  260. if (!this.m_controller.HandEnable)
  261. {
  262. return;
  263. }
  264. this.m_vMoveCam.x = (this.m_vMoveCam.y = (this.m_vMoveCam.z = (this.m_fRotCam = 0f)));
  265. this.m_vMoveVelocity.x = (this.m_vMoveVelocity.y = (this.m_vMoveVelocity.z = 0f));
  266. if (this.m_buttons.GetPressDown(AVRControllerButtons.BTN.VIRTUAL_MENU))
  267. {
  268. this.m_bPressMenuBtnLong = false;
  269. this.m_fMenuPressBeforeTime = Time.realtimeSinceStartup;
  270. }
  271. else if (this.m_buttons.GetPress(AVRControllerButtons.BTN.VIRTUAL_MENU))
  272. {
  273. if (!this.m_bPressMenuBtnLong && Time.realtimeSinceStartup - this.m_fMenuPressBeforeTime > 1f)
  274. {
  275. if (this.m_eMode == OvrControllerBehavior.OvrControllerMode.MOUSE_POINTER)
  276. {
  277. int num = GameMain.Instance.CMSystem.OvrPointerMode + 1;
  278. if (1 <= num)
  279. {
  280. num = 0;
  281. }
  282. this.ChangePointerMode((OvrControllerBehavior.PointerSubMode)num);
  283. }
  284. else if (this.m_eMode == OvrControllerBehavior.OvrControllerMode.MOVE)
  285. {
  286. int num2 = GameMain.Instance.CMSystem.OvrMoveMode + 1;
  287. if (3 <= num2)
  288. {
  289. num2 = 0;
  290. }
  291. this.ChangeMoveMode((OvrControllerBehavior.MoveSubMode)num2);
  292. }
  293. else if (this.m_eMode == OvrControllerBehavior.OvrControllerMode.ITEM)
  294. {
  295. this.m_HandItem.NextModel();
  296. }
  297. this.m_bPressMenuBtnLong = true;
  298. }
  299. }
  300. else if (this.m_buttons.GetPressUp(AVRControllerButtons.BTN.VIRTUAL_MENU) && !this.m_bPressMenuBtnLong)
  301. {
  302. if (this.m_buttons.GetPress(AVRControllerButtons.BTN.MENU))
  303. {
  304. GameMain.Instance.OvrMgr.OvrCamera.ReCallcOffset();
  305. GameMain.Instance.OvrMgr.OvrCamera.ShowUI(true);
  306. GameMain.Instance.OvrMgr.OvrCamera.UIPosReset(0f);
  307. }
  308. else
  309. {
  310. int num3 = (int)(this.m_eMode + 1);
  311. if (num3 == 5 && !this.m_bHandDanceMode)
  312. {
  313. num3++;
  314. }
  315. if (6 <= num3)
  316. {
  317. num3 = 0;
  318. }
  319. this.ChangeMode((OvrControllerBehavior.OvrControllerMode)num3);
  320. }
  321. }
  322. if (this.m_eMode == OvrControllerBehavior.OvrControllerMode.MOUSE_POINTER)
  323. {
  324. if (GameMain.Instance.CMSystem.OvrPointerMode == 0)
  325. {
  326. RaycastHit raycastHit;
  327. if (this.m_bCursorMoveEnable && Physics.Raycast(base.transform.position, base.transform.rotation * Vector3.forward, out raycastHit, float.PositiveInfinity, 33554432))
  328. {
  329. Vector2 textureCoord = raycastHit.textureCoord;
  330. Vector2 a = new Vector2(1280f * ((textureCoord.x - this.m_fUiCursorMargin) / (1f - this.m_fUiCursorMargin * 2f)), 720f * ((textureCoord.y - this.m_fUiCursorMargin) / (1f - this.m_fUiCursorMargin * 2f)));
  331. Vector2 vector = GameMain.Instance.OvrMgr.SystemUICamera.GetOvrVirtualMousePos(this.m_bHandL);
  332. Vector2 a2 = a - vector;
  333. Vector2 b = a2 * this.m_fCursorLaserEasing;
  334. Vector2 v = vector + b;
  335. GameMain.Instance.OvrMgr.SystemUICamera.SetOvrVirtualMousePos(this.m_bHandL, v);
  336. }
  337. Debug.DrawLine(base.transform.position, base.transform.position + base.transform.rotation * (Vector3.forward * 10f), new Color(1f, 0f, 0f));
  338. this.TouchPadToClick();
  339. this.TouchPadWheel();
  340. if (this.m_buttons.GetPressDown(AVRControllerButtons.BTN.GRIP))
  341. {
  342. GameMain.Instance.OvrMgr.OvrCamera.ToggleUI();
  343. }
  344. }
  345. }
  346. else if (this.m_eMode == OvrControllerBehavior.OvrControllerMode.MOVE)
  347. {
  348. if (GameMain.Instance.CMSystem.OvrMoveMode == 0)
  349. {
  350. Vector2 vector2 = this.m_buttons.GetAxis() * this.m_fMoveSpeed;
  351. if (this.m_buttons.GetPress(AVRControllerButtons.BTN.TRIGGER))
  352. {
  353. this.m_vMoveCam.y = vector2.y;
  354. }
  355. else if (this.m_buttons.GetPress(AVRControllerButtons.BTN.GRIP))
  356. {
  357. this.m_fRotCam = vector2.x;
  358. }
  359. else
  360. {
  361. this.m_vMoveCam.x = -vector2.x;
  362. this.m_vMoveCam.z = vector2.y;
  363. }
  364. }
  365. else if (GameMain.Instance.CMSystem.OvrMoveMode == 2)
  366. {
  367. }
  368. }
  369. else if (this.m_eMode == OvrControllerBehavior.OvrControllerMode.CAMERA)
  370. {
  371. if (this.m_buttons.GetPressDown(AVRControllerButtons.BTN.TRIGGER))
  372. {
  373. this.m_HandCamera.Snap();
  374. }
  375. if (this.m_buttons.GetPressDown(AVRControllerButtons.BTN.STICK_PAD))
  376. {
  377. GameMain.Instance.OvrMgr.OvrCamera.ToggleUI();
  378. }
  379. }
  380. }
  381. public override Vector3 GetVelocityHand()
  382. {
  383. Vector3 result = default(Vector3);
  384. if (this.m_eMode == OvrControllerBehavior.OvrControllerMode.MOVE && GameMain.Instance.CMSystem.OvrMoveMode == 1)
  385. {
  386. if (this.m_buttons.GetPressDown(AVRControllerButtons.BTN.GRIP))
  387. {
  388. this.m_vMoveTugPosBack = base.transform.position;
  389. }
  390. else if (this.m_buttons.GetPress(AVRControllerButtons.BTN.GRIP))
  391. {
  392. if (this.m_goTestObj != null)
  393. {
  394. this.m_goTestObj.transform.position = base.transform.position;
  395. }
  396. Vector3 a = base.transform.position - this.m_vMoveTugPosBack;
  397. result = a * -1f;
  398. }
  399. }
  400. return result;
  401. }
  402. public override float GetRotHandY()
  403. {
  404. float num = 0f;
  405. if (this.m_eMode == OvrControllerBehavior.OvrControllerMode.MOVE && GameMain.Instance.CMSystem.OvrMoveMode == 1)
  406. {
  407. if (this.m_buttons.GetPressDown(AVRControllerButtons.BTN.STICK_PAD))
  408. {
  409. Transform baseHeadTransform = GameMain.Instance.OvrMgr.OvrCamera.GetBaseHeadTransform();
  410. Vector3 position = baseHeadTransform.position;
  411. position.y = 0f;
  412. Vector3 vector = baseHeadTransform.rotation * Vector3.forward;
  413. vector.y = 0f;
  414. Vector3 position2 = base.transform.position;
  415. position2.y = 0f;
  416. Vector3 vector2 = position2 - position;
  417. this.m_fRotBack = Quaternion.FromToRotation(vector.normalized, vector2.normalized).eulerAngles.y;
  418. }
  419. else if (this.m_buttons.GetPress(AVRControllerButtons.BTN.STICK_PAD))
  420. {
  421. Transform baseHeadTransform2 = GameMain.Instance.OvrMgr.OvrCamera.GetBaseHeadTransform();
  422. Vector3 position3 = baseHeadTransform2.position;
  423. position3.y = 0f;
  424. Vector3 vector3 = baseHeadTransform2.rotation * Vector3.forward;
  425. vector3.y = 0f;
  426. Vector3 position4 = base.transform.position;
  427. position4.y = 0f;
  428. Vector3 vector4 = position4 - position3;
  429. num = Quaternion.FromToRotation(vector3.normalized, vector4.normalized).eulerAngles.y - this.m_fRotBack;
  430. num *= -1f;
  431. }
  432. }
  433. return num;
  434. }
  435. protected virtual void LateUpdate()
  436. {
  437. if (this.m_eMode == OvrControllerBehavior.OvrControllerMode.MOVE && GameMain.Instance.CMSystem.OvrMoveMode == 1 && this.m_buttons.GetPress(AVRControllerButtons.BTN.STICK_PAD))
  438. {
  439. Transform baseHeadTransform = GameMain.Instance.OvrMgr.OvrCamera.GetBaseHeadTransform();
  440. Vector3 position = baseHeadTransform.position;
  441. position.y = 0f;
  442. Vector3 vector = baseHeadTransform.rotation * Vector3.forward;
  443. vector.y = 0f;
  444. Vector3 position2 = base.transform.position;
  445. position2.y = 0f;
  446. Vector3 vector2 = position2 - position;
  447. this.m_fRotBack = Quaternion.FromToRotation(vector.normalized, vector2.normalized).eulerAngles.y;
  448. }
  449. }
  450. public float m_fPointerSpeed = 10f;
  451. public float m_fMoveSpeed = 10f;
  452. public Vector3 m_vMoveVelocity;
  453. public float m_fCursorEasing = 6f;
  454. public float m_fCursorBoost = 0.1f;
  455. public float m_fMenuPressBeforeTime;
  456. public float m_fCursorLaserEasing = 0.3f;
  457. public float m_fUiCursorMargin = 0.2f;
  458. public GameObject m_goTestObj;
  459. private readonly string[] m_strMode = new string[]
  460. {
  461. "GRAB",
  462. "POINTER",
  463. "MOVE",
  464. "CAMERA",
  465. "ITEM",
  466. "DANCE"
  467. };
  468. private readonly string[] m_strPointerMode = new string[]
  469. {
  470. "-LASER"
  471. };
  472. private readonly string[] m_strMoveMode = new string[]
  473. {
  474. "-DIR",
  475. "-DRAW",
  476. "-ARC"
  477. };
  478. [NonSerialized]
  479. private OvrControllerBehavior.OvrControllerMode m_eMode;
  480. protected bool m_bPressLeft;
  481. protected Text m_txMode;
  482. protected GameObject m_goModeCanvas;
  483. protected bool m_bPressMenuBtnLong;
  484. protected GameObject m_goHandCamera;
  485. protected OvrHandCamera m_HandCamera;
  486. protected Vector3 m_vMoveTugPosBack;
  487. protected Vector3 m_vMoveTugRotHnadPosBack;
  488. protected Vector3 m_vMoveTugRotHeadPosBack;
  489. protected Vector3 m_vMoveTugVector;
  490. protected ArcTeleport m_ArcTeleport;
  491. protected GameObject m_goHandModel;
  492. protected OvrHandAnimator m_HandAnim;
  493. protected bool m_bWheelFirst;
  494. protected float m_fWheel;
  495. protected OvrHandItemMgr m_HandItem;
  496. protected bool m_bCursorMoveEnable = true;
  497. protected float m_fRotBack;
  498. protected Coroutine m_coCursorMoveWait;
  499. private enum OvrControllerMode
  500. {
  501. GRAB,
  502. MOUSE_POINTER,
  503. MOVE,
  504. CAMERA,
  505. ITEM,
  506. DANCE,
  507. MAX
  508. }
  509. private enum PointerSubMode
  510. {
  511. LASER,
  512. MAX
  513. }
  514. private enum MoveSubMode
  515. {
  516. DIRECTIONAL,
  517. DRAW,
  518. ARC,
  519. MAX
  520. }
  521. private enum TouchSubMode
  522. {
  523. MAN,
  524. WOMAN
  525. }
  526. }