Пример #1
0
        void DetectAttachedJoystickDevice(int unityJoystickId, string unityJoystickName)
        {
            if (unityJoystickName != "Wireless Controller") //This is the joystick name for ps4 controller on windows
            {
                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)
            {
                return;
            }
            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 PS4WinDevice(deviceProfile, unityJoystickId);

            joystickDevice.Device = DS4Devices.getNextDS4Controller(); //TODO: wrong, nothing ensures that order is the same so we could end rumbling the other player controller
            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 + ")");
            }
        }