示例#1
0
 public UnityInputDevice(UnityInputDeviceProfileBase deviceProfile, int joystickId, string joystickName)
 {
     profile    = deviceProfile;
     JoystickId = joystickId;
     if (joystickId != 0)
     {
         base.SortOrder = 100 + joystickId;
     }
     SetupAnalogQueries();
     SetupButtonQueries();
     base.AnalogSnapshot = null;
     if (IsKnown)
     {
         base.Name        = profile.Name;
         base.Meta        = profile.Meta;
         base.DeviceClass = profile.DeviceClass;
         base.DeviceStyle = profile.DeviceStyle;
         int analogCount = profile.AnalogCount;
         for (int i = 0; i < analogCount; i++)
         {
             InputControlMapping inputControlMapping = profile.AnalogMappings[i];
             if (Utility.TargetIsAlias(inputControlMapping.Target))
             {
                 Debug.LogError("Cannot map control \"" + inputControlMapping.Handle + "\" as InputControlType." + inputControlMapping.Target + " in profile \"" + deviceProfile.Name + "\" because this target is reserved as an alias. The mapping will be ignored.");
                 continue;
             }
             InputControl inputControl = AddControl(inputControlMapping.Target, inputControlMapping.Handle);
             inputControl.Sensitivity   = Mathf.Min(profile.Sensitivity, inputControlMapping.Sensitivity);
             inputControl.LowerDeadZone = Mathf.Max(profile.LowerDeadZone, inputControlMapping.LowerDeadZone);
             inputControl.UpperDeadZone = Mathf.Min(profile.UpperDeadZone, inputControlMapping.UpperDeadZone);
             inputControl.Raw           = inputControlMapping.Raw;
             inputControl.Passive       = inputControlMapping.Passive;
         }
         int buttonCount = profile.ButtonCount;
         for (int j = 0; j < buttonCount; j++)
         {
             InputControlMapping inputControlMapping2 = profile.ButtonMappings[j];
             if (Utility.TargetIsAlias(inputControlMapping2.Target))
             {
                 Debug.LogError("Cannot map control \"" + inputControlMapping2.Handle + "\" as InputControlType." + inputControlMapping2.Target + " in profile \"" + deviceProfile.Name + "\" because this target is reserved as an alias. The mapping will be ignored.");
                 continue;
             }
             InputControl inputControl2 = AddControl(inputControlMapping2.Target, inputControlMapping2.Handle);
             inputControl2.Passive = inputControlMapping2.Passive;
         }
     }
     else
     {
         base.Name = "Unknown Device";
         base.Meta = "\"" + joystickName + "\"";
         for (int k = 0; k < NumUnknownButtons; k++)
         {
             AddControl((InputControlType)(500 + k), "Button " + k);
         }
         for (int l = 0; l < NumUnknownAnalogs; l++)
         {
             AddControl((InputControlType)(400 + l), "Analog " + l, 0.2f, 0.9f);
         }
     }
 }
示例#2
0
        private void AttachKeyboardDevices()
        {
            int count = systemDeviceProfiles.Count;

            for (int i = 0; i < count; i++)
            {
                UnityInputDeviceProfileBase unityInputDeviceProfileBase = systemDeviceProfiles[i];
                if (unityInputDeviceProfileBase.IsNotJoystick && unityInputDeviceProfileBase.IsSupportedOnThisPlatform)
                {
                    AttachDevice(new UnityInputDevice(unityInputDeviceProfileBase));
                }
            }
        }
示例#3
0
 private void OnEnable()
 {
     if (!EnforceSingleton())
     {
         return;
     }
     InputManager.InvertYAxis             = invertYAxis;
     InputManager.SuspendInBackground     = suspendInBackground;
     InputManager.EnableICade             = enableICade;
     InputManager.EnableXInput            = enableXInput;
     InputManager.XInputUpdateRate        = (uint)Mathf.Max(xInputUpdateRate, 0);
     InputManager.XInputBufferSize        = (uint)Mathf.Max(xInputBufferSize, 0);
     InputManager.EnableNativeInput       = enableNativeInput;
     InputManager.NativeInputEnableXInput = nativeInputEnableXInput;
     InputManager.NativeInputUpdateRate   = (uint)Mathf.Max(nativeInputUpdateRate, 0);
     InputManager.NativeInputPreventSleep = nativeInputPreventSleep;
     if (InputManager.SetupInternal())
     {
         if (logDebugInfo)
         {
             Debug.Log("InControl (version " + InputManager.Version + ")");
             Logger.OnLogMessage -= LogMessage;
             Logger.OnLogMessage += LogMessage;
         }
         foreach (string customProfile in customProfiles)
         {
             Type type = Type.GetType(customProfile);
             if (type == null)
             {
                 Debug.LogError("Cannot find class for custom profile: " + customProfile);
             }
             else
             {
                 UnityInputDeviceProfileBase unityInputDeviceProfileBase = Activator.CreateInstance(type) as UnityInputDeviceProfileBase;
                 if (unityInputDeviceProfileBase != null)
                 {
                     InputManager.AttachDevice(new UnityInputDevice(unityInputDeviceProfileBase));
                 }
             }
         }
     }
     SceneManager.sceneLoaded -= OnSceneWasLoaded;
     SceneManager.sceneLoaded += OnSceneWasLoaded;
     if (dontDestroyOnLoad)
     {
         UnityEngine.Object.DontDestroyOnLoad(this);
     }
 }
示例#4
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.");
         }
     }
 }
示例#5
0
 public UnityInputDevice(UnityInputDeviceProfileBase deviceProfile)
     : this(deviceProfile, 0, string.Empty)
 {
 }
        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;
                    }
                }
            }

            UnityInputDeviceProfileBase 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)
            {
                var joystickDevice = new UnityInputDevice(unityJoystickId, unityJoystickName);
                AttachDevice(joystickDevice);
                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.");
                return;
            }

            if (!deviceProfile.IsHidden)
            {
                var joystickDevice = new UnityInputDevice(deviceProfile, unityJoystickId, unityJoystickName);
                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.");
            }
        }
        public UnityInputDevice(UnityInputDeviceProfileBase deviceProfile, int joystickId, string joystickName)
        {
            profile = deviceProfile;

            JoystickId = joystickId;
            if (joystickId != 0)
            {
                SortOrder = 100 + joystickId;
            }

            SetupAnalogQueries();
            SetupButtonQueries();

            AnalogSnapshot = null;

            if (IsKnown)
            {
                Name = profile.Name;
                Meta = profile.Meta;

                var analogMappingCount = profile.AnalogCount;
                for (var i = 0; i < analogMappingCount; i++)
                {
                    var analogMapping = profile.AnalogMappings[i];
                    if (Utility.TargetIsAlias(analogMapping.Target))
                    {
                        Debug.LogError("Cannot map control \"" + analogMapping.Handle + "\" as InputControlType." + analogMapping.Target + " in profile \"" + deviceProfile.Name + "\" because this target is reserved as an alias. The mapping will be ignored.");
                    }
                    else
                    {
                        var analogControl = AddControl(analogMapping.Target, analogMapping.Handle);
                        analogControl.Sensitivity   = Mathf.Min(profile.Sensitivity, analogMapping.Sensitivity);
                        analogControl.LowerDeadZone = Mathf.Max(profile.LowerDeadZone, analogMapping.LowerDeadZone);
                        analogControl.UpperDeadZone = Mathf.Min(profile.UpperDeadZone, analogMapping.UpperDeadZone);
                        analogControl.Raw           = analogMapping.Raw;
                        analogControl.Passive       = analogMapping.Passive;
                    }
                }

                var buttonMappingCount = profile.ButtonCount;
                for (var i = 0; i < buttonMappingCount; i++)
                {
                    var buttonMapping = profile.ButtonMappings[i];
                    if (Utility.TargetIsAlias(buttonMapping.Target))
                    {
                        Debug.LogError("Cannot map control \"" + buttonMapping.Handle + "\" as InputControlType." + buttonMapping.Target + " in profile \"" + deviceProfile.Name + "\" because this target is reserved as an alias. The mapping will be ignored.");
                    }
                    else
                    {
                        var buttonControl = AddControl(buttonMapping.Target, buttonMapping.Handle);
                        buttonControl.Passive = buttonMapping.Passive;
                    }
                }
            }
            else
            {
                Name = "Unknown Device";
                Meta = "\"" + joystickName + "\"";

                for (var i = 0; i < NumUnknownButtons; i++)
                {
                    AddControl(InputControlType.Button0 + i, "Button " + i);
                }

                for (var i = 0; i < NumUnknownAnalogs; i++)
                {
                    AddControl(InputControlType.Analog0 + i, "Analog " + i, 0.2f, 0.9f);
                }
            }
        }
 public UnityInputDevice(UnityInputDeviceProfileBase deviceProfile)
     : this(deviceProfile, 0, "")
 {
 }