Advertisement
Guest User

Untitled

a guest
Dec 15th, 2019
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.24 KB | None | 0 0
  1. #if UNITY_EDITOR
  2.  
  3. using System.Collections.Generic;
  4. using UnityEditor;
  5.  
  6. public class InputManagerAsset
  7. {
  8.     public enum InputType
  9.     {
  10.         KeyOrMouseButton,
  11.         MouseMovement,
  12.         JoystickAxis
  13.     };
  14.  
  15.     public static void ReadAxes( List<string> names = null , List<InputType> types = null )
  16.     {
  17.         names.Clear();
  18.         types.Clear();
  19.  
  20.         var inputManager = AssetDatabase.LoadAllAssetsAtPath("ProjectSettings/InputManager.asset")[0];
  21.  
  22.         SerializedObject obj = new SerializedObject(inputManager);
  23.  
  24.         SerializedProperty axisArray = obj.FindProperty("m_Axes");
  25.  
  26.         if( axisArray.arraySize == 0 )
  27.             return;
  28.  
  29.         for( int i = 0; i < axisArray.arraySize; ++i )
  30.         {
  31.             SerializedProperty axis = axisArray.GetArrayElementAtIndex(i);
  32.  
  33.             string name = axis.FindPropertyRelative("m_Name").stringValue;
  34.  
  35.             if( string.IsNullOrEmpty( name ) )
  36.                 continue;
  37.  
  38.             if( names != null )
  39.                 names.Add( name );
  40.  
  41.             InputType inputType = (InputType)axis.FindPropertyRelative("type").intValue;
  42.  
  43.             if( types != null )
  44.                 types.Add( inputType );
  45.  
  46.         }
  47.     }
  48.  
  49.    
  50.  
  51.  
  52. }
  53.  
  54. #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement