1.3.1: Fixed type name issue in SerializeReferenceTo, due to Unity using their own type naming scheme

This commit is contained in:
Anders Ejlersen 2021-12-05 14:06:19 +01:00
parent e1d0e0e90b
commit ec2afb78db
2 changed files with 29 additions and 7 deletions

View file

@ -39,12 +39,13 @@ namespace Module.Inspector.Editor
height = EditorGUIUtility.singleLineHeight 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); int newIndex = EditorGUI.Popup(rect, label, index, arrGui);
if (newIndex != -1 && index != newIndex) if (newIndex != -1 && index != newIndex)
{ {
Type newType = EditorTypeUtility.GetType(arrStrings[newIndex]); Type newType = EditorTypeUtility.GetType(arrStrings[newIndex]);
if (newType != null && IsSupported(newType)) if (newType != null && IsSupported(newType))
property.managedReferenceValue = FormatterServices.GetUninitializedObject(newType); property.managedReferenceValue = FormatterServices.GetUninitializedObject(newType);
@ -117,16 +118,37 @@ namespace Module.Inspector.Editor
return true; 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(' '); int index = unityNaming.LastIndexOf(' ');
string str;
if (index != -1) 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 str.Replace('/', '+');
return unityNaming.Trim(); }
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('/', '+');
} }
} }
} }

View file

@ -1,6 +1,6 @@
{ {
"name": "com.module.inspector", "name": "com.module.inspector",
"version": "1.3.0", "version": "1.3.1",
"displayName": "Module.Inspector", "displayName": "Module.Inspector",
"description": "Custom inspector with various useful property drawers", "description": "Custom inspector with various useful property drawers",
"unity": "2019.2", "unity": "2019.2",