Guest User

Untitled

a guest
Jul 19th, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.29 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public static class Brainput{
  6.  
  7. public static float GetAxis(int controller, int axis){
  8. return Input.GetAxis("joystick " + controller + " analog " + axis);
  9. }
  10. public static bool GetButton(int controller, int button){
  11. return Input.GetButton("joystick " + controller + " button " + button);
  12. }
  13. public static bool GetButtonDown(int controller, int button){
  14. return Input.GetButtonDown("joystick " + controller + " button " + button);
  15. }
  16. public static bool GetButtonUp(int controller, int button){
  17. return Input.GetButtonUp("joystick " + controller + " button " + button);
  18. }
  19.  
  20. public static float[] GetAxes(int controller, params int[] axes){
  21. float[] values = new float[axes.Length];
  22. for (int a = 0; a < axes.Length; a++){
  23. values[a] = GetAxis(controller, axes[a]);
  24. }
  25. return values;
  26. }
  27. public static bool[] GetButtons(int controller, params int[] buttons){
  28. bool[] values = new bool[buttons.Length];
  29. for (int a = 0; a < buttons.Length; a++){
  30. values[a] = GetButton(controller, buttons[a]);
  31. }
  32. return values;
  33. }
  34. public static bool[] GetButtonsDown(int controller, params int[] buttons){
  35. bool[] values = new bool[buttons.Length];
  36. for (int a = 0; a < buttons.Length; a++){
  37. values[a] = GetButtonDown(controller, buttons[a]);
  38. }
  39. return values;
  40. }
  41. public static bool[] GetButtonsUp(int controller, params int[] buttons){
  42. bool[] values = new bool[buttons.Length];
  43. for (int a = 0; a < buttons.Length; a++){
  44. values[a] = GetButtonUp(controller, buttons[a]);
  45. }
  46. return values;
  47. }
  48. public static bool GetAnyButtons(int controller, params int[] buttons){
  49. for (int a = 0; a < buttons.Length; a++){
  50. if(GetButton(controller, buttons[a]))
  51. return true;
  52. }
  53. return false;
  54. }
  55. public static bool GetAnyButtonsDown(int controller, params int[] buttons){
  56. for (int a = 0; a < buttons.Length; a++){
  57. if(GetButtonDown(controller, buttons[a]))
  58. return true;
  59. }
  60. return false;
  61. }
  62. public static bool GetAnyButtonsUp(int controller, params int[] buttons){
  63. for (int a = 0; a < buttons.Length; a++){
  64. if(GetButtonUp(controller, buttons[a]))
  65. return true;
  66. }
  67. return false;
  68. }
  69.  
  70. public static Vector2 GetJoystick(int controller){
  71. float[] values = GetAxes(controller, 0, 1);
  72. return new Vector2(values[0], values[1]);
  73. }
  74.  
  75. }
Add Comment
Please, Sign In to add comment