Fix incorrect nested class names in reference dropdown

This commit is contained in:
VladV 2023-07-31 19:36:38 +04:00
parent a0c5ca5037
commit 1a5b5a7468
3 changed files with 40 additions and 2 deletions

View File

@ -13,7 +13,10 @@ namespace TriInspector.Utilities
{
public static void DrawTypeSelector(Rect rect, TriProperty property)
{
var typeNameContent = new GUIContent(property.ValueType?.Name ?? "[None]");
var typeName = property.ValueType != null
? TriTypeUtilities.GetTypeNiceName(property.ValueType)
: "[None]";
var typeNameContent = new GUIContent(typeName);
if (EditorGUI.DropdownButton(rect, typeNameContent, FocusType.Passive))
{
@ -141,7 +144,8 @@ namespace TriInspector.Utilities
private class ReferenceTypeItem : AdvancedDropdownItem
{
public ReferenceTypeItem(Type type, Texture2D preview = null) : base(type?.Name ?? "[None]")
public ReferenceTypeItem(Type type, Texture2D preview = null)
: base(type != null ? TriTypeUtilities.GetTypeNiceName(type) : "[None]")
{
Type = type;
icon = preview;

View File

@ -0,0 +1,31 @@
using System;
using System.Collections.Generic;
namespace TriInspector.Utilities
{
public static class TriTypeUtilities
{
private static readonly Dictionary<Type, string> TypeNiceNames = new Dictionary<Type, string>();
public static string GetTypeNiceName(Type type)
{
if (TypeNiceNames.TryGetValue(type, out var niceName))
{
return niceName;
}
niceName = type.Name;
while (type.DeclaringType != null)
{
niceName = type.DeclaringType.Name + "." + niceName;
type = type.DeclaringType;
}
TypeNiceNames[type] = niceName;
return niceName;
}
}
}

View File

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: cd64ca1178f24265a0eea33c5dfbb3c9
timeCreated: 1690816481