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