public static float GetAxis(string axis) { switch (axis) { case "Horizontal": return(checkAxes(new Dictionary <string, bool>() { { axis, false }, { "LeftAnalogueHorizontal", false } })); case "Vertical": return(checkAxes(new Dictionary <string, bool>() { { axis, false }, { "LeftAnalogueVertical", false } })); case "RHorizontal": return(checkAxes(new Dictionary <string, bool>() { { "RightAnalogueHorizontal", false } })); case "RVertical": return(checkAxes(new Dictionary <string, bool>() { { "RightAnalogueVertical", false } })); default: break; } return(Input.GetAxis(axis)); }
// Use this for initialization void Start() { // Try Find our Moga Manager Game Object mogaManagerObject = GameObject.Find("MogaControllerManager"); // If it exists.. if (mogaManagerObject != null) { // Check the Moga Manager Script is correctly attached to the Moga Manager Game Object mogaManagerScript = mogaManagerObject.GetComponent <Moga_ControllerManager>(); // If it is attached... if (mogaManagerScript != null) { // Register MOGA Controller Input.RegisterMogaController(); // Get our mapped KeyCode Values and assign them. aButtonKeyCode = mogaManagerScript.p1ButtonA; bButtonKeyCode = mogaManagerScript.p1ButtonB; xButtonKeyCode = mogaManagerScript.p1ButtonX; yButtonKeyCode = mogaManagerScript.p1ButtonY; mogaFound = true; } } }
// dictionary of axes: name of axis -> whether or not to invert this axis private static float checkAxes(Dictionary <string, bool> axes) { foreach (KeyValuePair <string, bool> entry in axes) { float result = Input.GetAxis(entry.Key); if (result > epsilon || result < -epsilon) { return(entry.Value ? -result : result); } } return(0.0f); }
private static bool checkKeyAndAxisThresholdLower(KeyCode keyCode, string axis, KeyCode mogaKey) { if (Input.GetAxis(axis) < -0.95f) { return(true); } if (Input.GetKeyDown(mogaKey)) { return(true); } return(keyCode == lastKeyHit); }
private static bool checkKeyAndButton(KeyCode keyCode, string button, KeyCode mogaKey) { if (Input.GetButton(button)) { return(true); } if (Input.GetKeyDown(mogaKey)) { return(true); } return(keyCode == lastKeyHit); }
private static bool checkAlternateButton(string button, string altButton, KeyCode mogaKey) { if (Input.GetButton(altButton)) { return(true); } if (Input.GetKeyDown(mogaKey)) { return(true); } return(Input.GetButton(button)); }
public Moga_Input getInputScript() { inputScripts = Selection.activeTransform.gameObject.GetComponents <Moga_Input>(); if (inputScripts != null) // GameObject has one or more Input Script already attached { foreach (object obj in inputScripts) { Moga_Input inputScript = (Moga_Input)obj; return(inputScript); } } return(null); }
void Start() { #if UNITY_EDITOR debug = false; #else debug = false; #endif if (Grid.mogaManagerObject != null) { // Check the Moga Manager Script is correctly attached to the Moga Manager Game Object mogaManagerScript = Grid.mogaManagerObject.GetComponent <Moga_ControllerManager>(); if (mogaManagerScript != null) { Input.RegisterMogaController(); } } }
// Update is called once per frame void Update() { if (mogaFound) { this.transform.Rotate(0, -Input.GetAxis("Horizontal"), 0, Space.World); this.transform.Rotate(Input.GetAxis("Vertical"), 0, 0, Space.World); if (Input.GetKeyDown(aButtonKeyCode)) { this.GetComponent <Renderer>().material.color = Color.red; } else if (Input.GetKeyUp(aButtonKeyCode)) { this.GetComponent <Renderer>().material.color = Color.white; } if (Input.GetKeyDown(bButtonKeyCode)) { this.GetComponent <Renderer>().material.color = Color.blue; } else if (Input.GetKeyUp(bButtonKeyCode)) { this.GetComponent <Renderer>().material.color = Color.white; } if (Input.GetKeyDown(xButtonKeyCode)) { this.GetComponent <Renderer>().material.color = Color.yellow; } else if (Input.GetKeyUp(xButtonKeyCode)) { this.GetComponent <Renderer>().material.color = Color.white; } if (Input.GetKeyDown(yButtonKeyCode)) { this.GetComponent <Renderer>().material.color = Color.green; } else if (Input.GetKeyUp(yButtonKeyCode)) { this.GetComponent <Renderer>().material.color = Color.white; } } }
public static bool GetAction(string action) { // Debug.Log (mogaManagerScript.isControllerConnected ()); switch (action) { case "Jump": return(checkAlternateButton(action, "Y", mogaManagerScript.p1ButtonY)); case "Use": case "Pickup": return(checkKeyAndButton(KeyCode.E, "A", mogaManagerScript.p1ButtonA)); case "Select": return(checkKeyAndButton(KeyCode.Space, "Y", mogaManagerScript.p1ButtonY)); case "Drop": return(checkKeyAndButton(KeyCode.Z, "LB", mogaManagerScript.p1ButtonL1)); case "ToggleLaser": return(checkKeyAndButton(KeyCode.Backslash, "RB", mogaManagerScript.p1ButtonR1)); case "CursorLeft": return(checkKeyAndAxisThresholdLower(KeyCode.Z, "LeftAnalogueHorizontal", mogaManagerScript.p1ButtonL2)); case "CursorRight": return(checkKeyAndAxisThresholdUpper(KeyCode.X, "LeftAnalogueHorizontal", mogaManagerScript.p1ButtonR2)); case "PrimaryAttack": return(checkKeyAndButton(KeyCode.F, "RightTrigger", mogaManagerScript.p1ButtonR2)); case "SecondaryAttack": return(checkKeyAndButton(KeyCode.G, "LeftTrigger", mogaManagerScript.p1ButtonL2)); case "Suicide": return(KeyCode.Escape == lastKeyHit); default: break; } return(Input.GetButton(action)); }
void DebugInput() { string[] buttons = new string[] { "A", "B", "X", "Jump", "Y", "LB", "RB", "LeftTrigger", "RightTrigger", "Start", "Select" }; foreach (string button in buttons) { if (Input.GetButton(button)) { Debug.Log(button); } } string[] axes = new string[] { "Horizontal", "Vertical", "LeftAnalogueHorizontal", "LeftAnalogueVertical", "RightAnalogueHorizontal", "RightAnalogueVertical", "DPadHorizontal", "DPadVertical", "Axis7", "Axis8", "Axis9", }; foreach (string axis in axes) { float result = Input.GetAxis(axis); if (result > epsilon || result < -epsilon) { Debug.Log(axis + ": " + result); } } if (debugMoga) { KeyCode[] joystickKeys = new KeyCode[] { mogaManagerScript.p1ButtonA, mogaManagerScript.p1ButtonB, mogaManagerScript.p1ButtonX, mogaManagerScript.p1ButtonY, mogaManagerScript.p1ButtonL1, mogaManagerScript.p1ButtonR1, mogaManagerScript.p1ButtonL2, mogaManagerScript.p1ButtonR2, mogaManagerScript.p1ButtonStart, mogaManagerScript.p1ButtonSelect, mogaManagerScript.p1ButtonDPadLeft, mogaManagerScript.p1ButtonDPadRight, mogaManagerScript.p1ButtonDPadUp, mogaManagerScript.p1ButtonDPadDown }; foreach (KeyCode keyCode in joystickKeys) { if (Input.GetKeyDown(keyCode)) { Debug.Log(keyCode); } } string[] mogaAxes = new string[] { mogaManagerScript.p1AxisLookHorizontal, mogaManagerScript.p1AxisLookVertical }; foreach (string axis in mogaAxes) { float result = Input.GetAxis(axis); if (result > epsilon || result < -epsilon) { Debug.Log(axis + ": " + result); } } } }