fix: pasting FullQualifiedName in the generators text field, not picking up the actual type

This commit is contained in:
Soraphis 2023-07-12 19:52:20 +02:00 committed by GitHub
parent 994026fb7e
commit e88822e034
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 9 deletions

View File

@ -16,8 +16,6 @@ namespace UnityAtoms.Editor
private TypeSelectorDropdown typeSelectorDropdown;
private SerializedProperty fullQualifiedName;
private SerializedProperty typeNamespace;
private SerializedProperty baseType;
private SerializedProperty generatedOptions;
private static bool safeSearch = true;
@ -26,8 +24,6 @@ namespace UnityAtoms.Editor
{
// Find Properties.
fullQualifiedName = serializedObject.FindProperty(nameof(AtomGenerator.FullQualifiedName));
typeNamespace = serializedObject.FindProperty(nameof(AtomGenerator.Namespace));
baseType = serializedObject.FindProperty(nameof(AtomGenerator.BaseType));
generatedOptions = serializedObject.FindProperty(nameof(AtomGenerator.GenerationOptions));
// Check if the current type is unsafe.
@ -90,8 +86,6 @@ namespace UnityAtoms.Editor
serializedObject.Update();
fullQualifiedName.stringValue = selectedType.AssemblyQualifiedName;
typeNamespace.stringValue = selectedType.Namespace;
baseType.stringValue = selectedType.Name;
serializedObject.ApplyModifiedProperties();
});
@ -251,7 +245,10 @@ namespace UnityAtoms.Editor
parent.AddChild(dropdownItem);
// Use Hash instead of id! If 2 AdvancedDropdownItems have the same name, they will generate the same id (stupid, I know). To ensure searching for a unique identifier, we use the hash instead.
idTypePairs.Add(dropdownItem.GetHashCode(), type);
if (!idTypePairs.TryAdd(dropdownItem.GetHashCode(), type) && type.FullName != idTypePairs[dropdownItem.GetHashCode()].FullName)
{
Debug.LogError($"Could not add '{type.FullName}' to list, because it had a hash collision with: {idTypePairs[dropdownItem.GetHashCode()].FullName}");
}
}
}

View File

@ -11,8 +11,8 @@ namespace UnityAtoms.Editor
public class AtomGenerator : ScriptableObject
{
[TextArea] public string FullQualifiedName;
public string Namespace;
public string BaseType;
public string Namespace => string.IsNullOrWhiteSpace(FullQualifiedName) ? "" : Type.GetType(FullQualifiedName)?.Namespace;
public string BaseType => string.IsNullOrWhiteSpace(FullQualifiedName) ? "" : Type.GetType(FullQualifiedName)?.Name;
public int GenerationOptions;