Skip to content

Instantly share code, notes, and snippets.

@kurtdekker
Created September 20, 2021 22:14
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 kurtdekker/f41391a165881c5fda9f446dcc3c0089 to your computer and use it in GitHub Desktop.
Save kurtdekker/f41391a165881c5fda9f446dcc3c0089 to your computer and use it in GitHub Desktop.
Display and Test ALL Unity3D inputs (old Input System)
using UnityEngine;
using System.Collections;
using UnityEditor;
// @kurtdekker
// You must put this in an Editor folder!
// Once compiled, you must run it from Menu -> Assets -> ReadInputManager
public class ReadInputManager
{
public static void ReadAxes()
{
var inputManager = AssetDatabase.LoadAllAssetsAtPath("ProjectSettings/InputManager.asset")[0];
SerializedObject obj = new SerializedObject(inputManager);
SerializedProperty axisArray = obj.FindProperty("m_Axes");
if (axisArray.arraySize == 0)
Debug.LogError("No Axes Defined!");
string listOfInputAxes = "";
for( int i = 0; i < axisArray.arraySize; ++i )
{
var axis = axisArray.GetArrayElementAtIndex(i);
var name = axis.FindPropertyRelative("m_Name").stringValue;
var axisVal = axis.FindPropertyRelative("axis").intValue;
var inputType = (InputType)axis.FindPropertyRelative("type").intValue;
// @kurtdekker
// Debug.Log(name);
// Debug.Log(axisVal);
// Debug.Log(inputType);
listOfInputAxes += name + ",";
}
string AxesListPath = @"Assets/Resources/" + testinputs.AxesResourceName + ".txt";
System.IO.File.WriteAllText( AxesListPath, listOfInputAxes);
AssetDatabase.ImportAsset( AxesListPath );
Debug.Log( "Captured InputManager asset axes to file.");
}
public enum InputType
{
KeyOrMouseButton,
MouseMovement,
JoystickAxis,
};
[MenuItem("Assets/ReadInputManager")]
public static void DoRead()
{
ReadAxes();
}
}
using UnityEngine;
using UnityEngine.SceneManagement;
using System.Collections;
using System.Collections.Generic;
// @kurtdekker
// once you have run the Assets -> ReadInputManager, put
// this script on a blank GameObject and press Play
public class testinputs : MonoBehaviour
{
public bool AlphaSort;
public const string AxesResourceName = "InputManagerAxes/InputManagerAxes";
string[] axes;
void Start ()
{
string[] all = Resources.Load<TextAsset>( AxesResourceName).text.Split(
new char[] { ','},
System.StringSplitOptions.RemoveEmptyEntries);
// remove dupes
HashSet<string> hash = new HashSet<string>();
foreach( var s in all)
{
hash.Add( s);
}
axes = new string[hash.Count];
hash.CopyTo( axes, 0);
if (AlphaSort)
{
System.Array.Sort( axes);
}
}
void OnGUI()
{
float x = Screen.width * 0.3f;
float y = Screen.height * 0.05f;
float w = Screen.width * 0.2f;
float h = Screen.height - y * 2;
// @kurtdekker
// int fs = 12;
for( int i = 0; i < axes.Length; i++)
{
Rect r = new Rect( x, y + (h * i) / axes.Length, w, h / axes.Length);
GUI.Label( r, axes[i]
// , OurStyles.LABELCJ(fs)
);
r.x += r.width;
GUI.Label( r, System.String.Format( "{0:0.00}", Input.GetAxisRaw( axes[i]))
// , OurStyles.LABELCJ(fs)
);
}
}
}
@kurtdekker
Copy link
Author

// testinputs for Unity - by Kurt Dekker @kurtdekker

To use the above files:

Make a new project
Make a folder structure:

Editor
Resources/InputManagerAxes
Scripts

In Editor, place the ReadInputManager.cs script
In Scripts, place the testinputs.cs script

Open Unity, let everything compile.

Select Assets -> ReadInputManager

That will create the InputManagerAxes file

Make a blank scene

Add a blank GameObject

Add the testinputs.cs script to the blank GameObject

Press RUN

Wiggle your inputs and observe!!

@kurtdekker
Copy link
Author

Screen Shot 2021-09-20 at 3 17 09 PM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment