Files
2025-05-13 03:30:23 +03:00

75 lines
1.6 KiB
C#

using UnityEditor;
using UnityEngine;
class InputEditor : EditorWindow {
[MenuItem ("L/InputEditor")]
static void ShowWindow () {
EditorWindow.GetWindow (typeof(InputEditor));
}
public enum AxisType{
KeyOrMouseButton = 0,
MouseMovement = 1,
JoystickAxis = 2
}
private bool _renameAxis;
void OnGUI () {
_renameAxis = GUILayout.Toggle (_renameAxis, "Rename axis");
if (GUILayout.Button ("Reset input axes")) {
var serializedObject = new SerializedObject(AssetDatabase.LoadAllAssetsAtPath("ProjectSettings/InputManager.asset")[0]);
int axisId = 0;
while(true){
var axesProperty = serializedObject.FindProperty("m_Axes");
axesProperty.Next(true);
axesProperty.Next(true);
axesProperty.Next(true);
bool fail = false;
for(int i = 0; i < axisId; ++i){
if(!axesProperty.Next(false)){
fail = true;
break;
}
}
if(fail){
break;
}
int propId = 0;
//go deeper - into axis properties
axesProperty.Next(true);
do{
switch(propId){
case 0:
if(_renameAxis){
axesProperty.stringValue = "Axis" + axisId;
}
break;
case 9: //sensitivity
axesProperty.floatValue = 1.0f;
break;
case 10: //snap
case 11: //invert
break;
case 12: //type
axesProperty.enumValueIndex = (int)AxisType.JoystickAxis;
break;
case 13: //axis
axesProperty.intValue = axisId;
break;
}
propId++;
}while(axesProperty.Next(false) && propId < 15);
axisId++;
}
serializedObject.ApplyModifiedProperties();
}
}
}