Skip to content

Commit c6b1b8a

Browse files
Merge pull request #40 from ExtendRealityLtd/fix/axis-data
fix(AxisCreator): add remove axis method and custom axis1 and axis2
2 parents f12b128 + 4444968 commit c6b1b8a

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)