Example #1
0
 // If the controller we are tracking changes index, update
 private void OnControllerIndexChanged(ETrackedControllerRole role, uint index)
 {
     if (_anchorDevice == MountDevice.LeftController && role == ETrackedControllerRole.LeftHand)
     {
         _anchorDevice = MountDevice.World; // This will trick the system into reattaching the overlay
     }
     else if (_anchorDevice == MountDevice.RightController && role == ETrackedControllerRole.RightHand)
     {
         _anchorDevice = MountDevice.World; // This will trick the system into reattaching the overlay
     }
 }
Example #2
0
    /// <summary>
    /// Attach the Overlay to [device] at [scale] size with offset [offset], and base position [point].
    /// [point] isn't used for HMD or World, and can be ignored.
    /// </summary>
    /// <param name="device"></param>
    /// <param name="scale"></param>
    /// <param name="offset"></param>
    /// <param name="point"></param>
    public void AttachTo(MountDevice device, float scale, Vector3 offset, MountLocation point = MountLocation.Center)
    {
        // Update Overlay Anchor position
        GetOverlayPosition();

        // Update cached values
        _anchorDevice = device;
        AnchorDevice  = device;
        _anchorPoint  = point;
        AnchorPoint   = point;
        _anchorOffset = offset;
        AnchorOffset  = offset;
        Scale         = scale;

        // Attach Overlay
        switch (device)
        {
        case MountDevice.Screen:
            _anchor = OpenVR.k_unTrackedDeviceIndexInvalid;
            OverlayReference.transform.localPosition = -offset;
            OverlayReference.transform.localRotation = Quaternion.identity;
            break;

        case MountDevice.World:
            _anchor = OpenVR.k_unTrackedDeviceIndexInvalid;
            OverlayReference.transform.localPosition = -offset;
            OverlayReference.transform.localRotation = Quaternion.identity;
            break;

        case MountDevice.LeftController:
            _anchor = HOTK_TrackedDeviceManager.Instance.LeftIndex;
            AttachToController(point, offset);
            break;

        case MountDevice.RightController:
            _anchor = HOTK_TrackedDeviceManager.Instance.RightIndex;
            AttachToController(point, offset);
            break;

        default:
            throw new ArgumentOutOfRangeException("device", device, null);
        }
    }
Example #3
0
 /// <summary>
 /// Attach the Overlay to [device] at [scale], and base position [point].
 /// [point] isn't used for HMD or World, and can be ignored.
 /// </summary>
 /// <param name="device"></param>
 /// <param name="scale"></param>
 /// <param name="point"></param>
 public void AttachTo(MountDevice device, float scale, MountLocation point = MountLocation.Center)
 {
     AttachTo(device, scale, Vector3.zero, point);
 }