Exemple #1
0
        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 != SDLSupport.kXRInterfaceCurrent)
            {
                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 SDL descriptor.
            SDLDeviceDescriptor deviceDescriptor;

            try
            {
                deviceDescriptor = SDLDeviceDescriptor.FromJson(description.capabilities);
            }
            catch (Exception)
            {
                return(null);
            }

            if (deviceDescriptor == null)
            {
                return(null);
            }

            if (string.IsNullOrEmpty(matchedLayout))
            {
                //matchedLayout = "Joystick";
            }

            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 SDLLayoutBuilder {
                descriptor = deviceDescriptor, parentLayout = matchedLayout
            };

            InputSystem.RegisterLayoutBuilder(() => layout.Build(), layoutName, matchedLayout);

            return(layoutName);
        }
        internal static string OnFindLayoutForDevice(int deviceId, ref InputDeviceDescription description, string matchedLayout, IInputRuntime runtime)
        {
            if (description.interfaceName != LinuxSupport.kInterfaceName)
            {
                return(null);
            }

            if (string.IsNullOrEmpty(description.capabilities))
            {
                return(null);
            }

            // Try to parse the SDL descriptor.
            SDLDeviceDescriptor deviceDescriptor;

            try
            {
                deviceDescriptor = SDLDeviceDescriptor.FromJson(description.capabilities);
            }
            catch (Exception exception)
            {
                Debug.LogError($"{exception} while trying to parse descriptor for SDL device: {description.capabilities}");
                return(null);
            }

            if (deviceDescriptor == null)
            {
                return(null);
            }

            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 SDLLayoutBuilder {
                m_Descriptor = deviceDescriptor, m_ParentLayout = matchedLayout
            };

            InputSystem.RegisterLayoutBuilder(() => layout.Build(), layoutName, matchedLayout);

            return(layoutName);
        }