Skip to content

Commit 4444968

Browse files
committed
fix(AxisCreator): add remove axis method and custom axis1 and axis2
The Axis Creator now has a custom axis1 and axis2 which is used by the prefabs instead of relying on the Horizontal and Vertical axes provided by Unity as these are not clean axis settings. The AxisCreator editor window also allows deleting of existing Tilia axis inputs so its easier to upgrade. The incorrect negative multiplier in the controller mappings has also been removed now as the inversion happens on the axis setting in the Unity Input Manager.
1 parent f12b128 commit 4444968

6 files changed

Lines changed: 581 additions & 26 deletions

Editor/UnityInputManagerAxisCreator.cs

Lines changed: 41 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,11 @@ public class InputAxis
4444
private static bool isManualCheck;
4545
private static Vector2 scrollPosition;
4646

47+
private static readonly InputAxis axis1 = new InputAxis() { name = "Tilia.Input.UnityInputManager_Axis1", dead = 0.001f, sensitivity = 1f, snap = true, type = AxisType.JoystickAxis, axis = 1, joyNum = 0 };
48+
private static readonly InputAxis axis2 = new InputAxis() { name = "Tilia.Input.UnityInputManager_Axis2", dead = 0.001f, sensitivity = 1f, snap = true, invert = true, type = AxisType.JoystickAxis, axis = 2, joyNum = 0 };
4749
private static readonly InputAxis axis3 = new InputAxis() { name = "Tilia.Input.UnityInputManager_Axis3", dead = 0.001f, sensitivity = 1f, snap = true, type = AxisType.JoystickAxis, axis = 3, joyNum = 0 };
48-
private static readonly InputAxis axis4 = new InputAxis() { name = "Tilia.Input.UnityInputManager_Axis4", dead = 0.001f, sensitivity = 3f, snap = true, type = AxisType.JoystickAxis, axis = 4, joyNum = 0 };
49-
private static readonly InputAxis axis5 = new InputAxis() { name = "Tilia.Input.UnityInputManager_Axis5", dead = 0.001f, sensitivity = 3f, snap = true, invert = true, type = AxisType.JoystickAxis, axis = 5, joyNum = 0 };
50+
private static readonly InputAxis axis4 = new InputAxis() { name = "Tilia.Input.UnityInputManager_Axis4", dead = 0.001f, sensitivity = 1f, snap = true, type = AxisType.JoystickAxis, axis = 4, joyNum = 0 };
51+
private static readonly InputAxis axis5 = new InputAxis() { name = "Tilia.Input.UnityInputManager_Axis5", dead = 0.001f, sensitivity = 1f, snap = true, invert = true, type = AxisType.JoystickAxis, axis = 5, joyNum = 0 };
5052
private static readonly InputAxis axis6 = new InputAxis() { name = "Tilia.Input.UnityInputManager_Axis6", dead = 0.001f, sensitivity = 1f, snap = true, type = AxisType.JoystickAxis, axis = 6, joyNum = 0 };
5153
private static readonly InputAxis axis7 = new InputAxis() { name = "Tilia.Input.UnityInputManager_Axis7", dead = 0.001f, sensitivity = 1f, snap = true, type = AxisType.JoystickAxis, axis = 7, joyNum = 0 };
5254
private static readonly InputAxis axis8 = new InputAxis() { name = "Tilia.Input.UnityInputManager_Axis8", dead = 0.001f, sensitivity = 1f, snap = true, type = AxisType.JoystickAxis, axis = 8, joyNum = 0 };
@@ -75,10 +77,11 @@ public void OnGUI()
7577
scrollPosition = scrollViewScope.scrollPosition;
7678

7779
bool mappingsExist = AxisDefined(axis3.name);
78-
const string mappingsNotFound = "The required Input Axis Definitions have not been found, click the 'Add Input Axis Definitions' button below to automatically created the required Input Axis Definitions.";
79-
const string mappingsFound = "The required Input Axis Definitions have already been created. If you would like to delete these Input Axis Definitions then manually remove the Input axes from the Unity Input Manager found in the Unity Project Settings.";
80+
const string mappingsNotFound = "The required Input Axis Definitions have not been found.\n\nClick the 'Add Input Axis Definitions' button below to automatically created the required Input Axis Definitions.";
81+
const string mappingsFound = "The required Input Axis Definitions have already been created.\n\nClick the 'Delete Input Definitions' button below to delete these Input Axis Definitions.";
8082
const string hideToggleLabel = "Do not prompt again.";
8183
const string addMappingsButtonLabel = "Add Input Definitions";
84+
const string deleteMappingsButtonLabel = "Delete Input Definitions";
8285
string mappingText = mappingsExist ? mappingsFound : mappingsNotFound;
8386
MessageType messageType = mappingsExist ? MessageType.Info : MessageType.Warning;
8487

@@ -101,6 +104,14 @@ public void OnGUI()
101104
Close();
102105
}
103106
}
107+
else
108+
{
109+
if (GUILayout.Button(deleteMappingsButtonLabel))
110+
{
111+
DeleteInputMappings();
112+
}
113+
}
114+
104115
}
105116

106117
if (changeCheckScope.changed)
@@ -138,12 +149,17 @@ private static void ManageInputMappings()
138149

139150
private static void AddInputMappings()
140151
{
141-
for (int axisIndex = 3; axisIndex <= 20; axisIndex++)
152+
for (int axisIndex = 1; axisIndex <= 20; axisIndex++)
142153
{
143154
AddAxis((InputAxis)Type.GetType("Tilia.Input.UnityInputManager.UnityInputManagerAxisCreator").GetField("axis" + axisIndex, BindingFlags.NonPublic | BindingFlags.Static).GetValue(null));
144155
}
145156
}
146157

158+
private static void DeleteInputMappings()
159+
{
160+
RemoveAllAxes();
161+
}
162+
147163
private static SerializedProperty GetChildProperty(SerializedProperty parent, string name)
148164
{
149165
SerializedProperty child = parent.Copy();
@@ -180,12 +196,12 @@ private static void AddAxis(InputAxis axis)
180196
}
181197

182198
SerializedObject serializedObject = new SerializedObject(AssetDatabase.LoadAllAssetsAtPath("ProjectSettings/InputManager.asset")[0]);
183-
SerializedProperty axesProperty = serializedObject.FindProperty("m_Axes");
199+
SerializedProperty axesArrayProperty = serializedObject.FindProperty("m_Axes");
184200

185-
axesProperty.arraySize++;
201+
axesArrayProperty.arraySize++;
186202
serializedObject.ApplyModifiedProperties();
187203

188-
SerializedProperty axisProperty = axesProperty.GetArrayElementAtIndex(axesProperty.arraySize - 1);
204+
SerializedProperty axisProperty = axesArrayProperty.GetArrayElementAtIndex(axesArrayProperty.arraySize - 1);
189205

190206
GetChildProperty(axisProperty, "m_Name").stringValue = axis.name;
191207
GetChildProperty(axisProperty, "descriptiveName").stringValue = axis.descriptiveName;
@@ -206,6 +222,23 @@ private static void AddAxis(InputAxis axis)
206222
serializedObject.ApplyModifiedProperties();
207223
}
208224

225+
private static void RemoveAllAxes()
226+
{
227+
SerializedObject serializedObject = new SerializedObject(AssetDatabase.LoadAllAssetsAtPath("ProjectSettings/InputManager.asset")[0]);
228+
SerializedProperty axesArrayProperty = serializedObject.FindProperty("m_Axes");
229+
230+
for (int i = axesArrayProperty.arraySize - 1; i >= 0; i--)
231+
{
232+
SerializedProperty axisProperty = axesArrayProperty.GetArrayElementAtIndex(i);
233+
string axisName = GetChildProperty(axisProperty, "m_Name").stringValue;
234+
if (axisName.Contains("Tilia.Input.UnityInputManager"))
235+
{
236+
axesArrayProperty.DeleteArrayElementAtIndex(i);
237+
}
238+
}
239+
serializedObject.ApplyModifiedProperties();
240+
}
241+
209242
private static string GetProjectKeyName()
210243
{
211244
return hidePromptKey + AssetDatabase.AssetPathToGUID("Assets");

0 commit comments

Comments
 (0)