private static string DeviceRequirementToDisplayString(InputControlScheme.DeviceRequirement requirement) { ////TODO: need something more flexible to produce correct results for more than the simple string we produce here var deviceLayout = InputControlPath.TryGetDeviceLayout(requirement.controlPath); var usage = InputControlPath.TryGetDeviceUsage(requirement.controlPath); if (!string.IsNullOrEmpty(usage)) { return($"{deviceLayout} {usage}"); } return(deviceLayout); }
private InputControl RegisterInputControl(string controlPath) { var layout = InputControlPath.TryGetDeviceLayout(controlPath); if (layout == null) { throw new Exception(string.Format("Could not parse a device layout for the {0} control path", controlPath)); } m_Layout = layout; // Check if we already have a a device created for this type of OnScreenControl int deviceIndex = GetDeviceEventIndex(layout); // If we do not have a device created yet, create a new one if (deviceIndex < 0) { var device = CreateOnScreenDevice(layout, this); if (device == null) { throw new Exception(string.Format("Could not create a device for the {0} control path", controlPath)); } return(InputControlPath.TryFindControl(device, controlPath)); } else { m_NextControlOnDevice = s_DeviceEventInfoArray[deviceIndex].firstControl.m_NextControlOnDevice; var temp = s_DeviceEventInfoArray[deviceIndex].firstControl; temp.m_NextControlOnDevice = this; return(InputControlPath.TryFindControl(s_DeviceEventInfoArray[deviceIndex].device, controlPath)); } }
/// <summary> /// Grab <see cref="InputSystem.settings"/> and set it up for editing. /// </summary> private void InitializeWithCurrentSettings() { // Find the set of available assets in the project. m_AvailableInputSettingsAssets = FindInputSettingsInProject(); // See which is the active one. m_Settings = InputSystem.settings; var currentSettingsPath = AssetDatabase.GetAssetPath(m_Settings); if (string.IsNullOrEmpty(currentSettingsPath)) { if (m_AvailableInputSettingsAssets.Length != 0) { m_CurrentSelectedInputSettingsAsset = 0; m_Settings = AssetDatabase.LoadAssetAtPath <InputSettings>(m_AvailableInputSettingsAssets[0]); InputSystem.settings = m_Settings; } } else { m_CurrentSelectedInputSettingsAsset = ArrayHelpers.IndexOf(m_AvailableInputSettingsAssets, currentSettingsPath); if (m_CurrentSelectedInputSettingsAsset == -1) { // This is odd and shouldn't happen. Solve by just adding the path to the list. m_CurrentSelectedInputSettingsAsset = ArrayHelpers.Append(ref m_AvailableInputSettingsAssets, currentSettingsPath); } ////REVIEW: should we store this by platform? EditorBuildSettings.AddConfigObject(kEditorBuildSettingsConfigKey, m_Settings, true); } // Refresh the list of assets we display in the UI. m_AvailableSettingsAssetsOptions = new GUIContent[m_AvailableInputSettingsAssets.Length]; for (var i = 0; i < m_AvailableInputSettingsAssets.Length; ++i) { var name = m_AvailableInputSettingsAssets[i]; if (name.StartsWith("Assets/")) { name = name.Substring("Assets/".Length); } if (name.EndsWith(".asset")) { name = name.Substring(0, name.Length - ".asset".Length); } if (name.EndsWith(".inputsettings")) { name = name.Substring(0, name.Length - ".inputsettings".Length); } // Ugly hack: GenericMenu iterprets "/" as a submenu path. But luckily, "/" is not the only slash we have in Unicode. m_AvailableSettingsAssetsOptions[i] = new GUIContent(name.Replace("/", "\u29f8")); } // Look up properties. m_SettingsObject = new SerializedObject(m_Settings); m_UpdateMode = m_SettingsObject.FindProperty("m_UpdateMode"); m_CompensateForScreenOrientation = m_SettingsObject.FindProperty("m_CompensateForScreenOrientation"); m_FilterNoiseOnCurrent = m_SettingsObject.FindProperty("m_FilterNoiseOnCurrent"); m_DefaultDeadzoneMin = m_SettingsObject.FindProperty("m_DefaultDeadzoneMin"); m_DefaultDeadzoneMax = m_SettingsObject.FindProperty("m_DefaultDeadzoneMax"); m_DefaultButtonPressPoint = m_SettingsObject.FindProperty("m_DefaultButtonPressPoint"); m_DefaultTapTime = m_SettingsObject.FindProperty("m_DefaultTapTime"); m_DefaultSlowTapTime = m_SettingsObject.FindProperty("m_DefaultSlowTapTime"); m_DefaultHoldTime = m_SettingsObject.FindProperty("m_DefaultHoldTime"); m_TapRadius = m_SettingsObject.FindProperty("m_TapRadius"); m_MultiTapDelayTime = m_SettingsObject.FindProperty("m_MultiTapDelayTime"); // Initialize ReorderableList for list of supported devices. var supportedDevicesProperty = m_SettingsObject.FindProperty("m_SupportedDevices"); m_SupportedDevices = new ReorderableList(m_SettingsObject, supportedDevicesProperty) { drawHeaderCallback = rect => { EditorGUI.LabelField(rect, m_SupportedDevicesText); }, onChangedCallback = list => { Apply(); }, onAddDropdownCallback = (rect, list) => { var dropdown = new InputControlPickerDropdown( new InputControlPickerState(), path => { var layoutName = InputControlPath.TryGetDeviceLayout(path) ?? path; var existingIndex = m_Settings.supportedDevices.IndexOf(x => x == layoutName); if (existingIndex != -1) { m_SupportedDevices.index = existingIndex; return; } var numDevices = supportedDevicesProperty.arraySize; supportedDevicesProperty.InsertArrayElementAtIndex(numDevices); supportedDevicesProperty.GetArrayElementAtIndex(numDevices) .stringValue = layoutName; m_SupportedDevices.index = numDevices; Apply(); }, mode: InputControlPicker.Mode.PickDevice); dropdown.Show(rect); }, drawElementCallback = (rect, index, isActive, isFocused) => { var layoutName = m_Settings.supportedDevices[index]; var icon = EditorInputControlLayoutCache.GetIconForLayout(layoutName); if (icon != null) { var iconRect = rect; iconRect.width = 20; rect.x += 20; rect.width -= 20; GUI.Label(iconRect, icon); } EditorGUI.LabelField(rect, m_Settings.supportedDevices[index]); } }; }