Browse Source

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.
master
shalliwell 5 years ago
parent
commit
cb7e6902a6
  1. 70
      Assets/Fungus/Scripts/Editor/VariableEditor.cs

70
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();
}
}

Loading…
Cancel
Save