123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230 |
- 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<GameObject>(this.cursorTimer);
- if (this.instantiatedCursorTimer != null)
- {
- this.cursorTimerMaterial = this.instantiatedCursorTimer.GetComponent<Renderer>().material;
- this.cursorTimerMaterial.SetColor("_Color", this.cursorTimerColor);
- this.instantiatedCursorTimer.GetComponent<Renderer>().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<Renderer>().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<Renderer>().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
- }
- }
|