Created
August 4, 2013 18:31
-
-
Save AngryAnt/6151366 to your computer and use it in GitHub Desktop.
Adding axes to the Unity input manager. As described in the post http://angryant.com/2013/08/04/Unity-Hacks-Dual-sticks/
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public static void AddAxis (AxisDefinition axis) | |
| { | |
| if (AxisDefined (axis.name)) | |
| { | |
| throw new System.ArgumentException (string.Format ("Specified axis \"{0}\" already exists", axis.name)); | |
| } | |
| SerializedObject serializedObject = new SerializedObject (AssetDatabase.LoadAllAssetsAtPath ("ProjectSettings/InputManager.asset")[0]); | |
| SerializedProperty axesProperty = serializedObject.FindProperty ("m_Axes"); | |
| axesProperty.arraySize++; | |
| serializedObject.ApplyModifiedProperties (); | |
| SerializedProperty axisProperty = axesProperty.GetArrayElementAtIndex (axesProperty.arraySize - 1); | |
| GetChildProperty (axisProperty, "m_Name").stringValue = axis.name; | |
| GetChildProperty (axisProperty, "descriptiveName").stringValue = axis.descriptiveName; | |
| GetChildProperty (axisProperty, "descriptiveNegativeName").stringValue = axis.descriptiveNegativeName; | |
| GetChildProperty (axisProperty, "negativeButton").stringValue = axis.negativeButton; | |
| GetChildProperty (axisProperty, "positiveButton").stringValue = axis.positiveButton; | |
| GetChildProperty (axisProperty, "altNegativeButton").stringValue = axis.altNegativeButton; | |
| GetChildProperty (axisProperty, "altPositiveButton").stringValue = axis.altPositiveButton; | |
| GetChildProperty (axisProperty, "gravity").floatValue = axis.gravity; | |
| GetChildProperty (axisProperty, "dead").floatValue = axis.dead; | |
| GetChildProperty (axisProperty, "sensitivity").floatValue = axis.sensitivity; | |
| GetChildProperty (axisProperty, "snap").boolValue = axis.snap; | |
| GetChildProperty (axisProperty, "invert").boolValue = axis.invert; | |
| GetChildProperty (axisProperty, "type").intValue = (int)axis.type; | |
| GetChildProperty (axisProperty, "axis").intValue = axis.axis - 1; | |
| GetChildProperty (axisProperty, "joyNum").intValue = axis.joyNum; | |
| serializedObject.ApplyModifiedProperties (); | |
| } | |
| public static SerializedProperty GetChildProperty (SerializedProperty parent, string name) | |
| { | |
| SerializedProperty child = parent.Copy (); | |
| child.Next (true); | |
| do | |
| { | |
| if (child.name == name) | |
| { | |
| return child; | |
| } | |
| } | |
| while (child.Next (false)); | |
| return null; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment