Пример #1
0
        void DetectAttachedJoystickDevice(int unityJoystickId, string unityJoystickName)
        {
            var matchedDeviceProfile = deviceProfiles.Find(config => config.HasJoystickName(unityJoystickName));
            UnityInputDeviceProfile deviceProfile = null;

            if (matchedDeviceProfile == null)
            {
                deviceProfile = new UnknownDeviceProfile(unityJoystickName);
                deviceProfiles.Add(deviceProfile);
            }
            else
            {
                deviceProfile = matchedDeviceProfile;
            }


            foreach (var device in devices)
            {
                var unityDevice = device as UnityInputDevice;
                if (unityDevice != null && unityDevice.IsConfiguredWith(deviceProfile, unityJoystickId))
                {
                    Logger.LogInfo("Device \"" + unityJoystickName + "\" is already configured with " + deviceProfile.Name);
                    return;
                }
            }

            var inputDevice = new UnityInputDevice(deviceProfile, unityJoystickId);

            devices.Add(inputDevice);

            InputManager.AttachDevice(inputDevice);

            if (matchedDeviceProfile == null)
            {
                Logger.LogWarning("Attached device has no matching profile: \"" + unityJoystickName + "\"");
            }
            else
            {
                Logger.LogInfo("Attached device \"" + unityJoystickName + "\" matched profile: " + deviceProfile.Name);
            }
        }
        void DetectAttachedJoystickDevice( int unityJoystickId, string unityJoystickName )
        {
            var matchedDeviceProfile = deviceProfiles.Find( config => config.HasJoystickName( unityJoystickName ) );
            UnityInputDeviceProfile deviceProfile = null;

            if (matchedDeviceProfile == null)
            {
                deviceProfile = new UnknownDeviceProfile( unityJoystickName );
                deviceProfiles.Add( deviceProfile );
            }
            else
            {
                deviceProfile = matchedDeviceProfile;
            }

            int deviceCount = devices.Count;
            for (int i = 0; i < deviceCount; i++)
            {
                var device = devices[i];
                var unityDevice = device as UnityInputDevice;
                if (unityDevice != null && unityDevice.IsConfiguredWith( deviceProfile, unityJoystickId ))
                {
                    Logger.LogInfo( "Device \"" + unityJoystickName + "\" is already configured with " + deviceProfile.Name );
                    return;
                }
            }

            var joystickDevice = new UnityInputDevice( deviceProfile, unityJoystickId );
            AttachDevice( joystickDevice );

            if (matchedDeviceProfile == null)
            {
                Logger.LogWarning( "Attached device has no matching profile: \"" + unityJoystickName + "\"" );
            }
            else
            {
                Logger.LogInfo( "Attached device \"" + unityJoystickName + "\" matched profile: " + deviceProfile.Name );
            }
        }