Ejemplo n.º 1
0
        public override void Update(ulong updateTick, float deltaTime)
        {
            int count = devices.Count;

            for (int i = 0; i < count; i++)
            {
                UnityInputDevice unityInputDevice = devices[i] as UnityInputDevice;
                if (unityInputDevice != null)
                {
                    unityInputDevice.Passive = (((int)controllerEnableMask & (1 << unityInputDevice.JoystickId - 1)) == 0);
                }
            }
            deviceRefreshTimer += deltaTime;
            if (deviceRefreshTimer >= 1f)
            {
                deviceRefreshTimer = 0f;
                QueryJoystickInfo();
                if (JoystickInfoHasChanged)
                {
                    Logger.LogInfo("Change in attached Unity joysticks detected; refreshing device list.");
                    DetachDevices();
                    AttachDevices();
                }
            }
        }
        void DetectAttachedJoystickDevice(int unityJoystickId, string unityJoystickName)
        {
            var matchedDeviceProfile = deviceProfiles.Find(config => config.HasJoystickName(unityJoystickName));

            if (matchedDeviceProfile == null)
            {
                matchedDeviceProfile = deviceProfiles.Find(config => config.HasRegexName(unityJoystickName));
            }

            UnityInputDeviceProfile deviceProfile = null;

            if (matchedDeviceProfile == null)
            {
                deviceProfile = new UnityUnknownDeviceProfile(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;
                }
            }

            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 AttachKeyboardDeviceWithConfig( UnityInputDeviceProfile config )
		{
			if (keyboardDevicesAttached)
			{
				return;
			}

			var keyboardDevice = new UnityInputDevice( config );
			AttachDevice( keyboardDevice );

			keyboardDevicesAttached = true;
		}
Ejemplo n.º 4
0
        void AttachKeyboardDeviceWithConfig(UnityInputDeviceProfile config)
        {
            if (keyboardDevicesAttached)
            {
                return;
            }

            var keyboardDevice = new UnityInputDevice(config);

            AttachDevice(keyboardDevice);

            keyboardDevicesAttached = true;
        }
Ejemplo n.º 5
0
        private bool HasAttachedDeviceWithJoystickId(int unityJoystickId)
        {
            int count = devices.Count;

            for (int i = 0; i < count; i++)
            {
                UnityInputDevice unityInputDevice = devices[i] as UnityInputDevice;
                if (unityInputDevice != null && unityInputDevice.JoystickId == unityJoystickId)
                {
                    return(true);
                }
            }
            return(false);
        }
Ejemplo n.º 6
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);
            }
        }
Ejemplo n.º 7
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.");
         }
     }
 }
Ejemplo n.º 8
0
	public Main()
	{
		if( instance != null )
		{
			Debug.LogError( "Cannot create a new instance of Main. Main is a singleton." );
			return;
		}

		//InputManager.EnableXInput = true;
		InputManager.Setup();

		InputDevice keyboardAndMouse = new UnityInputDevice( new KeyboardMouseDeviceProfile() );
		InputManager.AttachDevice( keyboardAndMouse );

		playerDevices = new List<PlayerDevice>();
		usedDevices = new List<InputDevice>();

		for ( int i = 0; i < InputManager.Devices.Count; i++ )
		{
			Debug.Log( InputManager.Devices[i].Name );

			if( !usedDevices.Contains(InputManager.Devices[i]) )
			{
				if( playerDevices.Count == 0 )
				{
					usedDevices.Add( InputManager.Devices[i] );
					usedDevices.Add( keyboardAndMouse );
					playerDevices.Add( new PlayerDevice( InputManager.Devices[i], keyboardAndMouse ) );
				}
				else
				{
					usedDevices.Add( InputManager.Devices[i] );
					playerDevices.Add( new PlayerDevice( InputManager.Devices[i] ) );
				}
			}
		}

		InputManager.OnDeviceAttached += HandleDeviceAttached;
		InputManager.OnDeviceDetached += HandlDeviceDetached;
	}
Ejemplo n.º 9
0
        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.");
            }
        }
		void DetectAttachedJoystickDevice( 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;
			}

			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;
				}
			}

			var matchedDeviceProfile = deviceProfiles.Find( config => config.HasJoystickName( unityJoystickName ) );

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

			UnityInputDeviceProfile deviceProfile = null;

			if (matchedDeviceProfile == null)
			{
				deviceProfile = new UnityUnknownDeviceProfile( 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;
				}
			}

			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 AttachDevice( UnityInputDevice device )
		{
			devices.Add( device );
			InputManager.AttachDevice( device );
		}
		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." );
			}
		}
Ejemplo n.º 13
0
        void DetectAttachedJoystickDevice(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 works properly as of Unity 4.5
            if (InputManager.UnityVersion <= new VersionInfo(4, 5))
            {
                if (Application.platform == RuntimePlatform.OSXEditor ||
                    Application.platform == RuntimePlatform.OSXPlayer)
                {
                    if (unityJoystickName == "Unknown Wireless Controller")
                    {
                        Debug.LogError("Disable 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
#if !UNITY_2017_2_OR_NEWER
                    || Application.platform == RuntimePlatform.OSXDashboardPlayer
#endif
#if !UNITY_5_4_OR_NEWER
                    || Application.platform == RuntimePlatform.OSXWebPlayer
#endif
                    )
                {
                    if (String.IsNullOrEmpty(unityJoystickName))
                    {
                        return;
                    }
                }
            }

            var matchedDeviceProfile = deviceProfiles.Find(config => config.HasJoystickName(unityJoystickName));

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

            UnityInputDeviceProfile deviceProfile = null;

            if (matchedDeviceProfile == null)
            {
                deviceProfile = new UnityUnknownDeviceProfile(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;
                }
            }

            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.");
            }
        }
Ejemplo n.º 14
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.");
            }
        }
Ejemplo n.º 15
0
 void AttachDevice(UnityInputDevice device)
 {
     devices.Add(device);
     InputManager.AttachDevice(device);
 }
Ejemplo n.º 16
0
 private void AttachDevice(UnityInputDevice device)
 {
     device.Passive = (((int)controllerEnableMask & (1 << device.JoystickId - 1)) == 0);
     devices.Add(device);
     InputManager.AttachDevice(device);
 }
        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 );
            }
        }
Ejemplo n.º 18
0
        void DetectAttachedJoystickDevice(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;
            }

            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;
                }
            }

            var matchedDeviceProfile = deviceProfiles.Find(config => config.HasJoystickName(unityJoystickName));

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

            UnityInputDeviceProfile deviceProfile = null;

            if (matchedDeviceProfile == null)
            {
                deviceProfile = new UnityUnknownDeviceProfile(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;
                }
            }

            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 ))
            {
                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 DetectAttachedJoystickDevice( int unityJoystickId, string unityJoystickName )
        {
            var matchedDeviceProfile = deviceProfiles.Find( config => config.HasJoystickName( unityJoystickName ) );

            if (matchedDeviceProfile == null) {
            matchedDeviceProfile = deviceProfiles.Find( config => config.HasRegexName( unityJoystickName ) );
            }

            UnityInputDeviceProfile deviceProfile = null;

            if (matchedDeviceProfile == null) {
            deviceProfile = new UnityUnknownDeviceProfile( 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)) {
                Debug.Log( "Device \"" + unityJoystickName + "\" is already configured with " + deviceProfile.Name );
                return;
            }
            }

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

            if (matchedDeviceProfile == null) {
                Debug.LogWarning( "Device " + unityJoystickId + " with name \"" + unityJoystickName + "\" does not match any known profiles." );
            }
            else {
                Debug.Log( "Device " + unityJoystickId + " matched profile " + deviceProfile.GetType().Name + " (" + deviceProfile.Name + ")" );
            }
            }
            else {
            Debug.Log( "Device " + unityJoystickId + " matching profile " + deviceProfile.GetType().Name + " (" + deviceProfile.Name + ")" + " is hidden and will not be attached." );
            }
        }