No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

EventSystemEditor.cs 2.0KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. using UnityEngine;
  2. using UnityEngine.EventSystems;
  3. namespace UnityEditor.EventSystems
  4. {
  5. [CustomEditor(typeof(EventSystem), true)]
  6. /// <summary>
  7. /// Custom Editor for the EventSystem Component.
  8. /// Extend this class to write a custom editor for a component derived from EventSystem.
  9. /// </summary>
  10. public class EventSystemEditor : Editor
  11. {
  12. public override void OnInspectorGUI()
  13. {
  14. DrawDefaultInspector();
  15. var eventSystem = target as EventSystem;
  16. if (eventSystem == null)
  17. return;
  18. if (eventSystem.GetComponent<BaseInputModule>() != null)
  19. return;
  20. // no input modules :(
  21. if (GUILayout.Button("Add Default Input Modules"))
  22. {
  23. InputModuleComponentFactory.AddInputModule(eventSystem.gameObject);
  24. Undo.RegisterCreatedObjectUndo(eventSystem.gameObject, "Add Default Input Modules");
  25. }
  26. }
  27. public override bool HasPreviewGUI()
  28. {
  29. return Application.isPlaying;
  30. }
  31. private GUIStyle m_PreviewLabelStyle;
  32. protected GUIStyle previewLabelStyle
  33. {
  34. get
  35. {
  36. if (m_PreviewLabelStyle == null)
  37. {
  38. m_PreviewLabelStyle = new GUIStyle("PreOverlayLabel")
  39. {
  40. richText = true,
  41. alignment = TextAnchor.UpperLeft,
  42. fontStyle = FontStyle.Normal
  43. };
  44. }
  45. return m_PreviewLabelStyle;
  46. }
  47. }
  48. public override bool RequiresConstantRepaint()
  49. {
  50. return Application.isPlaying;
  51. }
  52. public override void OnPreviewGUI(Rect rect, GUIStyle background)
  53. {
  54. var system = target as EventSystem;
  55. if (system == null)
  56. return;
  57. GUI.Label(rect, system.ToString(), previewLabelStyle);
  58. }
  59. }
  60. }