Example #1
0
        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;
                    }
                }
            }

            InputDeviceProfile 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)
            {
//				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.");
                var unknownDeviceProfile = new UnknownUnityDeviceProfile(unityJoystickName);
                var joystickDevice       = new UnknownUnityInputDevice(unknownDeviceProfile, unityJoystickId);
                AttachDevice(joystickDevice);
                return;
            }

            if (!deviceProfile.IsHidden)
            {
                var joystickDevice = new UnityInputDevice(deviceProfile, unityJoystickId);
                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.");
            }
        }
		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 ||
				    Application.platform == RuntimePlatform.OSXWebPlayer)
				{
					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 ||
				    Application.platform == RuntimePlatform.WindowsWebPlayer)
				{
					if (String.IsNullOrEmpty( unityJoystickName ))
					{
						return;
					}
				}
			}

			InputDeviceProfile 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)
			{
//				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." );
				var unknownDeviceProfile = new UnknownUnityDeviceProfile( unityJoystickName );
				var joystickDevice = new UnknownUnityInputDevice( unknownDeviceProfile, unityJoystickId );
				AttachDevice( joystickDevice );
				return;
			}

			if (!deviceProfile.IsHidden)
			{
				var joystickDevice = new UnityInputDevice( deviceProfile, unityJoystickId );
				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." );
			}
		}
        void DetectJoystickDevice( int unityJoystickId, string unityJoystickName )
        {
            if (unityJoystickName == "WIRED CONTROLLER" ||
                unityJoystickName == " WIRED CONTROLLER")
            {
                // Ignore Steam controller for now.
                return;
            }

            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 ))
            {
                if (Application.platform == RuntimePlatform.OSXEditor ||
                    Application.platform == RuntimePlatform.OSXPlayer ||
                    Application.platform == RuntimePlatform.OSXWebPlayer)
                {
                    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 ))
            {
                if (Application.platform == RuntimePlatform.WindowsEditor ||
                    Application.platform == RuntimePlatform.WindowsPlayer ||
                    Application.platform == RuntimePlatform.WindowsWebPlayer)
                {
                    if (String.IsNullOrEmpty( unityJoystickName ))
                    {
                        return;
                    }
                }
            }

            InputDeviceProfile matchedDeviceProfile = null;

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

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

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

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

            InputDeviceProfile deviceProfile = null;

            if (matchedDeviceProfile == null)
            {
                deviceProfile = new UnknownUnityDeviceProfile( unityJoystickName );
                systemDeviceProfiles.Add( deviceProfile );
            }
            else
            {
                deviceProfile = matchedDeviceProfile;
            }

            if (!deviceProfile.IsHidden)
            {
                var joystickDevice = new UnityInputDevice( deviceProfile, unityJoystickId );
                AttachDevice( joystickDevice );

                if (matchedDeviceProfile == null)
                {
                    Logger.LogWarning( "Device " + unityJoystickId + " with name \"" + unityJoystickName + "\" does not match any known profiles." );
                }
                else
                {
                    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." );
            }
        }
        void DetectJoystickDevice(int unityJoystickId, string unityJoystickName)
        {
            if (unityJoystickName == "WIRED CONTROLLER" ||
                unityJoystickName == " WIRED CONTROLLER")
            {
                // Ignore Steam controller for now.
                return;
            }

            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 ||
                    Application.platform == RuntimePlatform.OSXWebPlayer)
                {
                    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 ||
                    Application.platform == RuntimePlatform.WindowsWebPlayer)
                {
                    if (String.IsNullOrEmpty(unityJoystickName))
                    {
                        return;
                    }
                }
            }

            InputDeviceProfile matchedDeviceProfile = null;

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

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

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

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

            InputDeviceProfile deviceProfile = null;

            if (matchedDeviceProfile == null)
            {
                deviceProfile = new UnknownUnityDeviceProfile(unityJoystickName);
                systemDeviceProfiles.Add(deviceProfile);
            }
            else
            {
                deviceProfile = matchedDeviceProfile;
            }

            if (!deviceProfile.IsHidden)
            {
                var joystickDevice = new UnityInputDevice(deviceProfile, unityJoystickId);
                AttachDevice(joystickDevice);

                if (matchedDeviceProfile == null)
                {
                    Logger.LogWarning("Device " + unityJoystickId + " with name \"" + unityJoystickName + "\" does not match any known profiles.");
                }
                else
                {
                    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.");
            }
        }