Browse Source

Fix Multiline Fungus Variable Datas

Restore single and multiline logic, needed for StringMultilineData
Pass GUIContent down through call back look for multiline draw to function as expected
Add Mat4x4 custom drawer callback to use draw Children
master
shalliwell 5 years ago
parent
commit
cde242fd25
  1. 25
      Assets/Fungus/Scripts/Editor/CustomVariableDrawerLookup.cs
  2. 71
      Assets/Fungus/Scripts/Editor/VariableEditor.cs
  3. 2
      Assets/Fungus/Scripts/Editor/VariableListAdaptor.cs

25
Assets/Fungus/Scripts/Editor/CustomVariableDrawerLookup.cs

@ -17,42 +17,41 @@ namespace Fungus.EditorUtils
public static class CustomVariableDrawerLookup
{
//If you create new types that require custom singleline drawers, add them here
public static Dictionary<System.Type, System.Action<UnityEngine.Rect, UnityEditor.SerializedProperty>> typeToDrawer =
new Dictionary<System.Type, System.Action<Rect, UnityEditor.SerializedProperty>>()
public static Dictionary<System.Type, System.Action<UnityEngine.Rect, UnityEditor.SerializedProperty, GUIContent>> typeToDrawer =
new Dictionary<System.Type, System.Action<Rect, UnityEditor.SerializedProperty, GUIContent>>()
{
{
typeof(QuaternionVariable),
(rect, valueProp) => {valueProp.quaternionValue = UnityEngine.Quaternion.Euler(UnityEditor.EditorGUI.Vector3Field(rect, new UnityEngine.GUIContent(""), valueProp.quaternionValue.eulerAngles)); }
(rect, valueProp, con) => {valueProp.quaternionValue = UnityEngine.Quaternion.Euler(UnityEditor.EditorGUI.Vector3Field(rect, con, valueProp.quaternionValue.eulerAngles)); }
},
{
typeof(Vector4Variable),
(rect, valueProp) => {valueProp.vector4Value = UnityEditor.EditorGUI.Vector4Field(rect, new UnityEngine.GUIContent(""), valueProp.vector4Value); }
(rect, valueProp, con) => {valueProp.vector4Value = UnityEditor.EditorGUI.Vector4Field(rect, con, valueProp.vector4Value); }
},
{
typeof(Matrix4x4Variable),
(rect, valueProp, con) => {UnityEditor.EditorGUI.PropertyField(rect, valueProp, con, true); }
},
};
public static bool GetDrawer(System.Type type, out System.Action<Rect, SerializedProperty> drawer)
{
return typeToDrawer.TryGetValue(type, out drawer);
}
/// <summary>
/// Called by editors that want a single line variable property drawn
/// </summary>
/// <param name="type"></param>
/// <param name="rect"></param>
/// <param name="prop"></param>
public static void DrawCustomOrPropertyField(System.Type type, Rect rect, SerializedProperty prop)
public static void DrawCustomOrPropertyField(System.Type type, Rect rect, SerializedProperty prop, GUIContent label)
{
System.Action<UnityEngine.Rect, UnityEditor.SerializedProperty> drawer = null;
System.Action<UnityEngine.Rect, UnityEditor.SerializedProperty, GUIContent> drawer = null;
//delegate actual drawing to the variableInfo
var foundDrawer = typeToDrawer.TryGetValue(type, out drawer);
if (foundDrawer)
{
drawer(rect, prop);
drawer(rect, prop, label);
}
else
{
EditorGUI.PropertyField(rect, prop, new GUIContent(""));
EditorGUI.PropertyField(rect, prop, label);
}
}
}

71
Assets/Fungus/Scripts/Editor/VariableEditor.cs

@ -221,11 +221,28 @@ namespace Fungus.EditorUtils
var origLabel = new GUIContent(label);
var itemH = EditorGUI.GetPropertyHeight(valueProp, label);
if (itemH <= EditorGUIUtility.singleLineHeight*2)
{
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(position, origLabel);
Rect controlRect = EditorGUI.PrefixLabel(rect, label);
Rect valueRect = controlRect;
valueRect.width = controlRect.width - popupWidth - popupGap;
Rect popupRect = controlRect;
@ -236,15 +253,61 @@ namespace Fungus.EditorUtils
if (referenceProp.objectReferenceValue == null)
{
CustomVariableDrawerLookup.DrawCustomOrPropertyField(typeof(T), valueRect, valueProp);
CustomVariableDrawerLookup.DrawCustomOrPropertyField(typeof(T), valueRect, valueProp, GUIContent.none);
popupRect.x += valueRect.width + popupGap;
popupRect.width = popupWidth;
}
EditorGUI.PropertyField(popupRect, referenceProp, new GUIContent(""));
EditorGUI.PropertyField(popupRect, referenceProp, GUIContent.none);
EditorGUI.indentLevel = prevIndent;
}
EditorGUI.EndProperty();
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;
popupRect.height = EditorGUIUtility.singleLineHeight;
if (referenceProp.objectReferenceValue == null)
{
//EditorGUI.PropertyField(valueRect, valueProp, label);
CustomVariableDrawerLookup.DrawCustomOrPropertyField(typeof(T), valueRect, valueProp, label);
popupRect.x = rect.width - popupWidth + 5;
popupRect.width = popupWidth;
}
else
{
popupRect = EditorGUI.PrefixLabel(rect, label);
}
EditorGUI.PropertyField(popupRect, referenceProp, GUIContent.none);
}
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);
}
}

2
Assets/Fungus/Scripts/Editor/VariableListAdaptor.cs

@ -290,7 +290,7 @@ namespace Fungus.EditorUtils
}
else
{
CustomVariableDrawerLookup.DrawCustomOrPropertyField(variable.GetType(), rect, valueProp);
CustomVariableDrawerLookup.DrawCustomOrPropertyField(variable.GetType(), rect, valueProp, GUIContent.none);
}
}

Loading…
Cancel
Save