Skip to content

Commit

Permalink
Fix building name for some generic types; fix drawing SerializedDicti…
Browse files Browse the repository at this point in the history
…onary for non-serializable value/key types
  • Loading branch information
arimger committed Nov 28, 2024
1 parent 67aa037 commit 99baede
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,19 @@ static SerializedDictionaryDrawer()
var content = list.GetElementContent(element, index);
using (new EditorGUILayout.HorizontalScope())
{
var kOption = GUILayout.Width(Style.kGroupWidth);
DrawDictionaryProperty(kProperty, Style.kLabel, Style.kLabelWidth, kOption);

var vLabel = vProperty.hasVisibleChildren
? Style.vLabel
: GUIContent.none;
DrawDictionaryProperty(vProperty, vLabel, Style.vLabelWidth);
if (kProperty != null)
{
var kOption = GUILayout.Width(Style.kGroupWidth);
DrawDictionaryProperty(kProperty, Style.kLabel, Style.kLabelWidth, kOption);
}

if (vProperty != null)
{
var vLabel = vProperty.hasVisibleChildren
? Style.vLabel
: GUIContent.none;
DrawDictionaryProperty(vProperty, vLabel, Style.vLabelWidth);
}
}
};
return list;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,19 +76,21 @@ private static string GetTypeName(Type type, bool createFull)
stringBuilder.Append(':');
}

if (type.IsGenericType)
var typeName = type.Name;
//NOTE: there are rare cases where "generic" types have no arguments, let's ignore them
if (type.IsGenericType && typeName.Contains("`"))
{
var name = type.Name;
name = name.Substring(0, name.IndexOf("`"));
var genericCharIndex = typeName.IndexOf("`");
typeName = typeName.Substring(0, genericCharIndex);

stringBuilder.Append(name);
stringBuilder.Append(typeName);
stringBuilder.Append('<');
var arguments = type.GetGenericArguments();
for (var i = 0; i < arguments.Length; i++)
{
var argumentType = arguments[i];
var argumentType = arguments[i];
var argumentName = string.IsNullOrEmpty(argumentType.FullName)
? argumentType.Name
? argumentType.Name
: GetTypeName(argumentType, false);

stringBuilder.Append(argumentName);
Expand All @@ -102,7 +104,7 @@ private static string GetTypeName(Type type, bool createFull)
}
else
{
stringBuilder.Append(type.Name);
stringBuilder.Append(typeName);
}

return stringBuilder.ToString();
Expand Down

0 comments on commit 99baede

Please sign in to comment.