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,13 +39,14 @@ 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);
else
@ -118,15 +119,36 @@ 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('/', '+');
}
}
}

View file

@ -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",