Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update CameraCache failure case + perf #10714

Merged
merged 2 commits into from
Jul 7, 2022
Merged
Show file tree
Hide file tree
Changes from all 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
6 changes: 3 additions & 3 deletions Assets/MRTK/Core/Utilities/CameraCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,22 +31,22 @@ public static Camera Main
}

// If the cached camera is null, search for main
var mainCamera = Camera.main;
Camera mainCamera = Camera.main;

if (mainCamera == null)
{
Debug.Log("No main camera found. Searching for cameras in the scene.");

// If no main camera was found, try to determine one.
Camera[] cameras = GameObject.FindObjectsOfType<Camera>();
Camera[] cameras = Object.FindObjectsOfType<Camera>();
if (cameras.Length == 0)
{
Debug.LogWarning("No cameras found. Creating a \"MainCamera\".");
mainCamera = new GameObject("Main Camera", typeof(Camera), typeof(AudioListener)) { tag = "MainCamera" }.GetComponent<Camera>();
}
else
{
Debug.LogWarning("The Mixed Reality Toolkit was unable to determine a main camera. Please tag the scene's primary camera as \"MainCamera\", in the hierarchy.");
Debug.LogError("The Mixed Reality Toolkit was unable to determine a main camera. Please tag the scene's primary camera as \"MainCamera\", in the hierarchy.");
}
}

Expand Down
13 changes: 7 additions & 6 deletions Assets/MRTK/Services/CameraSystem/MixedRealityCameraSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public bool IsOpaque
{
get
{
currentDisplayType = DisplayType.Opaque;
DisplayType currentDisplayType = DisplayType.Opaque;

IReadOnlyList<IMixedRealityCameraSettingsProvider> dataProviders = GetDataProviders<IMixedRealityCameraSettingsProvider>();
if (dataProviders.Count > 0)
Expand Down Expand Up @@ -87,7 +87,6 @@ public bool IsOpaque
/// <inheritdoc/>
public MixedRealityCameraProfile CameraProfile => ConfigurationProfile as MixedRealityCameraProfile;

private DisplayType currentDisplayType;
private bool cameraOpaqueLastFrame = false;

/// <summary>
Expand Down Expand Up @@ -140,7 +139,7 @@ public override void Initialize()
{
cameraOpaqueLastFrame = IsOpaque;

if (IsOpaque)
if (cameraOpaqueLastFrame)
{
ApplySettingsForOpaqueDisplay();
}
Expand Down Expand Up @@ -212,11 +211,13 @@ public override void Update()
{
base.Update();

if (IsOpaque != cameraOpaqueLastFrame)
bool cameraOpaqueThisFrame = IsOpaque;

if (cameraOpaqueThisFrame != cameraOpaqueLastFrame)
{
cameraOpaqueLastFrame = IsOpaque;
cameraOpaqueLastFrame = cameraOpaqueThisFrame;

if (IsOpaque)
if (cameraOpaqueThisFrame)
{
ApplySettingsForOpaqueDisplay();
}
Expand Down