StandaloneInputModuleEditor.cs 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. #if UNITY_EDITOR && UNITY_INPUT_SYSTEM_ENABLE_UI
  2. using UnityEditor;
  3. using UnityEngine.EventSystems;
  4. namespace UnityEngine.InputSystem.UI.Editor
  5. {
  6. // The only purpose of the Input System suppying a custom editor for the UI StandaloneInputModule is to guide users to using
  7. // the Input System's InputSystemUIInputModule instead.
  8. [CustomEditor(typeof(StandaloneInputModule))]
  9. internal class StandaloneInputModuleModuleEditor : UnityEditor.Editor
  10. {
  11. SerializedProperty enableNativePlatformBackendsForNewInputSystem;
  12. SerializedProperty disableOldInputManagerSupport;
  13. public void OnEnable()
  14. {
  15. var allPlayerSettings = Resources.FindObjectsOfTypeAll<PlayerSettings>();
  16. if (allPlayerSettings.Length > 0)
  17. {
  18. var playerSettings = Resources.FindObjectsOfTypeAll<PlayerSettings>()[0];
  19. var so = new SerializedObject(playerSettings);
  20. enableNativePlatformBackendsForNewInputSystem = so.FindProperty("enableNativePlatformBackendsForNewInputSystem");
  21. disableOldInputManagerSupport = so.FindProperty("disableOldInputManagerSupport");
  22. }
  23. }
  24. public override void OnInspectorGUI()
  25. {
  26. // We assume that if these properties don't exist (ie are null), then that's because the new Input System has become the default.
  27. if (enableNativePlatformBackendsForNewInputSystem == null || enableNativePlatformBackendsForNewInputSystem.boolValue)
  28. {
  29. if (disableOldInputManagerSupport == null || disableOldInputManagerSupport.boolValue)
  30. EditorGUILayout.HelpBox("You are using StandaloneInputModule, which uses the old InputManager. You are using the new InputSystem, and have the old InputManager disabled. StandaloneInputModule will not work. Click the button below to replace this component with a InputSystemUIInputModule, which uses the new InputSystem.", MessageType.Error);
  31. else
  32. EditorGUILayout.HelpBox("You are using StandaloneInputModule, which uses the old InputManager. You also have the new InputSystem enabled in your project. Click the button below to replace this component with a InputSystemUIInputModule, which uses the new InputSystem (recommended).", MessageType.Info);
  33. if (GUILayout.Button("Replace with InputSystemUIInputModule"))
  34. {
  35. var go = ((StandaloneInputModule)target).gameObject;
  36. Undo.DestroyObjectImmediate(target);
  37. Undo.AddComponent<InputSystemUIInputModule>(go);
  38. return;
  39. }
  40. GUILayout.Space(10);
  41. }
  42. base.OnInspectorGUI();
  43. }
  44. }
  45. }
  46. #endif