private IEnumerator RecordKeys(UIDynamicButton btn, ICommandInvoker commandInvoker, Color btnColor, int slot) { isRecording = true; var expire = float.MaxValue; var setKeybindingList = new List <KeyChord>(); while (Time.unscaledTime < expire) { yield return(0); if (Input.GetKeyDown(KeyCode.Mouse0)) { continue; } if (Input.GetKeyUp(KeyCode.Mouse0)) { // Apply SaveKeyMap(setKeybindingList, commandInvoker, slot); StopRecording(btn, btnColor, commandInvoker, slot); yield break; } if (Input.GetKeyDown(KeyCode.Escape)) { // Cancel StopRecording(btn, btnColor, commandInvoker, slot); yield break; } var key = KeyCodes.bindableKeyCodes.GetCurrentDown(); if (key == KeyCode.None) { continue; } if (!KeyChord.IsValid(key)) { continue; } var ctrlDown = Input.GetKey(KeyCode.LeftControl) || Input.GetKey(KeyCode.RightControl); var altDown = Input.GetKey(KeyCode.LeftAlt) || Input.GetKey(KeyCode.RightAlt); var shiftDown = Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift); var binding = new KeyChord(key, ctrlDown, altDown, shiftDown); setKeybindingList.Add(binding); btn.label = setKeybindingList.GetKeyChordsAsString(); expire = Time.unscaledTime + Settings.TimeoutLen; } SaveKeyMap(setKeybindingList, commandInvoker, slot); StopRecording(btn, btnColor, commandInvoker, slot); }
private IEnumerator RecordAnalog(UIDynamicButton btn, ICommandInvoker commandInvoker, Color btnColor, int slot) { isRecording = true; var leftKeybinding = KeyChord.empty; while (true) { yield return(0); if (Input.GetKeyDown(KeyCode.Mouse0)) { continue; } if (Input.GetKeyUp(KeyCode.Mouse0)) { var mapped = analogMapManager.GetMapByName(commandInvoker.commandName, slot); if (mapped != null) { analogMapManager.maps.Remove(mapped); } break; } if (Input.GetKeyDown(KeyCode.Escape)) { break; } var ctrlDown = Input.GetKey(KeyCode.LeftControl) || Input.GetKey(KeyCode.RightControl); var altDown = Input.GetKey(KeyCode.LeftAlt) || Input.GetKey(KeyCode.RightAlt); var shiftDown = Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift); var keyUp = KeyCodes.bindableKeyCodes.GetCurrentUp(); if (keyUp != KeyCode.None) { if (!KeyChord.IsValid(keyUp)) { continue; } var binding = new KeyChord(keyUp, ctrlDown, altDown, shiftDown); if (leftKeybinding.key == KeyCode.None) { btn.label = "Type other direction..."; leftKeybinding = binding; continue; } else if (keyUp == leftKeybinding.key) { continue; } var map = new AnalogMap(leftKeybinding, binding, commandInvoker.commandName, slot); SaveAnalogMap(commandInvoker, binding, map); StopRecording(btn, btnColor, commandInvoker, slot); yield break; } foreach (var axisName in _knownAxisNames) { var axisValue = AnalogMap.GetAxis(axisName); if (Mathf.Abs(axisValue) < 0.75f) { continue; } var key = KeyCodes.bindableKeyCodes.GetCurrent(); // We don't want to take over the mouse! if (axisName.StartsWith("Mouse") && key == KeyCode.None && !ctrlDown && !shiftDown && !altDown) { continue; } var binding = new KeyChord(key, ctrlDown, altDown, shiftDown); var map = new AnalogMap(binding, axisName, axisValue < 0, commandInvoker.commandName, slot); SaveAnalogMap(commandInvoker, binding, map); StopRecording(btn, btnColor, commandInvoker, slot); yield break; } } StopRecording(btn, btnColor, commandInvoker, slot); }