VRDecideUseTouch.cs 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. using System;
  2. using UnityEngine;
  3. using UnityEngine.Events;
  4. using UnityEngine.UI;
  5. public class VRDecideUseTouch : MonoBehaviour
  6. {
  7. private void Update()
  8. {
  9. if (!this.m_IsUpdate)
  10. {
  11. return;
  12. }
  13. if (GameMain.Instance == null)
  14. {
  15. return;
  16. }
  17. if (this.m_ControllerR == null || this.m_ControllerL == null)
  18. {
  19. this.m_ControllerR = GameMain.Instance.OvrMgr.ovr_obj.right_controller.controller_buttons;
  20. this.m_ControllerL = GameMain.Instance.OvrMgr.ovr_obj.left_controller.controller_buttons;
  21. }
  22. if (this.m_ControllerR == null || this.m_ControllerL == null)
  23. {
  24. return;
  25. }
  26. bool isTouchControllerPress = false;
  27. isTouchControllerPress |= this.m_ControllerR.GetPress(AVRControllerButtons.BTN.VIRTUAL_L_CLICK);
  28. isTouchControllerPress |= this.m_ControllerL.GetPress(AVRControllerButtons.BTN.VIRTUAL_L_CLICK);
  29. bool flag = this.IsPressMouse() | Input.GetKey(KeyCode.Return);
  30. string text = string.Empty;
  31. if (isTouchControllerPress)
  32. {
  33. this.m_TotalGrabTime += Time.deltaTime;
  34. this.m_TextCountDown.gameObject.SetActive(true);
  35. }
  36. else if (flag && !isTouchControllerPress)
  37. {
  38. this.m_TotalGrabTime += Time.deltaTime;
  39. this.m_TextCountDown.gameObject.SetActive(true);
  40. }
  41. if (!isTouchControllerPress && !flag)
  42. {
  43. this.m_TotalGrabTime = 0f;
  44. this.m_TextCountDown.gameObject.SetActive(false);
  45. }
  46. if (flag != this.m_BeforeMousePress || isTouchControllerPress != this.m_BeforeTouchPress)
  47. {
  48. this.m_TotalGrabTime = 0f;
  49. }
  50. float num = this.m_MaxGrabTime - this.m_TotalGrabTime;
  51. num = ((num >= 0f) ? num : 0f);
  52. if (flag && !isTouchControllerPress)
  53. {
  54. text += "マウスとキーボードを使用します\n";
  55. }
  56. else if (isTouchControllerPress)
  57. {
  58. text += "Oculus Touch を使用します\n";
  59. }
  60. text += num.ToString("0.0");
  61. this.m_TextCountDown.text = text;
  62. if (this.m_MaxGrabTime < this.m_TotalGrabTime)
  63. {
  64. this.m_IsUpdate = false;
  65. string message = string.Empty;
  66. if (flag && !isTouchControllerPress)
  67. {
  68. message = "マウスとキーボードで移動や選択をします。";
  69. }
  70. else
  71. {
  72. message = "Oculus Touch を使用します。";
  73. }
  74. VRDialogMenu dialog = VRDialogMenu.CreateDialog();
  75. VRDialogMenu.TYPE_STYLE style = (VRDialogMenu.TYPE_STYLE)12;
  76. dialog.OpenDialog(message, style, delegate(VRDialogMenu.TYPE_STYLE type)
  77. {
  78. dialog.CloseDialog();
  79. if (type == VRDialogMenu.TYPE_STYLE.OK)
  80. {
  81. if (this.m_Callback != null)
  82. {
  83. this.m_Callback(isTouchControllerPress);
  84. }
  85. VRCanvasManager.Instance.OpenVRCanvas(VRCanvasManager.VRCanvasType.MainMenu);
  86. }
  87. else
  88. {
  89. VRCanvasManager.Instance.OpenVRDecideUseTouch(this.m_Callback);
  90. }
  91. });
  92. }
  93. this.m_BeforeMousePress = flag;
  94. this.m_BeforeTouchPress = isTouchControllerPress;
  95. }
  96. private bool IsPressMouse()
  97. {
  98. bool isHandPenMode = GameMain.Instance.OvrMgr.OvrCamera.IsHandPenMode;
  99. if (NInput.GetMouseButtonDown(0))
  100. {
  101. if (isHandPenMode)
  102. {
  103. this.m_IsClick = (this.m_BeforeHandModeClick = true);
  104. }
  105. else
  106. {
  107. this.m_IsClick = true;
  108. }
  109. }
  110. if (NInput.GetMouseButton(0) && this.m_BeforeHandModeClick && !isHandPenMode)
  111. {
  112. this.m_IsClick = false;
  113. }
  114. if (NInput.GetMouseButtonUp(0))
  115. {
  116. this.m_IsClick = false;
  117. }
  118. if (this.m_ControllerR.GetPressUp(AVRControllerButtons.BTN.VIRTUAL_L_CLICK) | this.m_ControllerL.GetPressUp(AVRControllerButtons.BTN.VIRTUAL_L_CLICK))
  119. {
  120. this.m_IsClick = false;
  121. }
  122. this.m_BeforeHandModeClick = isHandPenMode;
  123. return this.m_IsClick;
  124. }
  125. public void StartDecideController(UnityAction<bool> callback_is_oculus_touch)
  126. {
  127. this.m_Callback = callback_is_oculus_touch;
  128. this.m_IsUpdate = true;
  129. this.m_BeforeMousePress = false;
  130. this.m_BeforeTouchPress = false;
  131. this.m_BeforeHandModeClick = false;
  132. this.m_IsClick = false;
  133. }
  134. [SerializeField]
  135. [Tooltip("カウントダウン用テキストUI")]
  136. private Text m_TextCountDown;
  137. private AVRControllerButtons m_ControllerR;
  138. private AVRControllerButtons m_ControllerL;
  139. private float m_TotalGrabTime;
  140. private float m_MaxGrabTime = 3f;
  141. private UnityAction<bool> m_Callback;
  142. private bool m_IsUpdate;
  143. private bool m_BeforeMousePress;
  144. private bool m_BeforeTouchPress;
  145. private bool m_BeforePenMode;
  146. private bool m_IsMousePress;
  147. private bool m_BeforeHandModeClick;
  148. private bool m_IsClick;
  149. }