From cb7e6902a6bcc2f76d085a3be2cfa0e901f161b1 Mon Sep 17 00:00:00 2001 From: shalliwell Date: Sat, 9 May 2020 19:55:42 +1000 Subject: [PATCH] Fix VariableDataDrawer 2019.3 Previously had a single and multi line variant, with multiline never being actually used. Changes in 2019.3 mean that its trying to use multiline and we don't actually want to, it makes many properties that are presently single line comfortable draw incorrectly. --- .../Fungus/Scripts/Editor/VariableEditor.cs | 70 +------------------ 1 file changed, 3 insertions(+), 67 deletions(-) diff --git a/Assets/Fungus/Scripts/Editor/VariableEditor.cs b/Assets/Fungus/Scripts/Editor/VariableEditor.cs index 83c2a785..63504b3b 100644 --- a/Assets/Fungus/Scripts/Editor/VariableEditor.cs +++ b/Assets/Fungus/Scripts/Editor/VariableEditor.cs @@ -221,26 +221,11 @@ namespace Fungus.EditorUtils var origLabel = new GUIContent(label); - if (EditorGUI.GetPropertyHeight(valueProp, label) <= EditorGUIUtility.singleLineHeight) - { - DrawSingleLineProperty(position, origLabel, referenceProp, valueProp, flowchart, typeInfo); - } - else - { - DrawMultiLineProperty(position, origLabel, referenceProp, valueProp, flowchart, typeInfo); - } - - EditorGUI.EndProperty(); - } - - protected virtual void DrawSingleLineProperty(Rect rect, GUIContent label, SerializedProperty referenceProp, SerializedProperty valueProp, Flowchart flowchart, - VariableInfoAttribute typeInfo) - { int popupWidth = Mathf.RoundToInt(EditorGUIUtility.singleLineHeight); const int popupGap = 5; //get out starting rect with intent honoured - Rect controlRect = EditorGUI.PrefixLabel(rect, label); + Rect controlRect = EditorGUI.PrefixLabel(position, origLabel); Rect valueRect = controlRect; valueRect.width = controlRect.width - popupWidth - popupGap; Rect popupRect = controlRect; @@ -251,64 +236,15 @@ namespace Fungus.EditorUtils if (referenceProp.objectReferenceValue == null) { - DrawValueProperty(valueRect, valueProp, typeInfo); + CustomVariableDrawerLookup.DrawCustomOrPropertyField(typeof(T), valueRect, valueProp); popupRect.x += valueRect.width + popupGap; popupRect.width = popupWidth; } EditorGUI.PropertyField(popupRect, referenceProp, new GUIContent("")); EditorGUI.indentLevel = prevIndent; - } - - protected virtual void DrawMultiLineProperty(Rect rect, GUIContent label, SerializedProperty referenceProp, SerializedProperty valueProp, Flowchart flowchart, - VariableInfoAttribute typeInfo) - { - const int popupWidth = 100; - - Rect controlRect = rect; - Rect valueRect = controlRect; - valueRect.width = controlRect.width - 5; - Rect popupRect = controlRect; - - if (referenceProp.objectReferenceValue == null) - { - DrawValueProperty(valueRect, valueProp, typeInfo); - popupRect.x = rect.width - popupWidth + 5; - popupRect.width = popupWidth; - } - else - { - popupRect = EditorGUI.PrefixLabel(rect, label); - } - - EditorGUI.PropertyField(popupRect, referenceProp, new GUIContent("")); - } - - protected virtual void DrawValueProperty(Rect valueRect, SerializedProperty valueProp, VariableInfoAttribute typeInfo) - { - CustomVariableDrawerLookup.DrawCustomOrPropertyField(typeof(T), valueRect, valueProp); - } - public override float GetPropertyHeight(SerializedProperty property, GUIContent label) - { - VariableInfoAttribute typeInfo = VariableEditor.GetVariableInfo(typeof(T)); - if (typeInfo == null) - { - return EditorGUIUtility.singleLineHeight; - } - - string propNameBase = typeInfo.VariableType; - propNameBase = Char.ToLowerInvariant(propNameBase[0]) + propNameBase.Substring(1); - - SerializedProperty referenceProp = property.FindPropertyRelative(propNameBase + "Ref"); - - if (referenceProp.objectReferenceValue != null) - { - return EditorGUIUtility.singleLineHeight; - } - - SerializedProperty valueProp = property.FindPropertyRelative(propNameBase + "Val"); - return EditorGUI.GetPropertyHeight(valueProp, label); + EditorGUI.EndProperty(); } }