Advertisement
infinite_ammo

InputOverride.cs

Nov 24th, 2013
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.09 KB | None | 0 0
  1. public class EditorMenu
  2.     {
  3.         [MenuItem("Custom/Setup InputManager Asset")]
  4.         static void SetupInputManagerAsset()
  5.         {
  6.             var inputManagerAsset = AssetDatabase.LoadAllAssetsAtPath( "ProjectSettings/InputManager.asset" )[0];
  7.             var serializedObject = new SerializedObject( inputManagerAsset );
  8.             var axisArray = serializedObject.FindProperty( "m_Axes" );
  9.  
  10.             axisArray.arraySize = 100;
  11.             serializedObject.ApplyModifiedProperties();
  12.  
  13.             int axisIndex = 0;
  14.             for (int joystick = 1; joystick <= 10; joystick++)
  15.             {
  16.                 for (int analog = 0; analog <= 9; analog++)
  17.                 {
  18.                     var axis = axisArray.GetArrayElementAtIndex( axisIndex++ );
  19.  
  20.                     GetChildProperty( axis, "m_Name" ).stringValue = string.Format( "joystick {0} analog {1}", joystick, analog );
  21.                     GetChildProperty( axis, "descriptiveName" ).stringValue = "";
  22.                     GetChildProperty( axis, "descriptiveNegativeName" ).stringValue = "";
  23.                     GetChildProperty( axis, "negativeButton" ).stringValue = "";
  24.                     GetChildProperty( axis, "positiveButton" ).stringValue = "";
  25.                     GetChildProperty( axis, "altNegativeButton" ).stringValue = "";
  26.                     GetChildProperty( axis, "altPositiveButton" ).stringValue = "";
  27.                     GetChildProperty( axis, "gravity" ).floatValue = 10.0f;
  28.                     GetChildProperty( axis, "dead" ).floatValue = 0.001f;
  29.                     GetChildProperty( axis, "sensitivity" ).floatValue = 1.0f;
  30.                     GetChildProperty( axis, "snap" ).boolValue = false;
  31.                     GetChildProperty( axis, "invert" ).boolValue = false;
  32.                     GetChildProperty( axis, "type" ).intValue = 2;
  33.                     GetChildProperty( axis, "axis" ).intValue = analog;
  34.                     GetChildProperty( axis, "joyNum" ).intValue = joystick;
  35.                 }
  36.             }
  37.  
  38.             serializedObject.ApplyModifiedProperties();
  39.  
  40.             EditorUtility.DisplayDialog( "Success", "InputManager asset has been initialized.", "OK" );
  41.         }
  42.  
  43.  
  44.         static SerializedProperty GetChildProperty( SerializedProperty parent, string name )
  45.         {
  46.             SerializedProperty child = parent.Copy();
  47.             child.Next( true );
  48.  
  49.             do
  50.             {
  51.                 if (child.name == name)
  52.                 {
  53.                     return child;
  54.                 }
  55.             }
  56.             while (child.Next( false ));
  57.  
  58.             return null;
  59.         }
  60.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement