/************************************************************************************ Copyright : Copyright (c) Facebook Technologies, LLC and its affiliates. All rights reserved. Licensed under the Oculus Utilities SDK License Version 1.31 (the "License"); you may not use the Utilities SDK except in compliance with the License, which is provided at the time of installation or download, or which otherwise accompanies this software in either electronic or hard copy form. You may obtain a copy of the License at https://developer.oculus.com/licenses/utilities-1.31 Unless required by applicable law or agreed to in writing, the Utilities SDK distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. ************************************************************************************/ using UnityEngine; using VR = UnityEngine.VR; using System.Collections; using System.Collections.Generic; /// /// Shows the Oculus plaform UI. /// public class OVRPlatformMenu : MonoBehaviour { /// /// The key code. /// private OVRInput.RawButton inputCode = OVRInput.RawButton.Back; public enum eHandler { ShowConfirmQuit, RetreatOneLevel, }; public eHandler shortPressHandler = eHandler.ShowConfirmQuit; /// /// Callback to handle short press. Returns true if ConfirmQuit menu should be shown. /// public System.Func OnShortPress; private static Stack sceneStack = new Stack(); enum eBackButtonAction { NONE, SHORT_PRESS }; eBackButtonAction HandleBackButtonState() { eBackButtonAction action = eBackButtonAction.NONE; if (OVRInput.GetDown(inputCode)) { action = eBackButtonAction.SHORT_PRESS; } return action; } /// /// Instantiate the cursor timer /// void Awake() { if (shortPressHandler == eHandler.RetreatOneLevel && OnShortPress == null) OnShortPress = RetreatOneLevel; if (!OVRManager.isHmdPresent) { enabled = false; return; } sceneStack.Push(UnityEngine.SceneManagement.SceneManager.GetActiveScene().name); } /// /// Show the confirm quit menu /// void ShowConfirmQuitMenu() { #if UNITY_ANDROID && !UNITY_EDITOR Debug.Log("[PlatformUI-ConfirmQuit] Showing @ " + Time.time); OVRManager.PlatformUIConfirmQuit(); #endif } /// /// Sample handler for short press which retreats to the previous scene that used OVRPlatformMenu. /// private static bool RetreatOneLevel() { if (sceneStack.Count > 1) { string parentScene = sceneStack.Pop(); UnityEngine.SceneManagement.SceneManager.LoadSceneAsync (parentScene); return false; } return true; } /// /// Tests for long-press and activates global platform menu when detected. /// as per the Unity integration doc, the back button responds to "mouse 1" button down/up/etc /// void Update() { #if UNITY_ANDROID eBackButtonAction action = HandleBackButtonState(); if (action == eBackButtonAction.SHORT_PRESS) { if (OnShortPress == null || OnShortPress()) { ShowConfirmQuitMenu(); } } #endif } }