diff --git a/Packages/Core/Editor/Drawers/AtomBaseReferenceDrawer.cs b/Packages/Core/Editor/Drawers/AtomBaseReferenceDrawer.cs index 951e9eeb..85ec9e75 100644 --- a/Packages/Core/Editor/Drawers/AtomBaseReferenceDrawer.cs +++ b/Packages/Core/Editor/Drawers/AtomBaseReferenceDrawer.cs @@ -24,12 +24,7 @@ namespace UnityAtoms.Editor public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { - GuiData guiData = new GuiData() - { - Position = position, - Property = property, - Label = label - }; + Rect initialPosition = position; if (_popupStyle == null) { @@ -41,18 +36,17 @@ namespace UnityAtoms.Editor using (var scope = new EditorGUI.PropertyScope(position, label, property)) { - guiData.Label = scope.content; - guiData.Position = EditorGUI.PrefixLabel(position, label); + label = scope.content; + position = EditorGUI.PrefixLabel(position, label); // Store old indent level and set it to 0, the PrefixLabel takes care of it int indent = EditorGUI.indentLevel; EditorGUI.indentLevel = 0; { EditorGUI.BeginChangeCheck(); { - DetermineDragAndDropFieldReferenceType(guiData); - DrawConfigurationButton(ref guiData); - string currentUsageTypePropertyName = GetUsages(property)[GetUsageIndex(property)].PropertyName; - DrawField(currentUsageTypePropertyName, guiData, position); + DetermineDragAndDropFieldReferenceType(position, property); + DrawConfigurationButton(ref position, property); + DrawField(position, property, label, initialPosition); } if (EditorGUI.EndChangeCheck()) { @@ -78,8 +72,8 @@ namespace UnityAtoms.Editor } var innerProperty = property.FindPropertyRelative(usageData.PropertyName); - 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. @@ -91,26 +85,27 @@ namespace UnityAtoms.Editor EditorGUI.GetPropertyHeight(innerProperty, label); } - private void DrawConfigurationButton(ref GuiData guiData) + private void DrawConfigurationButton(ref Rect position, SerializedProperty property) { - Rect button = new Rect(guiData.Position); + Rect button = new Rect(position); button.yMin += _popupStyle.margin.top; button.yMax = button.yMin + EditorGUIUtility.singleLineHeight; button.width = _popupStyle.fixedWidth + _popupStyle.margin.right; - guiData.Position.xMin = button.xMax; + position.xMin = button.xMax; - var currentUsageIndex = GetUsageIndex(guiData.Property); - var newUsageValue = EditorGUI.Popup(button, currentUsageIndex, GetPopupOptions(guiData.Property), _popupStyle); - SetUsageIndex(guiData.Property, newUsageValue); + var currentUsageIndex = GetUsageIndex(property); + var newUsageValue = EditorGUI.Popup(button, currentUsageIndex, GetPopupOptions(property), _popupStyle); + SetUsageIndex(property, newUsageValue); } - private static void DrawField(string usageTypePropertyName, in GuiData guiData, in Rect originalPosition) + private void DrawField(in Rect position, SerializedProperty property, GUIContent label, in Rect originalPosition) { - var usageTypeProperty = guiData.Property.FindPropertyRelative(usageTypePropertyName); + string usageTypePropertyName = GetUsages(property)[GetUsageIndex(property)].PropertyName; + var usageTypeProperty = property.FindPropertyRelative(usageTypePropertyName); if (usageTypeProperty == null) { - EditorGUI.LabelField(guiData.Position, "[Non serialized value]"); + EditorGUI.LabelField(position, "[Non serialized value]"); } else { @@ -121,10 +116,10 @@ namespace UnityAtoms.Editor // 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); + EditorGUI.GetPropertyHeight(SerializedPropertyType.Vector3, label) : + EditorGUI.GetPropertyHeight(usageTypeProperty, label); #else - var valueFieldHeight = EditorGUI.GetPropertyHeight(usageTypeProperty, guiData.Label); + var valueFieldHeight = EditorGUI.GetPropertyHeight(usageTypeProperty, label); #endif usageTypeProperty.isExpanded = expanded; @@ -135,7 +130,7 @@ namespace UnityAtoms.Editor } else { - EditorGUI.PropertyField(guiData.Position, usageTypeProperty, GUIContent.none); + EditorGUI.PropertyField(position, usageTypeProperty, GUIContent.none); } } } @@ -152,7 +147,7 @@ namespace UnityAtoms.Editor #region Auto Drag And Drop Usage Type Detection - private void DetermineDragAndDropFieldReferenceType(in GuiData guiData) + private void DetermineDragAndDropFieldReferenceType(in Rect position, SerializedProperty property) { EventType mouseEventType = Event.current.type; @@ -161,7 +156,7 @@ namespace UnityAtoms.Editor return; } - if (!IsMouseHoveringOverProperty(guiData.Position)) + if (!IsMouseHoveringOverProperty(position)) { return; } @@ -177,11 +172,11 @@ namespace UnityAtoms.Editor if (draggedObject is GameObject gameObject) { object[] instancers = gameObject.GetComponents(); - UpdateUsageConfigurationOption(guiData.Property, instancers); + UpdateUsageConfigurationOption(property, instancers); } else { - UpdateUsageConfigurationOption(guiData.Property, draggedObject); + UpdateUsageConfigurationOption(property, draggedObject); } } @@ -207,13 +202,13 @@ namespace UnityAtoms.Editor if (isDraggedTypeSameAsUsageType) { bool isUsageSetByUser = currentUsageIndex == index; + bool isNewUsageIndexSet = newUsageIndex > -1; if (isUsageSetByUser) { return; } - bool isNewUsageIndexSet = newUsageIndex > -1; if (!isNewUsageIndexSet) { newUsageIndex = index; diff --git a/Packages/Core/Editor/Utils/GuiData.cs b/Packages/Core/Editor/Utils/GuiData.cs deleted file mode 100644 index 9f2a1ea5..00000000 --- a/Packages/Core/Editor/Utils/GuiData.cs +++ /dev/null @@ -1,12 +0,0 @@ -using UnityEditor; -using UnityEngine; - -namespace UnityAtoms.Editor -{ - public struct GuiData - { - public Rect Position; - public SerializedProperty Property; - public GUIContent Label; - } -} \ No newline at end of file diff --git a/Packages/Core/Editor/Utils/GuiData.cs.meta b/Packages/Core/Editor/Utils/GuiData.cs.meta deleted file mode 100644 index 5371731a..00000000 --- a/Packages/Core/Editor/Utils/GuiData.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: a1c20882cb5b7ab4e8c3e8fb77d1ebf8 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: