using UnityEngine; using Valve.VR; using System; using OpenVRUtil; public class Beamy : MonoBehaviour { public new Camera camera; private RenderTexture renderTexture; public ETrackedControllerRole targetHand = ETrackedControllerRole.RightHand; private ulong overlayHandle = OpenVR.k_ulOverlayHandleInvalid; [Range(0, 0.5f)] public float size = 0.5f; [Range(-0.2f, 0.2f)] public float x; [Range(-0.2f, 0.2f)] public float y; [Range(-0.2f, 0.2f)] public float z; [Range(0, 360)] public int rotationX; [Range(0, 360)] public int rotationY; [Range(0, 360)] public int rotationZ; private void Start() { OpenVRUtil.System.InitOpenVR(); overlayHandle = Overlay.CreateOverlay("f3.beamy", "Beamy"); //Vertically flip the renderTexture for non-OpenGL environments Overlay.FlipOverlayVertical(overlayHandle); // Set camera.targetTexture to write the camera output to the render texture. renderTexture = new RenderTexture(512, 512, 16, RenderTextureFormat.ARGBFloat); camera.targetTexture = renderTexture; Overlay.SetOverlaySize(overlayHandle, size); Overlay.ShowOverlay(overlayHandle); } private void Update() { var position = new Vector3(x, y, z); var rotation = Quaternion.Euler(rotationX, rotationY, rotationZ); // SetOverlaySize(overlayHandle, size); // var position = new Vector3(x, y, z); // var rotation = Quaternion.Euler(rotationX, rotationY, rotationZ); // var rightControllerIndex = OpenVR.System.GetTrackedDeviceIndexForControllerRole(ETrackedControllerRole.RightHand); // if (rightControllerIndex != OpenVR.k_unTrackedDeviceIndexInvalid) { // SetOverlayTransformRelative(overlayHandle, rightControllerIndex, position, rotation); // } var controllerIndex = OpenVR.System.GetTrackedDeviceIndexForControllerRole(targetHand); if (controllerIndex != OpenVR.k_unTrackedDeviceIndexInvalid) { Overlay.SetOverlayTransformRelative(overlayHandle, controllerIndex, position, rotation); } if (!renderTexture.IsCreated()) { return; } Overlay.SetOverlayRenderTexture(overlayHandle, renderTexture); } private void OnApplicationQuit() { Overlay.DestroyOverlay(overlayHandle); } private void OnDestroy() { OpenVRUtil.System.ShutdownOpenVR(); } }