diff --git a/Assets/Textus/SerializeReferenceUI/Core/ManagedReferenceUtility.cs b/Assets/Textus/SerializeReferenceUI/Core/ManagedReferenceUtility.cs index 79746d4..0d67e39 100644 --- a/Assets/Textus/SerializeReferenceUI/Core/ManagedReferenceUtility.cs +++ b/Assets/Textus/SerializeReferenceUI/Core/ManagedReferenceUtility.cs @@ -51,6 +51,9 @@ public static class ManagedReferenceUtility // Skip abstract classes because they should not be instantiated if (type.IsAbstract) continue; + // Skip types that has no public empty constructors (activator can not create them) + if (type.IsClass && type.GetConstructor(Type.EmptyTypes) == null) // Structs still can be created (strangely) + continue; // Filter types by provided filters if there is ones if (filters != null && filters.All(f => f == null || f.Invoke(type)) == false) continue; diff --git a/Assets/Textus/SerializeReferenceUIExample/ExampleOfUsageFromDifferentAssembly/Animals/AnimalStruct.cs b/Assets/Textus/SerializeReferenceUIExample/ExampleOfUsageFromDifferentAssembly/Animals/AnimalStruct.cs new file mode 100644 index 0000000..453711e --- /dev/null +++ b/Assets/Textus/SerializeReferenceUIExample/ExampleOfUsageFromDifferentAssembly/Animals/AnimalStruct.cs @@ -0,0 +1,8 @@ +using System; + +[Serializable] +public struct AnimalStruct : IAnimal +{ + public string name; + public void Feed() => throw new NotImplementedException(); +} diff --git a/Assets/Textus/SerializeReferenceUIExample/ExampleOfUsageFromDifferentAssembly/Animals/AnimalStruct.cs.meta b/Assets/Textus/SerializeReferenceUIExample/ExampleOfUsageFromDifferentAssembly/Animals/AnimalStruct.cs.meta new file mode 100644 index 0000000..8815965 --- /dev/null +++ b/Assets/Textus/SerializeReferenceUIExample/ExampleOfUsageFromDifferentAssembly/Animals/AnimalStruct.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: c25ac56f032882a4b972b608e69230cc +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Textus/SerializeReferenceUIExample/ExampleOfUsageFromDifferentAssembly/NotSupportedTypes.meta b/Assets/Textus/SerializeReferenceUIExample/ExampleOfUsageFromDifferentAssembly/NotSupportedTypes.meta new file mode 100644 index 0000000..0c74f77 --- /dev/null +++ b/Assets/Textus/SerializeReferenceUIExample/ExampleOfUsageFromDifferentAssembly/NotSupportedTypes.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 5be67cbd02bf42146a3ebb2790befebf +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Textus/SerializeReferenceUIExample/ExampleOfUsageFromDifferentAssembly/NotSupportedTypes/ExampleOfNotSupportedTypes.cs b/Assets/Textus/SerializeReferenceUIExample/ExampleOfUsageFromDifferentAssembly/NotSupportedTypes/ExampleOfNotSupportedTypes.cs new file mode 100644 index 0000000..80eb1f5 --- /dev/null +++ b/Assets/Textus/SerializeReferenceUIExample/ExampleOfUsageFromDifferentAssembly/NotSupportedTypes/ExampleOfNotSupportedTypes.cs @@ -0,0 +1,27 @@ +using System; +using UnityEngine; + +public class ExampleOfNotSupportedTypes +{ + +} + +[Serializable] +public class AnimalMonoBehaviour : MonoBehaviour, IAnimal +{ + public void Feed() => throw new NotImplementedException(); +} + +[Serializable] +public class AnimalScriptableObject : ScriptableObject, IAnimal +{ + public void Feed() => throw new NotImplementedException(); +} + +[Serializable] +public class AnimalPrivateConstructor : IAnimal +{ + private AnimalPrivateConstructor(){} + public void Feed() => throw new NotImplementedException(); +} + diff --git a/Assets/Textus/SerializeReferenceUIExample/ExampleOfUsageFromDifferentAssembly/NotSupportedTypes/ExampleOfNotSupportedTypes.cs.meta b/Assets/Textus/SerializeReferenceUIExample/ExampleOfUsageFromDifferentAssembly/NotSupportedTypes/ExampleOfNotSupportedTypes.cs.meta new file mode 100644 index 0000000..4fd0064 --- /dev/null +++ b/Assets/Textus/SerializeReferenceUIExample/ExampleOfUsageFromDifferentAssembly/NotSupportedTypes/ExampleOfNotSupportedTypes.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 1060d26326c424a468bfd669381a0745 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Textus/SerializeReferenceUIExample/ExampleOfUsageFromDifferentAssembly/TestingAnimalWorldExample/Scenes/SerializeRefereneceUIExampleScene.unity b/Assets/Textus/SerializeReferenceUIExample/ExampleOfUsageFromDifferentAssembly/TestingAnimalWorldExample/Scenes/SerializeRefereneceUIExampleScene.unity index 87a658f..b3be355 100644 --- a/Assets/Textus/SerializeReferenceUIExample/ExampleOfUsageFromDifferentAssembly/TestingAnimalWorldExample/Scenes/SerializeRefereneceUIExampleScene.unity +++ b/Assets/Textus/SerializeReferenceUIExample/ExampleOfUsageFromDifferentAssembly/TestingAnimalWorldExample/Scenes/SerializeRefereneceUIExampleScene.unity @@ -199,12 +199,9 @@ MonoBehaviour: numberOfBones: 0 Tag: 00000005: - type: {class: RedApe, ns: , asm: SerializedReferenceExample} + type: {class: AnimalStruct, ns: , asm: SerializedReferenceExample} data: - age: 0 - food: {fileID: 0} - numberOfBones: 0 - Tag: + name: 00000006: type: {class: BlackApe, ns: , asm: SerializedReferenceExample} data: