using UnityEditor; using UnityEngine; namespace Ubisoft.Hotel.Localisation.Editor { [CustomPropertyDrawer(typeof(LocalisedString), true)] public class LocalisedStringPropertyDrawer : PropertyDrawer { public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { _ = DrawOrGetHeight(true, position, property); } public override float GetPropertyHeight(SerializedProperty property, GUIContent label) { return DrawOrGetHeight(false, new Rect(), property); } private float DrawOrGetHeight(bool draw, Rect position, SerializedProperty property) { SerializedProperty languageIdProperty = property.FindPropertyRelative(LocalisedString.ATTRIBUTE_LANGUAGE_ID); SerializedProperty valueProperty = property.FindPropertyRelative(LocalisedString.ATTRIBUTE_VALUE); float returnValue = Mathf.Max(EditorGUI.GetPropertyHeight(languageIdProperty), EditorGUI.GetPropertyHeight(valueProperty)); float separatorWidth = 10; float valueWidth = 2 * (position.width - separatorWidth) / 3; float languageIdWidth = position.width - separatorWidth - valueWidth; Rect innerPropertyRect = new Rect(position.x, position.y, languageIdWidth, returnValue); // Language id if (draw) { _ = EditorGUI.PropertyField(innerPropertyRect, languageIdProperty, GUIContent.none); } // Value innerPropertyRect.x = position.x + languageIdWidth + separatorWidth; innerPropertyRect.width = valueWidth; if (draw) { _ = EditorGUI.PropertyField(innerPropertyRect, valueProperty, GUIContent.none); } return returnValue; } } }