internal static string OnFindLayoutForDevice(ref InputDeviceDescription description, string matchedLayout, InputDeviceExecuteCommandDelegate executeCommandDelegate) { // If the device isn't a XRInput, we're not interested. if (description.interfaceName != XRUtilities.InterfaceCurrent && description.interfaceName != XRUtilities.InterfaceV1) { return(null); } // If the description doesn't come with a XR SDK descriptor, we're not // interested either. if (string.IsNullOrEmpty(description.capabilities)) { return(null); } // Try to parse the XR descriptor. XRDeviceDescriptor deviceDescriptor; try { deviceDescriptor = XRDeviceDescriptor.FromJson(description.capabilities); } catch (Exception) { return(null); } if (deviceDescriptor == null) { return(null); } if (string.IsNullOrEmpty(matchedLayout)) { #if UNITY_2019_3_OR_NEWER const InputDeviceCharacteristics controllerCharacteristics = InputDeviceCharacteristics.HeldInHand | InputDeviceCharacteristics.Controller; if ((deviceDescriptor.characteristics & InputDeviceCharacteristics.HeadMounted) != 0) { matchedLayout = "XRHMD"; } else if ((deviceDescriptor.characteristics & controllerCharacteristics) == controllerCharacteristics) { matchedLayout = "XRController"; } #else //UNITY_2019_3_OR_NEWER if (deviceDescriptor.deviceRole == InputDeviceRole.LeftHanded || deviceDescriptor.deviceRole == InputDeviceRole.RightHanded) { matchedLayout = "XRController"; } else if (deviceDescriptor.deviceRole == InputDeviceRole.Generic) { matchedLayout = "XRHMD"; } #endif //UNITY_2019_3_OR_NEWER } string layoutName; if (string.IsNullOrEmpty(description.manufacturer)) { layoutName = $"{SanitizeName(description.interfaceName)}::{SanitizeName(description.product)}"; } else { layoutName = $"{SanitizeName(description.interfaceName)}::{SanitizeName(description.manufacturer)}::{SanitizeName(description.product)}"; } var layout = new XRLayoutBuilder { descriptor = deviceDescriptor, parentLayout = matchedLayout, interfaceName = description.interfaceName }; InputSystem.RegisterLayoutBuilder(() => layout.Build(), layoutName, matchedLayout); return(layoutName); }
internal static string OnFindLayoutForDevice(int deviceId, ref InputDeviceDescription description, string matchedLayout, IInputRuntime runtime) { // If the device isn't a XRInput, we're not interested. if (description.interfaceName != XRUtilities.kXRInterfaceCurrent && description.interfaceName != XRUtilities.kXRInterfaceV1) { return(null); } // If the description doesn't come with a XR SDK descriptor, we're not // interested either. if (string.IsNullOrEmpty(description.capabilities)) { return(null); } // Try to parse the XR descriptor. XRDeviceDescriptor deviceDescriptor; try { deviceDescriptor = XRDeviceDescriptor.FromJson(description.capabilities); } catch (Exception) { return(null); } if (deviceDescriptor == null) { return(null); } if (string.IsNullOrEmpty(matchedLayout)) { if (deviceDescriptor.deviceRole == DeviceRole.LeftHanded || deviceDescriptor.deviceRole == DeviceRole.RightHanded) { matchedLayout = "XRController"; } else if (deviceDescriptor.deviceRole == DeviceRole.Generic) { matchedLayout = "XRHMD"; } } string layoutName = null; if (string.IsNullOrEmpty(description.manufacturer)) { layoutName = string.Format("{0}::{1}", SanitizeName(description.interfaceName), SanitizeName(description.product)); } else { layoutName = string.Format("{0}::{1}::{2}", SanitizeName(description.interfaceName), SanitizeName(description.manufacturer), SanitizeName(description.product)); } var layout = new XRLayoutBuilder { descriptor = deviceDescriptor, parentLayout = matchedLayout, interfaceName = description.interfaceName }; InputSystem.RegisterLayoutBuilder(() => layout.Build(), layoutName, matchedLayout); return(layoutName); }