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.");
            }
        }
        public static UnityInputDeviceProfile Load(string profileFile, string joystickName)
        {
            var data = IniFile.LoadFile(profileFile);

            if(!(bool)data["General"]["Enabled"])
            {
                return null;
            }

            // use the unknown device defaults
            var profile = new UnityUnknownDeviceProfile(joystickName);
            profile.Name = "Custom Profile: " + profileFile;

            profile.Sensitivity = (float)data["General"]["Sensitivity"];
            profile.LowerDeadZone = (float)data["General"]["LowerDeadZone"];
            profile.UpperDeadZone = (float)data["General"]["UpperDeadZone"];

            var analogs = data["AnalogMappings"];
            var buttons = data["ButtonMappings"];
            //Hashtable analogs = data["AnalogMappings"] as Hashtable;
            //Hashtable buttons = data["ButtonMappings"] as Hashtable;

            //var analogs = data.AnalogMappings;
            //var buttons = data.ButtonMappings;

            profile.AnalogMappings = new InputControlMapping[analogs.Count];

            int index;
            index = 0;
            foreach(DictionaryEntry entry in analogs)
            {
                string targetName = entry.Key.ToString();
                string sourceName = entry.Value.ToString();
                profile.AnalogMappings[index] = CreateMapping(targetName, targetName, sourceName);

                index += 1;
            }

            index = 0;
            foreach(DictionaryEntry entry in buttons)
            {
                string targetName = entry.Key.ToString();
                string sourceName = entry.Value.ToString();
                profile.ButtonMappings[index] = CreateMapping(targetName, targetName, sourceName);

                index += 1;
            }

            return profile;
        }
		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." );
			}
		}
Exemplo n.º 4
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.");
            }
        }
        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." );
            }
        }
        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.");
            }
        }