// Begin a keybind, preventing other keys from being bound and stopping any current bindings public void StartBind(KeyBindButton button) { if (!isBinding) { isBinding = true; UpdateButtonText(); currentText = button.displayText; if (currentText != null) { key = button.inputKey; prevText = currentText.text; currentText.text = ""; } else { Debug.LogError("Missing text component of this button"); } } }
public void Update() { if (this.PendingBindButton != null) { if (this.SkipFrame) { this.SkipFrame = false; return; } for (var i = 0; i < this.Keys.Length; i++) { var vKey = this.Keys[i]; if (Input.GetKeyDown(vKey)) { if (vKey == KeyCode.Escape) { this.PendingBindButton.SetDefault(); this.PendingBindButton = null; UIManager.Instance.MainMenu.IgnoreEsc = true; return; } SettingsManager.Instance.SetKeyBind(this.PendingBindButton.BindName, vKey); this.PendingBindButton.UpdateText(vKey.ToString()); this.PendingBindButton.SetDefault(); this.PendingBindButton = null; this.RefreshControls(); return; } } } else if (Input.GetKeyDown(KeyCode.Escape)) { UIManager.Instance.MainMenu.IgnoreEsc = true; this.Hide(); } }
IEnumerator AddInputs() { yield return(new WaitForSeconds(0.1f)); // Inputs are here, let's add them! for (int i = 0; i < inputManager.Inputs.Count; i++) { CustomInput input = inputManager.Inputs [i]; // If we don't want to show this control (for whatever reason) if (!input.displayInControls) { continue; } // Does it need a title? string[] prefix = input.name.Split('_'); if (lastAddedPrefix != prefix[0]) { lastAddedPrefix = prefix [0]; GameObject title = Instantiate(titleTextPrefab, bindingPanel.transform); title.GetComponent <TMP_Text> ().text = languageManager.GetString("control_" + prefix [0].ToLower()); } // Panel itself GameObject newPanel = Instantiate(keyBindPrefab, bindingPanel.transform); newPanel.name = input.name; // Disable the button if (!input.allowRebinding) { newPanel.GetComponent <Button> ().interactable = false; newPanel.transform.Find("Button").GetComponent <Image> ().color = new Color(0.8f, 0.8f, 0.8f); } KeyBindButton kbb = newPanel.GetComponent <KeyBindButton> (); kbb.inputKey = input.name; newPanel.transform.Find("Title").GetComponent <TMP_Text> ().text = languageManager.GetString("control_" + input.name.ToLower()); } }
public void SetKeyBind(KeyBindButton keyBind) { this.PendingBindButton = keyBind; this.PendingBindButton.SetPending(); this.SkipFrame = true; }