void DetectJoystickDevice(int unityJoystickId, string unityJoystickName)
        {
            if (HasAttachedDeviceWithJoystickId(unityJoystickId))
            {
                return;
            }

                        #if UNITY_PS4
            if (unityJoystickName == "Empty")
            {
                // On PS4 console, disconnected controllers may have this name.
                return;
            }
                        #endif

            if (unityJoystickName.IndexOf("webcam", StringComparison.OrdinalIgnoreCase) != -1)
            {
                // Unity thinks some webcams are joysticks. >_<
                return;
            }

            // PS4 controller only works properly as of Unity 4.5
            if (InputManager.UnityVersion < new VersionInfo(4, 5, 0, 0))
            {
                if (Application.platform == RuntimePlatform.OSXEditor ||
                    Application.platform == RuntimePlatform.OSXPlayer)
                {
                    if (unityJoystickName == "Unknown Wireless Controller")
                    {
                        // Ignore PS4 controller in Bluetooth mode on Mac since it connects but does nothing.
                        return;
                    }
                }
            }

            // As of Unity 4.6.3p1, empty strings on windows represent disconnected devices.
            if (InputManager.UnityVersion >= new VersionInfo(4, 6, 3, 0))
            {
                if (Application.platform == RuntimePlatform.WindowsEditor ||
                    Application.platform == RuntimePlatform.WindowsPlayer)
                {
                    if (String.IsNullOrEmpty(unityJoystickName))
                    {
                        return;
                    }
                }
            }

            UnityInputDeviceProfileBase deviceProfile = null;

            if (deviceProfile == null)
            {
                deviceProfile = customDeviceProfiles.Find(config => config.HasJoystickName(unityJoystickName));
            }

            if (deviceProfile == null)
            {
                deviceProfile = systemDeviceProfiles.Find(config => config.HasJoystickName(unityJoystickName));
            }

            if (deviceProfile == null)
            {
                deviceProfile = customDeviceProfiles.Find(config => config.HasLastResortRegex(unityJoystickName));
            }

            if (deviceProfile == null)
            {
                deviceProfile = systemDeviceProfiles.Find(config => config.HasLastResortRegex(unityJoystickName));
            }

            if (deviceProfile == null)
            {
                var joystickDevice = new UnityInputDevice(unityJoystickId, unityJoystickName);
                AttachDevice(joystickDevice);
                Debug.Log("[InControl] Joystick " + unityJoystickId + ": \"" + unityJoystickName + "\"");
                Logger.LogWarning("Device " + unityJoystickId + " with name \"" + unityJoystickName + "\" does not match any supported profiles and will be considered an unknown controller.");
                return;
            }

            if (!deviceProfile.IsHidden)
            {
                var joystickDevice = new UnityInputDevice(deviceProfile, unityJoystickId, unityJoystickName);
                AttachDevice(joystickDevice);
//				Debug.Log( "[InControl] Joystick " + unityJoystickId + ": \"" + unityJoystickName + "\"" );
                Logger.LogInfo("Device " + unityJoystickId + " matched profile " + deviceProfile.GetType().Name + " (" + deviceProfile.Name + ")");
            }
            else
            {
                Logger.LogInfo("Device " + unityJoystickId + " matching profile " + deviceProfile.GetType().Name + " (" + deviceProfile.Name + ")" + " is hidden and will not be attached.");
            }
        }
Example #2
0
 private void DetectJoystickDevice(int unityJoystickId, string unityJoystickName)
 {
     if (!HasAttachedDeviceWithJoystickId(unityJoystickId) && unityJoystickName.IndexOf("webcam", StringComparison.OrdinalIgnoreCase) == -1 && (!(InputManager.UnityVersion < new VersionInfo(4, 5, 0, 0)) || (Application.platform != 0 && Application.platform != RuntimePlatform.OSXPlayer) || !(unityJoystickName == "Unknown Wireless Controller")) && (!(InputManager.UnityVersion >= new VersionInfo(4, 6, 3, 0)) || (Application.platform != RuntimePlatform.WindowsEditor && Application.platform != RuntimePlatform.WindowsPlayer) || !string.IsNullOrEmpty(unityJoystickName)))
     {
         UnityInputDeviceProfileBase unityInputDeviceProfileBase = null;
         if (unityInputDeviceProfileBase == null)
         {
             unityInputDeviceProfileBase = customDeviceProfiles.Find((UnityInputDeviceProfileBase config) => config.HasJoystickName(unityJoystickName));
         }
         if (unityInputDeviceProfileBase == null)
         {
             unityInputDeviceProfileBase = systemDeviceProfiles.Find((UnityInputDeviceProfileBase config) => config.HasJoystickName(unityJoystickName));
         }
         if (unityInputDeviceProfileBase == null)
         {
             unityInputDeviceProfileBase = customDeviceProfiles.Find((UnityInputDeviceProfileBase config) => config.HasLastResortRegex(unityJoystickName));
         }
         if (unityInputDeviceProfileBase == null)
         {
             unityInputDeviceProfileBase = systemDeviceProfiles.Find((UnityInputDeviceProfileBase config) => config.HasLastResortRegex(unityJoystickName));
         }
         if (unityInputDeviceProfileBase == null)
         {
             UnityInputDevice device = new UnityInputDevice(unityJoystickId, unityJoystickName);
             AttachDevice(device);
             Debug.Log("[InControl] Joystick " + unityJoystickId + ": \"" + unityJoystickName + "\"");
             Logger.LogWarning("Device " + unityJoystickId + " with name \"" + unityJoystickName + "\" does not match any supported profiles and will be considered an unknown controller.");
         }
         else if (!unityInputDeviceProfileBase.IsHidden)
         {
             UnityInputDevice device2 = new UnityInputDevice(unityInputDeviceProfileBase, unityJoystickId, unityJoystickName);
             AttachDevice(device2);
             Logger.LogInfo("Device " + unityJoystickId + " matched profile " + unityInputDeviceProfileBase.GetType().Name + " (" + unityInputDeviceProfileBase.Name + ")");
         }
         else
         {
             Logger.LogInfo("Device " + unityJoystickId + " matching profile " + unityInputDeviceProfileBase.GetType().Name + " (" + unityInputDeviceProfileBase.Name + ") is hidden and will not be attached.");
         }
     }
 }