public bool GetButton(string name) { if (m_DisableInput) { return(false); } if (m_ButtonInputCommands.ContainsKey(name)) { ButtonInputCommand inputCommand = m_ButtonInputCommands[name]; //Check for keyboard input first (only return on success) bool result = false; if (inputCommand.KeyCode != KeyCode.None) { switch (inputCommand.ButtonState) { case ButtonState.OnPress: result = Input.GetKeyDown(inputCommand.KeyCode); break; case ButtonState.OnRelease: result = Input.GetKeyUp(inputCommand.KeyCode); break; case ButtonState.Pressed: result = Input.GetKey(inputCommand.KeyCode); break; case ButtonState.Released: result = (!Input.GetKey(inputCommand.KeyCode)); break; default: result = false; break; } if (result) { return(true); } } #if !UNITY_WEBGL //Check for controller, always return regardless of success if (inputCommand.ButtonCode != ControllerButtonCode.None) { switch (inputCommand.ButtonState) { case ButtonState.OnPress: return(ControllerInput.GetButtonDown(inputCommand.ControllerIndex, inputCommand.ButtonCode)); case ButtonState.OnRelease: return(ControllerInput.GetButtonUp(inputCommand.ControllerIndex, inputCommand.ButtonCode)); case ButtonState.Pressed: return(ControllerInput.GetButton(inputCommand.ControllerIndex, inputCommand.ButtonCode)); case ButtonState.Released: return(!ControllerInput.GetButton(inputCommand.ControllerIndex, inputCommand.ButtonCode)); default: break; } } return(false); #endif } Debug.Log("No button with name: " + name + " was found!"); return(false); }
public void BindButton(string name, KeyCode keyCode, ButtonState buttonState) { if (m_ButtonInputCommands.ContainsKey(name)) { ButtonInputCommand inputCommand = m_ButtonInputCommands[name]; inputCommand.KeyCode = keyCode; inputCommand.ButtonState = buttonState; return; } m_ButtonInputCommands.Add(name, new ButtonInputCommand(0, keyCode, ControllerButtonCode.None, buttonState)); }