Skip to content

Commit 577c279

Browse files
author
lawwong
committed
Add reservedDeviceIndex to main module
1 parent e22e9ea commit 577c279

2 files changed

Lines changed: 10 additions & 8 deletions

File tree

Assets/HTC.UnityPlugin/VRModule/VRModuleBase.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,9 @@ private struct WVRCtrlProfile
8080

8181
public abstract int moduleIndex { get; }
8282

83+
// reserved device index, so any device index less then this will not be occupied by submodule
84+
public virtual uint reservedDeviceIndex { get { return HMD_DEVICE_INDEX; } }
85+
8386
public virtual bool ShouldActiveModule() { return false; }
8487

8588
public void Activated()

Assets/HTC.UnityPlugin/VRModule/VRModuleManager.cs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -197,22 +197,21 @@ private void EnsureValidDeviceState(uint index, out IVRModuleDeviceState prevSta
197197
// this function will skip VRModule.HMD_DEVICE_INDEX (preserved index for HMD)
198198
private uint FindAndEnsureUnusedNotHMDDeviceState(out IVRModuleDeviceState prevState, out IVRModuleDeviceStateRW currState)
199199
{
200+
var index = (m_activatedModuleBase == null ? VRModule.HMD_DEVICE_INDEX : m_activatedModuleBase.reservedDeviceIndex) + 1u;
200201
var len = GetDeviceStateLength();
201-
for (uint i = 0u, imax = len; i < imax; ++i)
202+
for (; index < len; ++index)
202203
{
203-
if (i == VRModule.HMD_DEVICE_INDEX) { continue; }
204-
if (TryGetValidDeviceState(i, out prevState, out currState))
204+
if (TryGetValidDeviceState(index, out prevState, out currState))
205205
{
206206
if (prevState.isConnected) { continue; }
207207
if (currState.isConnected) { continue; }
208+
return index;
208209
}
209-
210-
EnsureValidDeviceState(i, out prevState, out currState);
211-
return i;
210+
break;
212211
}
213212

214-
EnsureValidDeviceState(len, out prevState, out currState);
215-
return len;
213+
EnsureValidDeviceState(index, out prevState, out currState);
214+
return index;
216215
}
217216

218217
private void Update()

0 commit comments

Comments
 (0)