-
Notifications
You must be signed in to change notification settings - Fork 1.1k
/
CameraFocusController.cs
100 lines (84 loc) · 3.05 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
using System;
using UnityEngine.UI;
#if UNITY_IOS
using UnityEngine.XR.ARKit;
#endif // UNITY_IOS
namespace UnityEngine.XR.ARFoundation.Samples
{
[RequireComponent(typeof(ARCameraManager))]
public class CameraFocusController
#if UNITY_IOS
: ARKitAdvancedCameraConfigurationController<ARKitFocusMode, ARKitFocus>
#else
: ARKitAdvancedCameraConfigurationController
#endif
{
[SerializeField]
Slider m_LensPositionSlider;
float m_LensPosition;
public float lensPosition
{
get => m_LensPosition;
set => m_LensPosition = value;
}
#if UNITY_IOS
protected override void UpdateCachedValues(ARKitLockedCamera lockedCamera)
{
currentMode = lockedCamera.currentFocusMode;
currentValue = lockedCamera.focus;
}
protected override void PopulateSupportedModes(ARKitLockedCamera lockedCamera)
{
var supportedModes = lockedCamera.supportedFocusModes;
m_SupportedModes = new();
if ((supportedModes & ARKitFocusMode.Locked) != ARKitFocusMode.None)
{
m_SupportedModes.Add(ARKitFocusMode.Locked);
}
if ((supportedModes & ARKitFocusMode.Auto) != ARKitFocusMode.None)
{
m_SupportedModes.Add(ARKitFocusMode.Auto);
}
if ((supportedModes & ARKitFocusMode.ContinuousAuto) != ARKitFocusMode.None)
{
m_SupportedModes.Add(ARKitFocusMode.ContinuousAuto);
}
}
protected override void PopulateRanges(ARKitLockedCamera lockedCamera)
{
if (!m_LensPositionSlider)
{
return;
}
var range = lockedCamera.focusRange;
Debug.Log($"Lens Position Range: {range.minimumLensPosition}, {range.maximumLensPosition}");
// update range of lens position slider
if (m_LensPositionSlider)
{
m_LensPositionSlider.minValue = range.minimumLensPosition;
m_LensPositionSlider.maxValue = range.maximumLensPosition;
}
RefreshUI(lockedCamera.focus);
}
void RefreshUI(ARKitFocus focus)
{
if (m_LensPositionSlider != null && Math.Abs(m_LensPositionSlider.value - focus.lensPosition) > float.Epsilon)
{
m_LensPosition = focus.lensPosition;
m_LensPositionSlider.SetValueWithoutNotify(focus.lensPosition);
}
}
protected override void UpdateMode(ARKitLockedCamera lockedCamera, ARKitFocusMode mode)
{
Debug.Log($"Updating focus mode to {mode.ToString()}.");
lockedCamera.requestedFocusMode = mode;
}
protected override void UpdateConfigValues(ARKitLockedCamera lockedCamera)
{
var focus = new ARKitFocus(m_LensPosition);
Debug.Log($"Updating focus: {focus.ToString()}");
lockedCamera.focus = focus;
}
#endif // UNITY_IOS
}
}