using UnityEngine; using UnityEditor; namespace Ubisoft.Hotel.Package.Editor { [CustomPropertyDrawer(typeof(Version))] public class VersionPropertyDrawer : PropertyDrawer { public sealed override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { position = EditorGUI.PrefixLabel(position, label); _ = EditorGUI.BeginProperty(position, label, property); int indentLevelBackup = EditorGUI.indentLevel; // Draw all three version fields in an horizontal layout SerializedProperty p; float dotWidth = EditorStyles.label.CalcSize(new GUIContent(".")).x; float fieldWidth = (position.width - (2 * dotWidth)) / 3; // 3 columns (major/minor/patch), 2 dots in between position.height = EditorStyles.numberField.lineHeight + EditorStyles.numberField.margin.vertical; // Major position.width = fieldWidth; p = property.FindPropertyRelative("m_major"); p.intValue = EditorGUI.IntField(position, p.intValue); position.x += position.width; // Dot position.width = dotWidth; EditorGUI.LabelField(position, "."); position.x += position.width; // Minor position.width = fieldWidth; p = property.FindPropertyRelative("m_minor"); p.intValue = EditorGUI.IntField(position, p.intValue); position.x += position.width; // Dot position.width = dotWidth; EditorGUI.LabelField(position, "."); position.x += position.width; // Patch position.width = fieldWidth; p = property.FindPropertyRelative("m_patch"); p.intValue = EditorGUI.IntField(position, p.intValue); position.x += position.width; EditorGUI.EndProperty(); EditorGUI.indentLevel = indentLevelBackup; } } }