A game about forced loneliness, made by TACStudios
1#if UNITY_EDITOR 2using System; 3using UnityEditor; 4using UnityEngine.InputSystem.Layouts; 5 6namespace UnityEngine.InputSystem.Editor 7{ 8 /// <summary> 9 /// Custom property drawer for string type fields that represent input control paths. 10 /// </summary> 11 /// <remarks> 12 /// To use this drawer on a property, apply <see cref="InputControlAttribute"/> on it. To constrain 13 /// what type of control is picked, set the <see cref="InputControlAttribute.layout"/> field on the 14 /// attribute. 15 /// 16 /// <example> 17 /// <code> 18 /// // A string representing a control path. Constrain it to picking Button-type controls. 19 /// [InputControl(layout = "Button")] 20 /// [SerializeField] private string m_ControlPath; 21 /// </code> 22 /// </example> 23 /// </remarks> 24 [CustomPropertyDrawer(typeof(InputControlAttribute))] 25 internal sealed class InputControlPathDrawer : PropertyDrawer, IDisposable 26 { 27 private InputControlPickerState m_PickerState; 28 private InputControlPathEditor m_Editor; 29 30 public void Dispose() 31 { 32 m_Editor?.Dispose(); 33 } 34 35 public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) 36 { 37 if (m_PickerState == null) 38 m_PickerState = new InputControlPickerState(); 39 if (m_Editor == null) 40 { 41 m_Editor = new InputControlPathEditor(property, m_PickerState, 42 () => property.serializedObject.ApplyModifiedProperties(), 43 label: label); 44 } 45 46 EditorGUI.BeginProperty(position, label, property); 47 m_Editor.OnGUI(position, label, property, () => property.serializedObject.ApplyModifiedProperties()); 48 EditorGUI.EndProperty(); 49 } 50 } 51} 52#endif // UNITY_EDITOR