/* Yarn Spinner is licensed to you under the terms found in the file LICENSE.md. */ using UnityEditor; using UnityEngine; namespace Yarn.Unity { [CustomPropertyDrawer(typeof(DialogueReference))] public class DialogueReferenceDrawer : PropertyDrawer { public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { position = EditorGUI.PrefixLabel(position, label); var projectProperty = property.FindPropertyRelative(nameof(DialogueReference.project)); var nodeNameProperty = property.FindPropertyRelative(nameof(DialogueReference.nodeName)); position = GetLineRect(position, out var projectRect); position = GetLineRect(position, out var nodeNameRect); EditorGUI.PropertyField(projectRect, projectProperty, GUIContent.none); EditorGUI.PropertyField(nodeNameRect, nodeNameProperty, GUIContent.none); } /// /// Given a rectangle, computes a rectangle of the same width as the /// input with the height of a single line, taking into account vertical /// spacing. /// /// A rectangle representing the total area /// availalbe. /// On return, a rectangle with the same width as /// and with a single line's worth of /// height. /// The remaining available space. private Rect GetLineRect(Rect input, out Rect lineRect) { lineRect = input; lineRect.height = EditorGUIUtility.singleLineHeight; var remainder = input; var offset = EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; remainder.y += offset; remainder.height -= offset; return remainder; } /// /// Returns the height, in pixels, needed for drawing the inspector for /// a . /// /// A serialized property representing a object. /// The label to display for . /// The displayed height for the property. public override float GetPropertyHeight(SerializedProperty property, GUIContent label) { const int lineCount = 2; return lineCount * EditorGUIUtility.singleLineHeight + (lineCount - 1) * EditorGUIUtility.standardVerticalSpacing; } } }