void AddSystemDeviceProfile(InputDeviceProfile deviceProfile) { if (deviceProfile != null && deviceProfile.IsSupportedOnThisPlatform) { systemDeviceProfiles.Add(deviceProfile); } }
public static void HideDevicesWithProfile(Type type) { if (type.IsSubclassOf(typeof(UnityInputDeviceProfile))) { InputDeviceProfile.Hide(type); } }
void Initialize(InputDeviceProfile profile, int joystickId) { Profile = profile; Meta = Profile.Meta; var analogMappingCount = Profile.AnalogCount; for (int i = 0; i < analogMappingCount; i++) { var analogMapping = Profile.AnalogMappings[i]; var analogControl = AddControl(analogMapping.Target, analogMapping.Handle); analogControl.Sensitivity = Mathf.Max(Profile.Sensitivity, analogMapping.Sensitivity); analogControl.LowerDeadZone = Mathf.Max(Profile.LowerDeadZone, analogMapping.LowerDeadZone); analogControl.UpperDeadZone = Mathf.Min(Profile.UpperDeadZone, analogMapping.UpperDeadZone); analogControl.Raw = analogMapping.Raw; } var buttonMappingCount = Profile.ButtonCount; for (int i = 0; i < buttonMappingCount; i++) { var buttonMapping = Profile.ButtonMappings[i]; AddControl(buttonMapping.Target, buttonMapping.Handle); } JoystickId = joystickId; if (joystickId != 0) { SortOrder = 100 + joystickId; } }
void Initialize( InputDeviceProfile profile, int joystickId ) { Profile = profile; Meta = Profile.Meta; var analogMappingCount = Profile.AnalogCount; for (int i = 0; i < analogMappingCount; i++) { var analogMapping = Profile.AnalogMappings[i]; 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; } var buttonMappingCount = Profile.ButtonCount; for (int i = 0; i < buttonMappingCount; i++) { var buttonMapping = Profile.ButtonMappings[i]; AddControl( buttonMapping.Target, buttonMapping.Handle ); } JoystickId = joystickId; if (joystickId != 0) { SortOrder = 100 + joystickId; } }
void AddSystemDeviceProfiles() { for (var i = 0; i < NativeInputDeviceProfileList.Profiles.Length; i++) { var typeName = NativeInputDeviceProfileList.Profiles[i]; var deviceProfile = InputDeviceProfile.CreateInstanceOfType(typeName); AddSystemDeviceProfile(deviceProfile); } }
/// <summary> /// Hides the devices with a given profile. /// This must be called before the input manager is initialized. /// </summary> /// <param name="type">Type.</param> public static void HideDevicesWithProfile(Type type) { #if NETFX_CORE if (type.GetTypeInfo().IsAssignableFrom(typeof(UnityInputDeviceProfile).GetTypeInfo())) #else if (type.IsSubclassOf(typeof(UnityInputDeviceProfile))) #endif { InputDeviceProfile.Hide(type); } }
InputDeviceProfile DetectDevice(string unityJoystickName) { // Try to find a matching profile for this device. InputDeviceProfile deviceProfile = null; var deviceInfo = new InputDeviceInfo { name = unityJoystickName }; // ReSharper disable once ConstantNullCoalescingCondition deviceProfile = deviceProfile ?? customDeviceProfiles.Find(profile => profile.Matches(deviceInfo)); deviceProfile = deviceProfile ?? systemDeviceProfiles.Find(profile => profile.Matches(deviceInfo)); deviceProfile = deviceProfile ?? customDeviceProfiles.Find(profile => profile.LastResortMatches(deviceInfo)); deviceProfile = deviceProfile ?? systemDeviceProfiles.Find(profile => profile.LastResortMatches(deviceInfo)); return(deviceProfile); }
void DetectDevice(DeviceHandle deviceHandle, InputDeviceInfo deviceInfo) { // Try to find a matching profile for this device. InputDeviceProfile deviceProfile = null; // ReSharper disable once ConstantNullCoalescingCondition deviceProfile = deviceProfile ?? customDeviceProfiles.Find(profile => profile.Matches(deviceInfo)); deviceProfile = deviceProfile ?? systemDeviceProfiles.Find(profile => profile.Matches(deviceInfo)); deviceProfile = deviceProfile ?? customDeviceProfiles.Find(profile => profile.LastResortMatches(deviceInfo)); deviceProfile = deviceProfile ?? systemDeviceProfiles.Find(profile => profile.LastResortMatches(deviceInfo)); // Find a matching previously attached device or create a new one. if (deviceProfile == null || deviceProfile.IsNotHidden) { var device = FindDetachedDevice(deviceInfo) ?? new NativeInputDevice(); device.Initialize(deviceHandle, deviceInfo, deviceProfile); AttachDevice(device); } }
void DetectDevice(DeviceHandle deviceHandle, InputDeviceInfo deviceInfo) { // Try to find a matching profile for this device. InputDeviceProfile deviceProfile = null; // ReSharper disable once ConstantNullCoalescingCondition deviceProfile = deviceProfile ?? customDeviceProfiles.Find(profile => profile.Matches(deviceInfo)); deviceProfile = deviceProfile ?? systemDeviceProfiles.Find(profile => profile.Matches(deviceInfo)); deviceProfile = deviceProfile ?? customDeviceProfiles.Find(profile => profile.LastResortMatches(deviceInfo)); deviceProfile = deviceProfile ?? systemDeviceProfiles.Find(profile => profile.LastResortMatches(deviceInfo)); // Debug.Log( "MATCHED PROFILE: " + deviceProfile.DeviceName + " (" + deviceProfile.GetType() + ")" ); // Find a matching previously attached device or create a new one. if (!deviceProfile.IsHidden) { var device = FindDetachedDevice(deviceInfo) ?? new NativeInputDevice(); device.Initialize(deviceHandle, deviceInfo, deviceProfile); 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) { 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."); } }
internal UnknownUnityInputDevice(InputDeviceProfile profile, int joystickId) : base(profile, joystickId) { AnalogSnapshot = new float[MaxAnalogs]; }
public UnityInputDevice(InputDeviceProfile profile) : base(profile.Name) { Initialize(profile, 0); }
public UnityInputDevice(InputDeviceProfile profile, int joystickId) : base(profile.Name) { Initialize(profile, joystickId); }
public UnityInputDevice( InputDeviceProfile profile, int joystickId ) : base( profile.Name ) { Initialize( profile, joystickId ); }
public UnityInputDevice( InputDeviceProfile profile ) : base( profile.Name ) { Initialize( profile, 0 ); }
internal UnknownUnityInputDevice( InputDeviceProfile profile, int joystickId ) : base( profile, joystickId ) { AnalogSnapshot = new float[MaxAnalogs]; }
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."); } }
internal void Initialize(DeviceHandle deviceHandle, InputDeviceInfo deviceInfo, InputDeviceProfile deviceProfile) { Handle = deviceHandle; Info = deviceInfo; profile = deviceProfile; SortOrder = 1000 + (int)Handle; numUnknownButtons = Math.Min((int)Info.numButtons, maxUnknownButtons); numUnknownAnalogs = Math.Min((int)Info.numAnalogs, maxUnknownAnalogs); buttons = new Int16[Info.numButtons]; analogs = new Int16[Info.numAnalogs]; AnalogSnapshot = null; const int numInputControlTypes = (int)InputControlType.Count + 1; controlSourceByTarget = new InputControlSource[numInputControlTypes]; ClearInputState(); ClearControls(); if (IsKnown) { Name = profile.DeviceName ?? Info.name; Name = Name.Replace("{NAME}", Info.name).Trim(); Meta = profile.DeviceNotes ?? Info.name; DeviceClass = profile.DeviceClass; DeviceStyle = profile.DeviceStyle; var analogMappingCount = profile.AnalogCount; for (var i = 0; i < analogMappingCount; i++) { var analogMapping = profile.AnalogMappings[i]; var analogControl = AddControl(analogMapping.Target, analogMapping.Name); 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; controlSourceByTarget[(int)analogMapping.Target] = analogMapping.Source; } var buttonMappingCount = profile.ButtonCount; for (var i = 0; i < buttonMappingCount; i++) { var buttonMapping = profile.ButtonMappings[i]; var buttonControl = AddControl(buttonMapping.Target, buttonMapping.Name); buttonControl.Passive = buttonMapping.Passive; controlSourceByTarget[(int)buttonMapping.Target] = buttonMapping.Source; } } else { Name = "Unknown Device"; Meta = Info.name; 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); } } skipUpdateFrames = 1; }
public UnityInputDevice(InputDeviceProfile deviceProfile, int joystickId, string joystickName) { profile = deviceProfile; JoystickId = joystickId; if (joystickId != 0) { SortOrder = 100 + joystickId; } SetupAnalogQueries(); SetupButtonQueries(); AnalogSnapshot = null; if (IsKnown) { Name = profile.DeviceName; Meta = profile.DeviceNotes; DeviceClass = profile.DeviceClass; DeviceStyle = profile.DeviceStyle; 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.Name + "\" as InputControlType." + analogMapping.Target + " in profile \"" + deviceProfile.DeviceName + "\" because this target is reserved as an alias. The mapping will be ignored."); } else { var analogControl = AddControl(analogMapping.Target, analogMapping.Name); 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.Name + "\" as InputControlType." + buttonMapping.Target + " in profile \"" + deviceProfile.DeviceName + "\" because this target is reserved as an alias. The mapping will be ignored."); } else { var buttonControl = AddControl(buttonMapping.Target, buttonMapping.Name); 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); } } }