Skip to content

Commit 68489cf

Browse files
authored
Merge pull request #4119 from wiwei/rc1pullinto
Merge pull request #3890 from Railboy/mrtk_camera_cache_fix
2 parents 0ec310a + 898e565 commit 68489cf

File tree

4 files changed

+20
-48
lines changed

4 files changed

+20
-48
lines changed

Assets/MixedRealityToolkit/Inspectors/Profiles/MixedRealityToolkitConfigurationProfileInspector.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,4 +285,4 @@ public override void OnInspectorGUI()
285285
}
286286
}
287287
}
288-
}
288+
}

Assets/MixedRealityToolkit/Inspectors/Utilities/MixedRealityInspectorUtility.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,10 @@ public static bool CheckMixedRealityConfigured(bool showHelpBox = true)
3535
{
3636
EditorGUILayout.HelpBox("No Mixed Reality Toolkit found in scene.", MessageType.Error);
3737
}
38-
39-
return false;
4038
}
4139

42-
MixedRealityToolkit.ConfirmInitialized();
40+
// Don't proceeed
41+
return false;
4342
}
4443

4544
if (!MixedRealityToolkit.Instance.HasActiveProfile)

Assets/MixedRealityToolkit/Services/MixedRealityToolkit.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -485,6 +485,11 @@ private void InitializeServiceLocator()
485485

486486
private void EnsureMixedRealityRequirements()
487487
{
488+
if (MixedRealityPlayspace == null)
489+
{
490+
Debug.LogError("Failed to generate a MixedRealityPlayspace.");
491+
}
492+
488493
// There's lots of documented cases that if the camera doesn't start at 0,0,0, things break with the WMR SDK specifically.
489494
// We'll enforce that here, then tracking can update it to the appropriate position later.
490495
CameraCache.Main.transform.position = Vector3.zero;

Assets/MixedRealityToolkit/Utilities/CameraCache.cs

Lines changed: 12 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -20,57 +20,25 @@ public static Camera Main
2020
{
2121
get
2222
{
23-
var mainCamera = cachedCamera == null ? Refresh(Camera.main) : cachedCamera;
24-
25-
if (mainCamera == null)
23+
if (cachedCamera != null)
2624
{
27-
// No camera in the scene tagged as main. Let's search the scene for a GameObject named Main Camera
28-
var cameras = Object.FindObjectsOfType<Camera>();
29-
30-
switch (cameras.Length)
31-
{
32-
case 0:
33-
return null;
34-
case 1:
35-
mainCamera = Refresh(cameras[0]);
36-
break;
37-
default:
38-
// Search for main camera by name.
39-
for (int i = 0; i < cameras.Length; i++)
40-
{
41-
if (cameras[i].name == "Main Camera")
42-
{
43-
mainCamera = Refresh(cameras[i]);
44-
break;
45-
}
46-
}
25+
return cachedCamera;
26+
}
4727

48-
// If we still didn't find it, just set the first camera.
49-
if (mainCamera == null)
50-
{
51-
Debug.LogWarning($"No main camera found. The Mixed Reality Toolkit used {cameras[0].name} as your main.");
52-
mainCamera = Refresh(cameras[0]);
53-
}
28+
// If the cached camera is null, search for main
29+
var mainCamera = Camera.main;
5430

55-
break;
56-
}
31+
if (mainCamera == null)
32+
{ // If no main camera was found, create it now
33+
Debug.LogWarning("No main camera found. The Mixed Reality Toolkit requires at least one camera in the scene. One will be generated now.");
34+
mainCamera = new GameObject("Main Camera", typeof(Camera)) { tag = "MainCamera" }.GetComponent<Camera>();
5735
}
5836

59-
return mainCamera;
60-
}
61-
}
37+
// Cache the main camera
38+
cachedCamera = mainCamera;
6239

63-
/// <summary>
64-
/// Set the cached camera to a new reference and return it
65-
/// </summary>
66-
/// <param name="newMain">New main camera to cache</param>
67-
public static Camera Refresh(Camera newMain)
68-
{
69-
if (newMain == null)
70-
{
71-
Debug.LogWarning("A null camera was passed into CameraCache.Refresh()");
40+
return cachedCamera;
7241
}
73-
return cachedCamera = newMain;
7442
}
7543
}
7644
}

0 commit comments

Comments
 (0)