Skip to content

Commit

Permalink
Merge pull request #95 from realitycollective/feature/disableuiraycas…
Browse files Browse the repository at this point in the history
…tcamerainXR

Focus Provider updated to only create UIRaycast camera when NOT in XR
  • Loading branch information
SimonDarksideJ authored Oct 16, 2023
2 parents 023e080 + 9a73920 commit 8bd84e9
Showing 1 changed file with 2 additions and 51 deletions.
53 changes: 2 additions & 51 deletions Runtime/Input/Modules/FocusProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ public FocusProvider(string name, uint priority, BaseProfile profile, IInputServ
private readonly PointerHitResult physicsHitResult = new PointerHitResult();
private readonly PointerHitResult graphicsHitResult = new PointerHitResult();
private readonly Color[] debugPointingRayColors;
private RenderTexture uiRaycastCameraTargetTexture;
private bool didCreateUIRaycastCamera;

private IInputService inputService = null;
Expand Down Expand Up @@ -576,64 +575,17 @@ private void EnsureUiRaycastCameraSetup()

if (Camera.main.IsNull())
{
// The main camera is not available yet, so we cannot init the raycat camera
// The main camera is not available yet, so we cannot init the raycast camera
// at this time. The get-accessor of the UIRaycastCamera property will ensure
// it is set up at a later time when accessed.
return;
}

GameObject cameraObject;

var existingUiRaycastCameraObject = GameObject.Find(uiRayCastCameraName);
if (existingUiRaycastCameraObject != null)
{
cameraObject = existingUiRaycastCameraObject;
}
else
{
cameraObject = new GameObject { name = uiRayCastCameraName };
cameraObject.transform.SetParent(Camera.main.transform, false);
didCreateUIRaycastCamera = true;
}

uiRaycastCamera = cameraObject.EnsureComponent<Camera>();
uiRaycastCamera.enabled = false;
uiRaycastCamera.clearFlags = CameraClearFlags.Color;
uiRaycastCamera.backgroundColor = new Color(0, 0, 0, 1);
uiRaycastCamera.orthographic = true;
uiRaycastCamera.orthographicSize = 0.5f;
uiRaycastCamera.nearClipPlane = 0.0f;
uiRaycastCamera.farClipPlane = 1000f;
uiRaycastCamera.rect = new Rect(0, 0, 1, 1);
uiRaycastCamera.depth = 0;
uiRaycastCamera.renderingPath = RenderingPath.UsePlayerSettings;
uiRaycastCamera.useOcclusionCulling = false;
uiRaycastCamera.allowHDR = false;
uiRaycastCamera.allowMSAA = false;
uiRaycastCamera.allowDynamicResolution = false;
uiRaycastCamera.targetDisplay = 0;
uiRaycastCamera.stereoTargetEye = StereoTargetEyeMask.Both;
uiRaycastCamera.cullingMask = Camera.main.cullingMask;

if (uiRaycastCameraTargetTexture == null)
{
// Set target texture to specific pixel size so that drag thresholds are treated the same regardless of underlying
// device display resolution.
uiRaycastCameraTargetTexture = new RenderTexture(128, 128, 0);
}

uiRaycastCamera.targetTexture = uiRaycastCameraTargetTexture;
uiRaycastCamera = Camera.main;
}

private void CleanUpUiRaycastCamera()
{
if (uiRaycastCameraTargetTexture != null)
{
uiRaycastCameraTargetTexture.Destroy();
}

uiRaycastCameraTargetTexture = null;

if (didCreateUIRaycastCamera && UIRaycastCamera.gameObject.IsNotNull())
{
UIRaycastCamera.gameObject.Destroy();
Expand Down Expand Up @@ -953,7 +905,6 @@ private static void UpdatePointerRayOnHit(RayStep[] raySteps, RaycastHit physics
private void RaycastGraphics(IInteractor pointer, UnityEvents.PointerEventData graphicEventData, LayerMask[] prioritizedLayerMasks, PointerHitResult hitResult)
{
Debug.Assert(UIRaycastCamera != null, "Missing UIRaycastCamera!");
Debug.Assert(UIRaycastCamera.nearClipPlane == 0, "Near plane must be zero for raycast distances to be correct");

if (pointer.Rays == null || pointer.Rays.Length <= 0)
{
Expand Down

0 comments on commit 8bd84e9

Please sign in to comment.