From 1a5b5a746843bb563dd5b5702ab002d167b735ae Mon Sep 17 00:00:00 2001 From: VladV Date: Mon, 31 Jul 2023 19:36:38 +0400 Subject: [PATCH] Fix incorrect nested class names in reference dropdown --- Editor/Utilities/TriManagedReferenceGui.cs | 8 ++++-- Editor/Utilities/TriTypeUtilities.cs | 31 ++++++++++++++++++++++ Editor/Utilities/TriTypeUtilities.cs.meta | 3 +++ 3 files changed, 40 insertions(+), 2 deletions(-) create mode 100644 Editor/Utilities/TriTypeUtilities.cs create mode 100644 Editor/Utilities/TriTypeUtilities.cs.meta diff --git a/Editor/Utilities/TriManagedReferenceGui.cs b/Editor/Utilities/TriManagedReferenceGui.cs index b0ab4a6..f15f9bf 100644 --- a/Editor/Utilities/TriManagedReferenceGui.cs +++ b/Editor/Utilities/TriManagedReferenceGui.cs @@ -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; diff --git a/Editor/Utilities/TriTypeUtilities.cs b/Editor/Utilities/TriTypeUtilities.cs new file mode 100644 index 0000000..f0322c8 --- /dev/null +++ b/Editor/Utilities/TriTypeUtilities.cs @@ -0,0 +1,31 @@ +using System; +using System.Collections.Generic; + +namespace TriInspector.Utilities +{ + public static class TriTypeUtilities + { + private static readonly Dictionary TypeNiceNames = new Dictionary(); + + 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; + } + } +} \ No newline at end of file diff --git a/Editor/Utilities/TriTypeUtilities.cs.meta b/Editor/Utilities/TriTypeUtilities.cs.meta new file mode 100644 index 0000000..906daa7 --- /dev/null +++ b/Editor/Utilities/TriTypeUtilities.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: cd64ca1178f24265a0eea33c5dfbb3c9 +timeCreated: 1690816481 \ No newline at end of file