From ec2afb78db24da3ec8fa8a04cdf14f826a3cd69c Mon Sep 17 00:00:00 2001 From: Anders Ejlersen Date: Sun, 5 Dec 2021 14:06:19 +0100 Subject: [PATCH] 1.3.1: Fixed type name issue in SerializeReferenceTo, due to Unity using their own type naming scheme --- .../SerializableReferenceToAttributeDrawer.cs | 34 +++++++++++++++---- package.json | 2 +- 2 files changed, 29 insertions(+), 7 deletions(-) diff --git a/Editor/Drawers/SerializableReferenceToAttributeDrawer.cs b/Editor/Drawers/SerializableReferenceToAttributeDrawer.cs index a0d239f..50fb71c 100644 --- a/Editor/Drawers/SerializableReferenceToAttributeDrawer.cs +++ b/Editor/Drawers/SerializableReferenceToAttributeDrawer.cs @@ -39,12 +39,13 @@ namespace Module.Inspector.Editor height = EditorGUIUtility.singleLineHeight }; - int index = Array.IndexOf(arrStrings, ConvertUnityToCSharp(property.managedReferenceFullTypename)); + int index = Array.IndexOf(arrStrings, ConvertUnityTypeFullnameToCSharpName(property.managedReferenceFullTypename)); int newIndex = EditorGUI.Popup(rect, label, index, arrGui); if (newIndex != -1 && index != newIndex) { Type newType = EditorTypeUtility.GetType(arrStrings[newIndex]); + if (newType != null && IsSupported(newType)) property.managedReferenceValue = FormatterServices.GetUninitializedObject(newType); @@ -117,16 +118,37 @@ namespace Module.Inspector.Editor return true; } - - private static string ConvertUnityToCSharp(string unityNaming) + + private static string ConvertUnityTypeFullnameToCSharpFullname(string unityNaming) { + if (string.IsNullOrEmpty(unityNaming)) + return string.Empty; + int index = unityNaming.LastIndexOf(' '); + string str; if (index != -1) - unityNaming = unityNaming.Substring(index); + { + str = unityNaming.Substring(0, index).Trim(); + str += ", "; + str += unityNaming.Substring(index).Trim(); + } + else + { + str = unityNaming; + } - unityNaming = unityNaming.Replace('/', '+'); - return unityNaming.Trim(); + return str.Replace('/', '+'); + } + + private static string ConvertUnityTypeFullnameToCSharpName(string unityNaming) + { + if (string.IsNullOrEmpty(unityNaming)) + return string.Empty; + + int index = unityNaming.LastIndexOf(' '); + string str = index != -1 ? unityNaming.Substring(index).Trim() : unityNaming; + return str.Replace('/', '+'); } } } \ No newline at end of file diff --git a/package.json b/package.json index aced385..5b030d4 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "com.module.inspector", - "version": "1.3.0", + "version": "1.3.1", "displayName": "Module.Inspector", "description": "Custom inspector with various useful property drawers", "unity": "2019.2",