AR Design
UBC EML collab with UBC SALA - visualizing IoT data in AR
MixedRealityCameraManager.cs
Go to the documentation of this file.
1 // Copyright (c) Microsoft Corporation. All rights reserved.
2 // Licensed under the MIT License. See LICENSE in the project root for license information.
3 
4 using UnityEngine;
5 
6 #if UNITY_WSA && UNITY_2017_2_OR_NEWER
7 using UnityEngine.XR.WSA;
8 #endif
9 
10 namespace HoloToolkit.Unity.InputModule
11 {
18  public class MixedRealityCameraManager : Singleton<MixedRealityCameraManager>
19  {
20  [Tooltip("The near clipping plane distance for an opaque display.")]
21  public float NearClipPlane_OpaqueDisplay = 0.1f;
22 
23  [Tooltip("Values for Camera.clearFlags, determining what to clear when rendering a Camera for an opaque display.")]
24  public CameraClearFlags CameraClearFlags_OpaqueDisplay = CameraClearFlags.Skybox;
25 
26  [Tooltip("Background color for a transparent display.")]
27  public Color BackgroundColor_OpaqueDisplay = Color.black;
28 
29  [Tooltip("Set the desired quality for your application for opaque display.")]
30  public int OpaqueQualityLevel;
31 
32  [Tooltip("The near clipping plane distance for a transparent display.")]
33  public float NearClipPlane_TransparentDisplay = 0.85f;
34 
35  [Tooltip("Values for Camera.clearFlags, determining what to clear when rendering a Camera for an opaque display.")]
36  public CameraClearFlags CameraClearFlags_TransparentDisplay = CameraClearFlags.SolidColor;
37 
38  [Tooltip("Background color for a transparent display.")]
39  public Color BackgroundColor_TransparentDisplay = Color.clear;
40 
41  [Tooltip("Set the desired quality for your application for HoloLens.")]
43 
44  public enum DisplayType
45  {
46  Opaque = 0,
47  Transparent
48  };
49 
50  public DisplayType CurrentDisplayType { get; private set; }
51 
52  public delegate void DisplayEventHandler(DisplayType displayType);
57  public event DisplayEventHandler OnDisplayDetected;
58 
59  private void Start()
60  {
61  CurrentDisplayType = DisplayType.Opaque;
62 
63 #if UNITY_WSA
64 #if UNITY_2017_2_OR_NEWER
65  if (!HolographicSettings.IsDisplayOpaque)
66 #endif
67  {
68  CurrentDisplayType = DisplayType.Transparent;
69  }
70 #endif
71 
72  if (CurrentDisplayType == DisplayType.Opaque)
73  {
74  ApplySettingsForOpaqueDisplay();
75  }
76  else
77  {
78  ApplySettingsForTransparentDisplay();
79  }
80 
81  if (OnDisplayDetected != null)
82  {
83  OnDisplayDetected(CurrentDisplayType);
84  }
85  }
86 
88  {
89  Debug.Log("Display is Opaque");
90  CameraCache.Main.clearFlags = CameraClearFlags_OpaqueDisplay;
91  CameraCache.Main.nearClipPlane = NearClipPlane_OpaqueDisplay;
92  CameraCache.Main.backgroundColor = BackgroundColor_OpaqueDisplay;
93  SetQuality(OpaqueQualityLevel);
94  }
95 
97  {
98  Debug.Log("Display is Transparent");
99  CameraCache.Main.clearFlags = CameraClearFlags_TransparentDisplay;
100  CameraCache.Main.backgroundColor = BackgroundColor_TransparentDisplay;
101  CameraCache.Main.nearClipPlane = NearClipPlane_TransparentDisplay;
102  SetQuality(HoloLensQualityLevel);
103  }
104 
105  private static void SetQuality(int level)
106  {
107  QualitySettings.SetQualityLevel(level, false);
108  }
109  }
110 }
DisplayEventHandler OnDisplayDetected
Event is fired when a display is detected. DisplayType enum value tells you if display is Opaque Vs T...
This script tells you if your head mounted display (HMD) is a transparent device or an occluded devic...
The purpose of this class is to provide a cached reference to the main camera. Calling Camera...
Definition: CameraCache.cs:12
static Camera Main
Returns a cached reference to the main camera and uses Camera.main if it hasn&#39;t been cached yet...
Definition: CameraCache.cs:20
Singleton behaviour class, used for components that should only have one instance.
Definition: Singleton.cs:14