using UnityEngine; using Valve.VR; using System; using OpenVRUtil; using UnityEngine.UI; using UnityEngine.EventSystems; public class DashboardOverlay : MonoBehaviour { public new Camera camera; public RenderTexture renderTexture; public GraphicRaycaster graphicRaycaster; public EventSystem eventSystem; private ulong dashboardHandle = OpenVR.k_ulOverlayHandleInvalid; private ulong thumbnailHandle = OpenVR.k_ulOverlayHandleInvalid; private void Start() { OpenVRUtil.System.InitOpenVR(); (dashboardHandle, thumbnailHandle) = Overlay.CreateDashboardOverlay("f3.beamy.dash", "Beamy Panel"); var filePath = Application.streamingAssetsPath + "/potionGroundy.png"; Overlay.SetOverlayFromFile(thumbnailHandle, filePath); renderTexture = new RenderTexture(1024, 768, 16, RenderTextureFormat.ARGBFloat); camera.targetTexture = renderTexture; Overlay.SetOverlaySize(dashboardHandle, 2.5f); Overlay.FlipOverlayVertical(dashboardHandle); var mouseScalingFactor = new HmdVector2_t() { v0 = renderTexture.width, v1 = renderTexture.height }; var error = OpenVR.Overlay.SetOverlayMouseScale(dashboardHandle, ref mouseScalingFactor); if (error != EVROverlayError.None) { throw new Exception("Failed to set mouse scaling factor: " + error); } } private void Update() { Overlay.SetOverlayRenderTexture(dashboardHandle, renderTexture); var vrEvent = new VREvent_t(); var uncbVREvent = (uint)System.Runtime.InteropServices.Marshal.SizeOf(typeof(VREvent_t)); while (OpenVR.Overlay.PollNextOverlayEvent(dashboardHandle, ref vrEvent, uncbVREvent)) { switch ((EVREventType)vrEvent.eventType) { case EVREventType.VREvent_MouseButtonDown: Debug.Log($"MouseDown: ({vrEvent.data.mouse.x}, {vrEvent.data.mouse.y})"); break; case EVREventType.VREvent_MouseButtonUp: Debug.Log($"MouseUp: ({vrEvent.data.mouse.x}, {vrEvent.data.mouse.y})"); break; } } } private void OnApplicationQuit() { Overlay.DestroyOverlay(dashboardHandle); } private void OnDestroy() { OpenVRUtil.System.ShutdownOpenVR(); } private Button GetButtonByPosition(Vector2 position) { // Return button that at position.x, position.y. // If nothing, return null. return null; } }