using System; using UnityEngine; public class OVRPlatformMenu : MonoBehaviour { private OVRPlatformMenu.eBackButtonAction ResetAndSendAction(OVRPlatformMenu.eBackButtonAction action) { MonoBehaviour.print("ResetAndSendAction( " + action + " );"); this.downCount = 0; this.upCount = 0; this.initialDownTime = -1f; this.waitForUp = false; this.ResetCursor(); if (action == OVRPlatformMenu.eBackButtonAction.LONG_PRESS) { this.waitForUp = true; } return action; } private OVRPlatformMenu.eBackButtonAction HandleBackButtonState() { if (this.waitForUp) { if (Input.GetKeyDown(this.keyCode) || Input.GetKey(this.keyCode)) { return OVRPlatformMenu.eBackButtonAction.NONE; } this.waitForUp = false; } if (Input.GetKeyDown(this.keyCode)) { this.downCount++; if (this.downCount == 1) { this.initialDownTime = Time.realtimeSinceStartup; } } else if (this.downCount > 0) { if (Input.GetKey(this.keyCode)) { if (this.downCount <= this.upCount) { this.downCount++; } float num = Time.realtimeSinceStartup - this.initialDownTime; if (num > this.shortPressDelay) { float timerRotateRatio = (num - this.shortPressDelay) / (this.longPressDelay - this.shortPressDelay); this.UpdateCursor(timerRotateRatio); } if (num > this.longPressDelay) { return this.ResetAndSendAction(OVRPlatformMenu.eBackButtonAction.LONG_PRESS); } } else { bool flag = this.initialDownTime >= 0f; if (flag) { if (this.upCount < this.downCount) { this.upCount++; } float num2 = Time.realtimeSinceStartup - this.initialDownTime; if (num2 < this.doubleTapDelay) { if (this.downCount == 2 && this.upCount == 2) { return this.ResetAndSendAction(OVRPlatformMenu.eBackButtonAction.DOUBLE_TAP); } } else if (num2 > this.shortPressDelay) { if (this.downCount == 1 && this.upCount == 1) { return this.ResetAndSendAction(OVRPlatformMenu.eBackButtonAction.SHORT_PRESS); } } else if (num2 < this.longPressDelay) { return this.ResetAndSendAction(OVRPlatformMenu.eBackButtonAction.NONE); } } } } return OVRPlatformMenu.eBackButtonAction.NONE; } private void Awake() { if (!OVRManager.isHmdPresent) { base.enabled = false; return; } if (this.cursorTimer != null && this.instantiatedCursorTimer == null) { this.instantiatedCursorTimer = UnityEngine.Object.Instantiate(this.cursorTimer); if (this.instantiatedCursorTimer != null) { this.cursorTimerMaterial = this.instantiatedCursorTimer.GetComponent().material; this.cursorTimerMaterial.SetColor("_Color", this.cursorTimerColor); this.instantiatedCursorTimer.GetComponent().enabled = false; } } } private void OnDestroy() { if (this.cursorTimerMaterial != null) { UnityEngine.Object.Destroy(this.cursorTimerMaterial); } } private void OnApplicationFocus(bool focusState) { } private void OnApplicationPause(bool pauseStatus) { if (!pauseStatus) { Input.ResetInputAxes(); } } private void ShowConfirmQuitMenu() { this.ResetCursor(); } private void ShowGlobalMenu() { } private void DoHandler(OVRPlatformMenu.eHandler handler) { if (handler == OVRPlatformMenu.eHandler.ResetCursor) { this.ResetCursor(); } if (handler == OVRPlatformMenu.eHandler.ShowConfirmQuit) { this.ShowConfirmQuitMenu(); } if (handler == OVRPlatformMenu.eHandler.ShowGlobalMenu) { this.ShowGlobalMenu(); } } private void Update() { } private void UpdateCursor(float timerRotateRatio) { timerRotateRatio = Mathf.Clamp(timerRotateRatio, 0f, 1f); if (this.instantiatedCursorTimer != null) { this.instantiatedCursorTimer.GetComponent().enabled = true; float value = Mathf.Clamp(1f - timerRotateRatio, 0f, 1f); this.cursorTimerMaterial.SetFloat("_ColorRampOffset", value); Vector3 forward = Camera.main.transform.forward; Vector3 position = Camera.main.transform.position; this.instantiatedCursorTimer.transform.position = position + forward * this.fixedDepth; this.instantiatedCursorTimer.transform.forward = forward; } } private void ResetCursor() { if (this.instantiatedCursorTimer != null) { this.cursorTimerMaterial.SetFloat("_ColorRampOffset", 1f); this.instantiatedCursorTimer.GetComponent().enabled = false; } } public GameObject cursorTimer; public Color cursorTimerColor = new Color(0f, 0.643f, 1f, 1f); public float fixedDepth = 3f; public KeyCode keyCode = KeyCode.Escape; public OVRPlatformMenu.eHandler doubleTapHandler; public OVRPlatformMenu.eHandler shortPressHandler = OVRPlatformMenu.eHandler.ShowConfirmQuit; public OVRPlatformMenu.eHandler longPressHandler = OVRPlatformMenu.eHandler.ShowGlobalMenu; private GameObject instantiatedCursorTimer; private Material cursorTimerMaterial; private float doubleTapDelay = 0.25f; private float shortPressDelay = 0.25f; private float longPressDelay = 0.75f; private int downCount; private int upCount; private float initialDownTime = -1f; private bool waitForUp; public enum eHandler { ResetCursor, ShowGlobalMenu, ShowConfirmQuit } private enum eBackButtonAction { NONE, DOUBLE_TAP, SHORT_PRESS, LONG_PRESS } }