コード例 #1
0
        private 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;
            }

            // As of Unity 4.6.3p1, empty strings on windows represent disconnected devices.
            if ((Application.platform == RuntimePlatform.WindowsEditor ||
                 Application.platform == RuntimePlatform.WindowsPlayer ||
                 Application.platform == RuntimePlatform.WindowsWebPlayer) &&
                string.IsNullOrEmpty(unityJoystickName))
            {
                return;
            }

            UnityInputDeviceProfile matchedDeviceProfile = _deviceProfiles.Find(config => config.HasJoystickName(unityJoystickName)) ??
                                                           _deviceProfiles.Find(config => config.HasLastResortRegex(unityJoystickName));

            UnityInputDeviceProfile deviceProfile = null;

            if (matchedDeviceProfile == null)
            {
                deviceProfile = new UnityUnknownDeviceProfile(unityJoystickName);
                _deviceProfiles.Add(deviceProfile);
            }
            else
            {
                deviceProfile = matchedDeviceProfile;
            }

            if (devices.OfType <UnityInputDevice>().Any(unityDevice => 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.");
            }
        }
コード例 #2
0
 public UnityInputDevice(UnityInputDeviceProfile profile) : base(profile.Name)
 {
     Initialize(profile, 0);
 }
コード例 #3
0
 public UnityInputDevice(UnityInputDeviceProfile profile, int joystickId) : base(profile.Name)
 {
     Initialize(profile, joystickId);
 }
コード例 #4
0
 public bool IsConfiguredWith(UnityInputDeviceProfile deviceProfile, int joystickId)
 {
     return(Profile == deviceProfile && JoystickId == joystickId);
 }