Skip to content

Commit f561407

Browse files
ChengNan Yanglawwong
authored andcommitted
Update get render model name API using Interop.WVR_GetParameters
* WaveVR_Utils.GetControllerName API is not available before WaveSDK 3.1
1 parent 9d8d22f commit f561407

File tree

1 file changed

+31
-19
lines changed

1 file changed

+31
-19
lines changed

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

Lines changed: 31 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using HTC.UnityPlugin.Vive;
55
using System;
66
using System.Collections.Generic;
7+
using System.Runtime.InteropServices;
78
using UnityEngine;
89
#if VIU_WAVEVR && UNITY_ANDROID
910
using wvr;
@@ -543,7 +544,7 @@ private IVRModuleDeviceStateRW UpdateDevicePose(uint deviceIndex, WaveVR.Device
543544
{
544545
currState.isConnected = true;
545546
currState.deviceClass = s_type2class[(int)content.type];
546-
currState.deviceModel = QueryDeviceModel(s_type2class[(int)content.type]);
547+
currState.deviceModel = QueryDeviceModel(s_index2type[(int)deviceIndex]);
547548
currState.serialNumber = content.type.ToString();
548549
currState.modelNumber = content.type.ToString();
549550
currState.renderModelName = content.type.ToString();
@@ -798,27 +799,38 @@ public override void TriggerViveControllerHaptic(uint deviceIndex, ushort durati
798799
}
799800
}
800801

801-
private VRModuleDeviceModel QueryDeviceModel(VRModuleDeviceClass device)
802+
private VRModuleDeviceModel QueryDeviceModel(WVR_DeviceType device)
802803
{
803-
if (device.Equals(VRModuleDeviceClass.HMD))
804+
switch (device)
804805
{
805-
return VRModuleDeviceModel.ViveFocusHMD;
806-
}
807-
else if (device.Equals(VRModuleDeviceClass.Controller))
808-
{
809-
VRModuleDeviceModel model;
810-
if (m_models.TryGetValue(WaveVR_Utils.GetControllerName(WaveVR_Controller.EDeviceType.Dominant), out model))
811-
{
812-
return model;
813-
}
814-
else
815-
{
806+
case WVR_DeviceType.WVR_DeviceType_HMD:
807+
return VRModuleDeviceModel.ViveFocusHMD;
808+
case WVR_DeviceType.WVR_DeviceType_Controller_Right:
809+
case WVR_DeviceType.WVR_DeviceType_Controller_Left:
810+
int buffer = 128;
811+
uint resultLength = 128;
812+
string parameterName = "GetRenderModelName";
813+
IntPtr ptrParameterName = Marshal.StringToHGlobalAnsi(parameterName);
814+
IntPtr ptrResult = Marshal.AllocHGlobal(buffer);
815+
uint ret = Interop.WVR_GetParameters(device, ptrParameterName, ptrResult, resultLength);
816+
if (ret > 0)
817+
{
818+
VRModuleDeviceModel model;
819+
if (m_models.TryGetValue(Marshal.PtrToStringAnsi(ptrResult), out model))
820+
{
821+
return model;
822+
}
823+
else
824+
{
825+
return VRModuleDeviceModel.Unknown;
826+
}
827+
}
828+
else
829+
{
830+
return VRModuleDeviceModel.Unknown;
831+
}
832+
default:
816833
return VRModuleDeviceModel.Unknown;
817-
}
818-
}
819-
else
820-
{
821-
return VRModuleDeviceModel.Unknown;
822834
}
823835
}
824836

0 commit comments

Comments
 (0)