From 4576277a192d9fdcd14f8deb60ce2ea2c61b3efe Mon Sep 17 00:00:00 2001 From: Adam Ramberg Date: Tue, 19 Dec 2023 00:38:03 +0100 Subject: [PATCH] Fix value field height in reference drawer for older Unity versions (#447) * Fix value field height in reference drawer for older unity versions * Fix property height for quaternions * Fix property field height for quaternions in variable editor as well * Fix comment --- .../Core/Editor/Drawers/AtomBaseReferenceDrawer.cs | 13 ++++++++++++- .../Editor/Editors/Variables/AtomVariableEditor.cs | 13 ++++++++++++- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/Packages/Core/Editor/Drawers/AtomBaseReferenceDrawer.cs b/Packages/Core/Editor/Drawers/AtomBaseReferenceDrawer.cs index 0db4bb1c..951e9eeb 100644 --- a/Packages/Core/Editor/Drawers/AtomBaseReferenceDrawer.cs +++ b/Packages/Core/Editor/Drawers/AtomBaseReferenceDrawer.cs @@ -79,7 +79,14 @@ namespace UnityAtoms.Editor var innerProperty = property.FindPropertyRelative(usageData.PropertyName); - return innerProperty == null ? + bool forceSingleLine = false; +#if UNITY_2021_2_OR_NEWER + // This is needed for similar reasons as described in the comment in the DrawField method below. + // This is basically a hack to fix a bug on Unity's side, which we need to revert when / if Unity fix it on their side. + forceSingleLine = innerProperty != null && innerProperty.propertyType == SerializedPropertyType.Quaternion; +#endif + + return innerProperty == null || forceSingleLine ? EditorGUIUtility.singleLineHeight : EditorGUI.GetPropertyHeight(innerProperty, label); } @@ -109,12 +116,16 @@ namespace UnityAtoms.Editor { var expanded = usageTypeProperty.isExpanded; usageTypeProperty.isExpanded = true; +#if UNITY_2021_2_OR_NEWER var valueFieldHeight = usageTypeProperty.propertyType == SerializedPropertyType.Quaternion ? // In versions prior to 2022.3 GetPropertyHeight returns the wrong value for "SerializedPropertyType.Quaternion" // In later versions, the fix is introduced _but only_ when using the SerializedPropertyType parameter, not when using the SerializedProperty parameter version. // ALSO the SerializedPropertyType parameter version does not work with the isExpanded flag which we set to true exactly for this reason a (few) lines above. EditorGUI.GetPropertyHeight(SerializedPropertyType.Vector3, guiData.Label) : EditorGUI.GetPropertyHeight(usageTypeProperty, guiData.Label); +#else + var valueFieldHeight = EditorGUI.GetPropertyHeight(usageTypeProperty, guiData.Label); +#endif usageTypeProperty.isExpanded = expanded; diff --git a/Packages/Core/Editor/Editors/Variables/AtomVariableEditor.cs b/Packages/Core/Editor/Editors/Variables/AtomVariableEditor.cs index ea03c53d..4faf33ca 100644 --- a/Packages/Core/Editor/Editors/Variables/AtomVariableEditor.cs +++ b/Packages/Core/Editor/Editors/Variables/AtomVariableEditor.cs @@ -25,7 +25,18 @@ namespace UnityAtoms.Editor } else { - EditorGUILayout.PropertyField(property, true); + // Quaternion property height is not handled correctly by Unity in version + // 2021.2 and above. Taking that into account here. +#if UNITY_2021_2_OR_NEWER + if (property.propertyType == SerializedPropertyType.Quaternion) + { + EditorGUILayout.PropertyField(property, false); + } + else +#endif + { + EditorGUILayout.PropertyField(property, true); + } } }