Skip to content

Commit 1c4cd9b

Browse files
author
lawwong
committed
Now Ex-Cam switch hotkey also switch Ex-Cam config interface
1 parent 794f0de commit 1c4cd9b

File tree

1 file changed

+58
-69
lines changed

1 file changed

+58
-69
lines changed

Assets/HTC.UnityPlugin/ViveInputUtility/Scripts/Misc/ExternalCameraHook.cs

Lines changed: 58 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,9 @@ public class ExternalCameraHook : SingletonBehaviour<ExternalCameraHook>, INewPo
1919
private Transform m_origin;
2020
[SerializeField]
2121
private string m_configPath = AUTO_LOAD_CONFIG_PATH;
22-
[SerializeField]
23-
private bool m_enableStaticQuadView = false;
24-
[SerializeField]
25-
private bool m_enableConfigUI = false;
22+
23+
private bool m_quadViewSwitch = false;
24+
private bool m_configInterfaceSwitch = true;
2625

2726
public ViveRoleProperty viveRole { get { return m_viveRole; } }
2827

@@ -32,39 +31,47 @@ public class ExternalCameraHook : SingletonBehaviour<ExternalCameraHook>, INewPo
3231

3332
public bool quadViewEnabled
3433
{
35-
get
34+
get { return m_quadViewSwitch; }
35+
set
3636
{
37-
#if VIU_STEAMVR
38-
return m_externalCamera != null && m_externalCamera.isActiveAndEnabled;
39-
#else
40-
return false;
41-
#endif
37+
if (m_quadViewSwitch != value)
38+
{
39+
m_quadViewSwitch = value;
40+
UpdateActivity();
41+
}
4242
}
4343
}
4444

45-
public bool enableStaticQuadView
45+
public bool configInterfaceEnabled
4646
{
47-
get { return m_enableStaticQuadView; }
47+
get { return m_configInterfaceSwitch; }
4848
set
4949
{
50-
if (m_enableStaticQuadView != value)
50+
if (m_configInterfaceSwitch != value)
5151
{
52-
m_enableStaticQuadView = value;
53-
UpdateExCamActivity();
52+
m_configInterfaceSwitch = value;
53+
UpdateActivity();
5454
}
5555
}
5656
}
5757

58-
public bool enableConfigUI
58+
public bool isQuadViewActive
5959
{
60-
get { return m_enableConfigUI; }
61-
set
60+
get
6261
{
63-
if (m_enableConfigUI != value)
64-
{
65-
m_enableConfigUI = value;
66-
UpdateExCamActivity();
67-
}
62+
#if VIU_STEAMVR
63+
return isActiveAndEnabled && m_externalCamera != null && m_externalCamera.isActiveAndEnabled;
64+
#else
65+
return false;
66+
#endif
67+
}
68+
}
69+
70+
public bool isConfigInterfaceActive
71+
{
72+
get
73+
{
74+
return isActiveAndEnabled && m_configUI != null && m_configUI.activeSelf;
6875
}
6976
}
7077

@@ -85,7 +92,7 @@ private void OnValidate()
8592
{
8693
if (Application.isPlaying && isActiveAndEnabled)
8794
{
88-
UpdateExCamActivity();
95+
UpdateActivity();
8996
}
9097
}
9198
#endif
@@ -125,12 +132,12 @@ private static void AutoLoadConfig()
125132

126133
var configPath = AUTO_LOAD_CONFIG_PATH;
127134

128-
if (Active && !string.IsNullOrEmpty(Instance.m_configPath))
135+
if (Active)
129136
{
130137
configPath = Instance.m_configPath;
131138
}
132139

133-
if (File.Exists(configPath))
140+
if (!string.IsNullOrEmpty(configPath) && File.Exists(configPath))
134141
{
135142
SteamVR_Render.instance.externalCameraConfigPath = string.Empty;
136143

@@ -178,7 +185,8 @@ private void OnEnable()
178185
{
179186
m_viveRole.onDeviceIndexChanged += OnDeviceIndexChanged;
180187
VivePose.AddNewPosesListener(this);
181-
UpdateExCamActivity();
188+
189+
OnDeviceIndexChanged(m_viveRole.GetDeviceIndex());
182190
}
183191
}
184192

@@ -188,7 +196,8 @@ private void OnDisable()
188196
{
189197
m_viveRole.onDeviceIndexChanged -= OnDeviceIndexChanged;
190198
VivePose.RemoveNewPosesListener(this);
191-
UpdateExCamActivity();
199+
200+
UpdateActivity();
192201
}
193202
}
194203

@@ -203,7 +212,7 @@ public virtual void OnNewPoses()
203212
m_staticExCamPose = VivePose.GetPose(deviceIndex);
204213
}
205214

206-
if (quadViewEnabled)
215+
if (isQuadViewActive)
207216
{
208217
Pose.SetPose(transform, m_staticExCamPose, m_origin);
209218
}
@@ -216,73 +225,53 @@ private void Update()
216225
{
217226
if (Input.GetKeyDown(KeyCode.M) && Input.GetKey(KeyCode.RightShift))
218227
{
219-
if (!quadViewEnabled)
228+
if (!isQuadViewActive)
220229
{
221-
m_enableStaticQuadView = true;
222-
m_enableConfigUI = false;
230+
m_quadViewSwitch = true;
231+
m_configInterfaceSwitch = true;
223232
}
224233
else
225234
{
226-
if (isTrackingDevice)
235+
if (m_configInterfaceSwitch)
227236
{
228-
m_enableConfigUI = !m_enableConfigUI;
237+
m_configInterfaceSwitch = false;
229238
}
230239
else
231240
{
232-
if (!m_enableConfigUI)
233-
{
234-
m_enableConfigUI = true;
235-
}
236-
else
237-
{
238-
m_enableStaticQuadView = false;
239-
m_enableConfigUI = false;
240-
}
241+
m_quadViewSwitch = false;
242+
m_configInterfaceSwitch = false;
241243
}
242244
}
243245

244-
UpdateExCamActivity();
246+
UpdateActivity();
245247
}
246248
}
247249
#endif
248250

249251
private void OnDeviceIndexChanged(uint deviceIndex)
250252
{
251-
UpdateExCamActivity();
253+
m_quadViewSwitch = isTrackingDevice;
254+
255+
UpdateActivity();
252256
}
253257

254-
private void UpdateExCamActivity()
258+
private void UpdateActivity()
255259
{
256260
if (!isActiveAndEnabled)
257261
{
258-
SetExCamActive(false);
259-
SetExCamUIActive(false);
262+
InternalSetQuadViewActive(false);
263+
InternalSetConfigInterfaceActive(false);
260264
}
261265
else
262266
{
263-
if (isTrackingDevice)
264-
{
265-
SetExCamActive(true);
266-
}
267-
else
268-
{
269-
SetExCamActive(m_enableStaticQuadView);
270-
}
271-
272-
if (quadViewEnabled)
273-
{
274-
SetExCamUIActive(m_enableConfigUI);
275-
}
276-
else
277-
{
278-
SetExCamUIActive(false);
279-
}
267+
InternalSetQuadViewActive(m_quadViewSwitch);
268+
InternalSetConfigInterfaceActive(isQuadViewActive && m_configInterfaceSwitch);
280269
}
281270
}
282271

283-
private void SetExCamActive(bool value)
272+
private void InternalSetQuadViewActive(bool value)
284273
{
285-
if (value && m_externalCamera == null)
274+
if (value && m_externalCamera == null && !string.IsNullOrEmpty(m_configPath) && File.Exists(m_configPath))
286275
{
287276
// don't know why SteamVR_ExternalCamera must be instantiated from the prefab
288277
// when create SteamVR_ExternalCamera using AddComponent, errors came out when disabling
@@ -313,7 +302,7 @@ private void SetExCamActive(bool value)
313302
}
314303
}
315304

316-
private void SetExCamUIActive(bool value)
305+
private void InternalSetConfigInterfaceActive(bool value)
317306
{
318307
if (value && m_configUI == null)
319308
{
@@ -347,7 +336,7 @@ protected virtual void Start()
347336
Debug.LogWarning("SteamVR plugin not found! install it to enable ExternalCamera!");
348337
}
349338

350-
private void UpdateExCamActivity() { }
339+
private void UpdateActivity() { }
351340

352341
public virtual void BeforeNewPoses() { }
353342

0 commit comments

Comments
 (0)