Skip to content

Instantly share code, notes, and snippets.

@mindfulvector
Created May 27, 2024 17:36
Show Gist options
  • Save mindfulvector/c721ec175952a052ef21df3e8c29387e to your computer and use it in GitHub Desktop.
Save mindfulvector/c721ec175952a052ef21df3e8c29387e to your computer and use it in GitHub Desktop.
/*
Copyright 2024. Isaac Raway and Stone Orb Software.
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
using UnityEngine;
using System.Collections.Generic;
public class TestJoystickInput : MonoBehaviour
{
private readonly string[] buttons = {
"A",
"B",
"X",
"Y",
"Back",
"Start",
"LeftStickClick",
"RightStickClick",
"LT",
"RT",
"LB",
"RB",
};
// Dictionary to store the state of each button
private readonly Dictionary<string, bool> buttonStates = new Dictionary<string, bool>
{
{"A", false},
{"B", false},
{"X", false},
{"Y", false},
{"Back", false},
{"Start", false},
{"Left Stick Click", false},
{"Right Stick Click", false},
{"LT", false},
{"RT", false}
};
void Update()
{
// Update the button states based on input
foreach(var button in buttons) {
buttonStates[button] = Input.GetButton(button);
if(button.Length == 2) {
buttonStates[button] = Input.GetAxis(button) != 0;
}
}
}
void OnGUI()
{
// Set the position and size of the GUI label
int labelWidth = 400;
int labelHeight = 20;
int startX = 10;
int startY = Screen.height - labelHeight - 10;
int padding = 5;
// Draw each button state as a label in the bottom left corner
foreach (var buttonState in buttonStates)
{
// Get the current input manager setting
//string currentSetting = GetInputManagerSetting(buttonState.Key);
// Check if the current setting matches the expected setting
//bool isCorrect = currentSetting == expectedButtons[buttonState.Key];
// Set the color based on whether the setting is correct
GUI.color = Color.white; // isCorrect ? Color.white : Color.red;
// Draw the label
GUI.Label(new Rect(startX, startY, labelWidth, labelHeight), $"{buttonState.Key}: {(buttonState.Value ? "Pressed" : "Released")}");
// Move to the next line
startY -= (labelHeight + padding);
}
// Reset the GUI color
GUI.color = Color.white;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment