Skip to content

Commit 8d60d63

Browse files
committed
Added shutdown processing of PhotoCapture instance.
1 parent 87fd89a commit 8d60d63

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

Assets/HoloLensWithOpenCVForUnityExample/Scripts/HoloLensPhotoCaptureExample.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System.Collections.Generic;
44
using UnityEngine.VR.WSA.WebCam;
55
using UnityEngine.VR.WSA.Input;
6+
using UnityEngine.EventSystems;
67

78
#if UNITY_5_3 || UNITY_5_3_OR_NEWER
89
using UnityEngine.SceneManagement;
@@ -52,6 +53,7 @@ void Start ()
5253
{
5354
m_Canvas = GameObject.Find ("PhotoCaptureCanvas");
5455
m_CanvasRenderer = m_Canvas.GetComponent<Renderer> () as Renderer;
56+
m_CanvasRenderer.enabled = false;
5557

5658
Initialize ();
5759
}
@@ -114,10 +116,14 @@ void OnStartPhotoMode (PhotoCapture.PhotoCaptureResult result)
114116

115117
void OnTappedEvent (InteractionSourceKind source, int tapCount, Ray headRay)
116118
{
119+
if (EventSystem.current.IsPointerOverGameObject ())
120+
return;
121+
117122
if (m_CapturingPhoto) {
118123
return;
119124
}
120125

126+
m_CanvasRenderer.enabled = false;
121127
m_CapturingPhoto = true;
122128
Debug.Log ("Taking picture...");
123129
m_PhotoCaptureObj.TakePhotoAsync (OnPhotoCaptured);
@@ -165,6 +171,7 @@ void OnPhotoCaptured (PhotoCapture.PhotoCaptureResult result, PhotoCaptureFrame
165171

166172
m_Texture.wrapMode = TextureWrapMode.Clamp;
167173

174+
m_CanvasRenderer.enabled = true;
168175
m_CanvasRenderer.sharedMaterial.SetTexture ("_MainTex", m_Texture);
169176
m_CanvasRenderer.sharedMaterial.SetMatrix ("_WorldToCameraMatrix", worldToCameraMatrix);
170177
m_CanvasRenderer.sharedMaterial.SetMatrix ("_CameraProjectionMatrix", projectionMatrix);
@@ -184,11 +191,20 @@ void OnPhotoCaptured (PhotoCapture.PhotoCaptureResult result, PhotoCaptureFrame
184191
m_CapturingPhoto = false;
185192
}
186193

194+
void OnStopPhotoMode (PhotoCapture.PhotoCaptureResult result)
195+
{
196+
Debug.Log ("StopPhotoMode!");
197+
m_PhotoCaptureObj.Dispose ();
198+
}
199+
187200
/// <summary>
188201
/// Raises the disable event.
189202
/// </summary>
190203
void OnDisable ()
191204
{
205+
if (m_PhotoCaptureObj != null)
206+
m_PhotoCaptureObj.StopPhotoModeAsync (OnStopPhotoMode);
207+
192208
if (m_GestureRecognizer != null && m_GestureRecognizer.IsCapturingGestures()) {
193209
m_GestureRecognizer.StopCapturingGestures ();
194210
m_GestureRecognizer.TappedEvent -= OnTappedEvent;

0 commit comments

Comments
 (0)