Skip to content

Commit 87340ea

Browse files
author
lawwong
committed
Fix left/right ctrl model not appear correctly on simulator
SimulatorModule returns left/right index even when the device isn't created this causes HandRole does't trigger device changed then causes RenderModelHook doesn't refresh models also add connected check when mapping left/right device in HandRole.cs to prevent mapping a disconnected device. Suppose this only effects SimulatorModule since currently all other modules only return connected left/right index
1 parent 05d9209 commit 87340ea

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

Assets/HTC.UnityPlugin/VRModule/Modules/SimulatorModule.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,9 @@ public override void OnDeactivated()
115115
}
116116
}
117117

118-
public override uint GetRightControllerDeviceIndex() { return RIGHT_INDEX; }
118+
public override uint GetRightControllerDeviceIndex() { return m_currStates != null && m_currStates[RIGHT_INDEX].isConnected ? RIGHT_INDEX : VRModule.INVALID_DEVICE_INDEX; }
119119

120-
public override uint GetLeftControllerDeviceIndex() { return LEFT_INDEX; }
120+
public override uint GetLeftControllerDeviceIndex() { return m_currStates != null && m_currStates[LEFT_INDEX].isConnected ? LEFT_INDEX : VRModule.INVALID_DEVICE_INDEX; }
121121

122122
public override void Update()
123123
{

Assets/HTC.UnityPlugin/ViveInputUtility/Scripts/ViveRole/RoleMaps/HandRole.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,8 @@ private void MappingLeftRightHands()
146146
else
147147
{
148148
rightIndex = VRModule.GetRightControllerDeviceIndex();
149-
if (rightIndex >= deviceCount || RoleMap.IsDeviceConnectedAndBound(rightIndex))
149+
var rightIndexState = VRModule.GetCurrentDeviceState(rightIndex);
150+
if (!rightIndexState.isConnected || RoleMap.IsDeviceBound(rightIndexState.serialNumber))
150151
{
151152
rightIndex = VRModule.INVALID_DEVICE_INDEX;
152153
}
@@ -159,7 +160,8 @@ private void MappingLeftRightHands()
159160
else
160161
{
161162
leftIndex = VRModule.GetLeftControllerDeviceIndex();
162-
if (leftIndex >= deviceCount || RoleMap.IsDeviceConnectedAndBound(leftIndex))
163+
var leftIndexState = VRModule.GetCurrentDeviceState(leftIndex);
164+
if (!leftIndexState.isConnected || RoleMap.IsDeviceBound(leftIndexState.serialNumber))
163165
{
164166
leftIndex = VRModule.INVALID_DEVICE_INDEX;
165167
}
@@ -172,7 +174,7 @@ private void MappingLeftRightHands()
172174
{
173175
if (i == rightIndex || i == leftIndex) { continue; }
174176
var state = VRModule.GetCurrentDeviceState(i);
175-
if (state.deviceClass != VRModuleDeviceClass.Controller) { continue; }
177+
if (!state.isConnected || state.deviceClass != VRModuleDeviceClass.Controller) { continue; }
176178
if (RoleMap.IsDeviceBound(state.serialNumber)) { continue; }
177179
m_sortedDeviceList.Add(i);
178180
}

0 commit comments

Comments
 (0)