OVRPlatformMenu.cs 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. using System;
  2. using UnityEngine;
  3. public class OVRPlatformMenu : MonoBehaviour
  4. {
  5. private OVRPlatformMenu.eBackButtonAction ResetAndSendAction(OVRPlatformMenu.eBackButtonAction action)
  6. {
  7. MonoBehaviour.print("ResetAndSendAction( " + action + " );");
  8. this.downCount = 0;
  9. this.upCount = 0;
  10. this.initialDownTime = -1f;
  11. this.waitForUp = false;
  12. this.ResetCursor();
  13. if (action == OVRPlatformMenu.eBackButtonAction.LONG_PRESS)
  14. {
  15. this.waitForUp = true;
  16. }
  17. return action;
  18. }
  19. private OVRPlatformMenu.eBackButtonAction HandleBackButtonState()
  20. {
  21. if (this.waitForUp)
  22. {
  23. if (Input.GetKeyDown(this.keyCode) || Input.GetKey(this.keyCode))
  24. {
  25. return OVRPlatformMenu.eBackButtonAction.NONE;
  26. }
  27. this.waitForUp = false;
  28. }
  29. if (Input.GetKeyDown(this.keyCode))
  30. {
  31. this.downCount++;
  32. if (this.downCount == 1)
  33. {
  34. this.initialDownTime = Time.realtimeSinceStartup;
  35. }
  36. }
  37. else if (this.downCount > 0)
  38. {
  39. if (Input.GetKey(this.keyCode))
  40. {
  41. if (this.downCount <= this.upCount)
  42. {
  43. this.downCount++;
  44. }
  45. float num = Time.realtimeSinceStartup - this.initialDownTime;
  46. if (num > this.shortPressDelay)
  47. {
  48. float timerRotateRatio = (num - this.shortPressDelay) / (this.longPressDelay - this.shortPressDelay);
  49. this.UpdateCursor(timerRotateRatio);
  50. }
  51. if (num > this.longPressDelay)
  52. {
  53. return this.ResetAndSendAction(OVRPlatformMenu.eBackButtonAction.LONG_PRESS);
  54. }
  55. }
  56. else
  57. {
  58. bool flag = this.initialDownTime >= 0f;
  59. if (flag)
  60. {
  61. if (this.upCount < this.downCount)
  62. {
  63. this.upCount++;
  64. }
  65. float num2 = Time.realtimeSinceStartup - this.initialDownTime;
  66. if (num2 < this.doubleTapDelay)
  67. {
  68. if (this.downCount == 2 && this.upCount == 2)
  69. {
  70. return this.ResetAndSendAction(OVRPlatformMenu.eBackButtonAction.DOUBLE_TAP);
  71. }
  72. }
  73. else if (num2 > this.shortPressDelay)
  74. {
  75. if (this.downCount == 1 && this.upCount == 1)
  76. {
  77. return this.ResetAndSendAction(OVRPlatformMenu.eBackButtonAction.SHORT_PRESS);
  78. }
  79. }
  80. else if (num2 < this.longPressDelay)
  81. {
  82. return this.ResetAndSendAction(OVRPlatformMenu.eBackButtonAction.NONE);
  83. }
  84. }
  85. }
  86. }
  87. return OVRPlatformMenu.eBackButtonAction.NONE;
  88. }
  89. private void Awake()
  90. {
  91. if (!OVRManager.isHmdPresent)
  92. {
  93. base.enabled = false;
  94. return;
  95. }
  96. if (this.cursorTimer != null && this.instantiatedCursorTimer == null)
  97. {
  98. this.instantiatedCursorTimer = UnityEngine.Object.Instantiate<GameObject>(this.cursorTimer);
  99. if (this.instantiatedCursorTimer != null)
  100. {
  101. this.cursorTimerMaterial = this.instantiatedCursorTimer.GetComponent<Renderer>().material;
  102. this.cursorTimerMaterial.SetColor("_Color", this.cursorTimerColor);
  103. this.instantiatedCursorTimer.GetComponent<Renderer>().enabled = false;
  104. }
  105. }
  106. }
  107. private void OnDestroy()
  108. {
  109. if (this.cursorTimerMaterial != null)
  110. {
  111. UnityEngine.Object.Destroy(this.cursorTimerMaterial);
  112. }
  113. }
  114. private void OnApplicationFocus(bool focusState)
  115. {
  116. }
  117. private void OnApplicationPause(bool pauseStatus)
  118. {
  119. if (!pauseStatus)
  120. {
  121. Input.ResetInputAxes();
  122. }
  123. }
  124. private void ShowConfirmQuitMenu()
  125. {
  126. this.ResetCursor();
  127. }
  128. private void ShowGlobalMenu()
  129. {
  130. }
  131. private void DoHandler(OVRPlatformMenu.eHandler handler)
  132. {
  133. if (handler == OVRPlatformMenu.eHandler.ResetCursor)
  134. {
  135. this.ResetCursor();
  136. }
  137. if (handler == OVRPlatformMenu.eHandler.ShowConfirmQuit)
  138. {
  139. this.ShowConfirmQuitMenu();
  140. }
  141. if (handler == OVRPlatformMenu.eHandler.ShowGlobalMenu)
  142. {
  143. this.ShowGlobalMenu();
  144. }
  145. }
  146. private void Update()
  147. {
  148. }
  149. private void UpdateCursor(float timerRotateRatio)
  150. {
  151. timerRotateRatio = Mathf.Clamp(timerRotateRatio, 0f, 1f);
  152. if (this.instantiatedCursorTimer != null)
  153. {
  154. this.instantiatedCursorTimer.GetComponent<Renderer>().enabled = true;
  155. float value = Mathf.Clamp(1f - timerRotateRatio, 0f, 1f);
  156. this.cursorTimerMaterial.SetFloat("_ColorRampOffset", value);
  157. Vector3 forward = Camera.main.transform.forward;
  158. Vector3 position = Camera.main.transform.position;
  159. this.instantiatedCursorTimer.transform.position = position + forward * this.fixedDepth;
  160. this.instantiatedCursorTimer.transform.forward = forward;
  161. }
  162. }
  163. private void ResetCursor()
  164. {
  165. if (this.instantiatedCursorTimer != null)
  166. {
  167. this.cursorTimerMaterial.SetFloat("_ColorRampOffset", 1f);
  168. this.instantiatedCursorTimer.GetComponent<Renderer>().enabled = false;
  169. }
  170. }
  171. public GameObject cursorTimer;
  172. public Color cursorTimerColor = new Color(0f, 0.643f, 1f, 1f);
  173. public float fixedDepth = 3f;
  174. public KeyCode keyCode = KeyCode.Escape;
  175. public OVRPlatformMenu.eHandler doubleTapHandler;
  176. public OVRPlatformMenu.eHandler shortPressHandler = OVRPlatformMenu.eHandler.ShowConfirmQuit;
  177. public OVRPlatformMenu.eHandler longPressHandler = OVRPlatformMenu.eHandler.ShowGlobalMenu;
  178. private GameObject instantiatedCursorTimer;
  179. private Material cursorTimerMaterial;
  180. private float doubleTapDelay = 0.25f;
  181. private float shortPressDelay = 0.25f;
  182. private float longPressDelay = 0.75f;
  183. private int downCount;
  184. private int upCount;
  185. private float initialDownTime = -1f;
  186. private bool waitForUp;
  187. public enum eHandler
  188. {
  189. ResetCursor,
  190. ShowGlobalMenu,
  191. ShowConfirmQuit
  192. }
  193. private enum eBackButtonAction
  194. {
  195. NONE,
  196. DOUBLE_TAP,
  197. SHORT_PRESS,
  198. LONG_PRESS
  199. }
  200. }