public bool HasPressed(InButton Button) { //Prevent false click when mixing Game elements with UI. if (Button.MainButton == KeyCode.Mouse0 || Button.AltButton == KeyCode.Mouse0) { if (Input.GetMouseButton(0)) { if (EventSystem.current.IsPointerOverGameObject()) { return(false); } } } //Unfortunately we cannot use our function (IsKeyPressed) here since we would have to //iterate all over the keycode to know whether or not a key is pressed. return(Input.GetKey(Button.MainButton) || Input.GetKey(Button.AltButton)); }
/* * When initializing we don't know if player has saved preferences yet. * This means that GetString("XButton") may not exists yet thus returning the default one. * PlayerPrefs will be saved once the user manually save them on the settings menu. */ private void Init() { KeyCode LocalLeftButton = (KeyCode)System.Enum.Parse(typeof(KeyCode), PlayerPrefs.GetString("LeftButton", "A")); KeyCode LocalAltLeftButton = (KeyCode)System.Enum.Parse(typeof(KeyCode), PlayerPrefs.GetString("AltLeftButton", "LeftArrow")); LeftButton = new InButton(LocalLeftButton, LocalAltLeftButton); KeyCode LocalRightButton = (KeyCode)System.Enum.Parse(typeof(KeyCode), PlayerPrefs.GetString("RightButton", "D")); KeyCode LocalAltRightButton = (KeyCode)System.Enum.Parse(typeof(KeyCode), PlayerPrefs.GetString("AltRightButton", "RightArrow")); RightButton = new InButton(LocalRightButton, LocalAltRightButton); KeyCode LocalUpButton = (KeyCode)System.Enum.Parse(typeof(KeyCode), PlayerPrefs.GetString("UpButton", "Space")); KeyCode LocalAltUpButton = (KeyCode)System.Enum.Parse(typeof(KeyCode), PlayerPrefs.GetString("AltUpButton", "UpArrow")); UpButton = new InButton(LocalUpButton, LocalAltUpButton); KeyCode LocalActionButton = (KeyCode)System.Enum.Parse(typeof(KeyCode), PlayerPrefs.GetString("ActionButton", "LeftControl")); KeyCode LocalAltActionButton = (KeyCode)System.Enum.Parse(typeof(KeyCode), PlayerPrefs.GetString("AltActionButton", "RightControl")); ActionButton = new InButton(LocalActionButton, LocalAltActionButton); }
private bool IsKeyPressed(InButton InButton, KeyCode InKey) { return(InButton.MainButton == InKey || InButton.AltButton == InKey); }