using UnityEngine; using Valve.VR; using System; using OpenVRUtil; using UnityEngine.UI; using UnityEngine.EventSystems; using System.Collections.Generic; 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); Overlay.SetOverlayMouseScale(dashboardHandle, renderTexture.width, renderTexture.height); } 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: vrEvent.data.mouse.y = renderTexture.height - vrEvent.data.mouse.y; var button = GetButtonByPosition(new Vector2(vrEvent.data.mouse.x, vrEvent.data.mouse.y)); if (button != null) { button.onClick.Invoke(); } break; } } } private void OnApplicationQuit() { Overlay.DestroyOverlay(dashboardHandle); } private void OnDestroy() { OpenVRUtil.System.ShutdownOpenVR(); } private Button GetButtonByPosition(Vector2 position) { var pointerEventData = new PointerEventData(eventSystem); pointerEventData.position = position; // List to save found elements. var raycastResultList = new List(); // Find elements at pointerEventData position then save to raycastList. graphicRaycaster.Raycast(pointerEventData, raycastResultList); // Get buttons from saved list. var raycastResult = raycastResultList.Find(element => element.gameObject.GetComponent