Skip to content
This repository has been archived by the owner on Aug 11, 2024. It is now read-only.

Fixed a few things with the new camera rig #405

Merged
merged 16 commits into from
Nov 9, 2019
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ public Transform PlayspaceTransform
return playspaceTransform;
}

if (MixedRealityToolkit.IsApplicationQuitting)
{
return null;
}

var playspaceTransformLookup = GameObject.Find(playspaceName);

playspaceTransform = playspaceTransformLookup == null
Expand Down Expand Up @@ -60,7 +65,7 @@ public Transform PlayspaceTransform
}

/// <inheritdoc />
public Transform CameraTransform => PlayerCamera.transform;
public Transform CameraTransform => PlayerCamera == null ? null : playerCamera.transform;

[SerializeField]
private Camera playerCamera = null;
Expand All @@ -75,6 +80,11 @@ public Camera PlayerCamera
return playerCamera;
}

if (MixedRealityToolkit.IsApplicationQuitting)
{
return null;
}

// Currently the XRTK only supports a single player/user
// So for now we will always reference the tagged MainCamera.
if (playerCamera == null)
Expand Down Expand Up @@ -122,6 +132,11 @@ public TrackedPoseDriver CameraPoseDriver
return cameraPoseDriver;
}

if (MixedRealityToolkit.IsApplicationQuitting)
{
return null;
}

cameraPoseDriver = PlayerCamera.gameObject.EnsureComponent<TrackedPoseDriver>();
cameraPoseDriver.UseRelativeTransform = true;
return cameraPoseDriver;
Expand All @@ -139,6 +154,16 @@ public Transform BodyTransform
{
get
{
if (bodyTransform != null)
{
return bodyTransform;
}

if (MixedRealityToolkit.IsApplicationQuitting)
{
return null;
}

if (bodyTransform == null)
{
bodyTransform = PlayspaceTransform.Find(playerBodyName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,13 +170,15 @@ public override void Disable()
{
base.Disable();

if (CameraRig == null) { return; }
var camera = CameraCache.Main;

if (CameraRig.CameraTransform != null)
if (camera != null)
{
CameraRig.CameraTransform.SetParent(null);
camera.transform.SetParent(null);
}

if (CameraRig == null) { return; }

if (CameraRig.PlayspaceTransform != null)
{
if (Application.isPlaying)
Expand All @@ -189,7 +191,8 @@ public override void Disable()
}
}

if (CameraRig is Component component)
if (CameraRig is Component component &&
component is IMixedRealityCameraRig)
{
if (Application.isPlaying)
{
Expand Down
6 changes: 6 additions & 0 deletions XRTK-Core/Packages/com.xrtk.core/Utilities/CameraCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Licensed under the MIT License. See LICENSE in the project root for license information.

using UnityEngine;
using XRTK.Services;

namespace XRTK.Utilities
{
Expand All @@ -24,6 +25,11 @@ public static Camera Main

if (mainCamera == null)
{
if (MixedRealityToolkit.IsApplicationQuitting)
{
return null;
}

mainCamera = new GameObject("Main Camera", typeof(Camera), typeof(AudioListener)) { tag = "MainCamera" }.GetComponent<Camera>();
}

Expand Down