Skip to content

Instantly share code, notes, and snippets.

@Ratstail91
Created June 24, 2020 20:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Ratstail91/30a44ee24ba44d56a1258268bfd76c42 to your computer and use it in GitHub Desktop.
Save Ratstail91/30a44ee24ba44d56a1258268bfd76c42 to your computer and use it in GitHub Desktop.
I hope the boss doesn't mind me sharing this file... wait, I am the boss!
using System;
using UnityEngine;
//DOCS: INPUT_KEYBOARD falls back to the legacy unity input system
//TODO: nintendo switch controls
public static class InputLayer {
//virtual inputs for Candy Raid
public enum Button {
ATTACK, SWITCH, PAUSE
}
public enum Axis {
HORIZONTAL, VERTICAL
}
public static bool GetButton(Button button) {
#if INPUT_KEYBOARD
switch(button) {
case Button.ATTACK:
return Input.GetButton("Attack");
case Button.SWITCH:
return Input.GetButton("Switch");
case Button.PAUSE:
return Input.GetButton("Pause");
default:
throw new ArgumentException("unknown button");
}
#else
throw new InvalidOperationException("method not implemented");
#endif
}
public static bool GetButtonDown(Button button) {
#if INPUT_KEYBOARD
switch(button) {
case Button.ATTACK:
return Input.GetButtonDown("Attack");
case Button.SWITCH:
return Input.GetButtonDown("Switch");
case Button.PAUSE:
return Input.GetButtonDown("Pause");
default:
throw new ArgumentException("unknown button");
}
#else
throw new InvalidOperationException("method not implemented");
#endif
}
public static bool GetButtonUp(Button button) {
#if INPUT_KEYBOARD
switch(button) {
case Button.ATTACK:
return Input.GetButtonUp("Attack");
case Button.SWITCH:
return Input.GetButtonUp("Switch");
case Button.PAUSE:
return Input.GetButtonUp("Pause");
default:
throw new ArgumentException("unknown button");
}
#else
throw new InvalidOperationException("method not implemented");
#endif
}
public static float GetAxis(Axis axis) {
#if INPUT_KEYBOARD
switch(axis) {
case Axis.VERTICAL:
return Input.GetAxis("Vertical");
case Axis.HORIZONTAL:
return Input.GetAxis("Horizontal");
default:
throw new ArgumentException("unknown axis");
}
#else
throw new InvalidOperationException("method not implemented");
#endif
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment