-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathCameraFocusController.cs
50 lines (43 loc) · 1.38 KB
/
CameraFocusController.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
using UnityEngine;
using System.Collections;
using Vuforia;
public class CameraFocusController : MonoBehaviour {
private bool mVuforiaStarted = false;
void Start ()
{
VuforiaARController vuforia = VuforiaARController.Instance;
if (vuforia != null)
vuforia.RegisterVuforiaStartedCallback(StartAfterVuforia);
}
private void StartAfterVuforia()
{
mVuforiaStarted = true;
SetAutofocus();
}
void OnApplicationPause(bool pause)
{
if (!pause)
{
// App resumed
if (mVuforiaStarted)
{
// App resumed and vuforia already started
// but lets start it again...
SetAutofocus(); // This is done because some android devices lose the auto focus after resume
// this was a bug in vuforia 4 and 5. I haven't checked 6, but the code is harmless anyway
}
}
}
private void SetAutofocus()
{
if (CameraDevice.Instance.SetFocusMode(CameraDevice.FocusMode.FOCUS_MODE_CONTINUOUSAUTO))
{
Debug.Log("Autofocus set");
}
else
{
// never actually seen a device that doesn't support this, but just in case
Debug.Log("this device doesn't support auto focus");
}
}
}