11// SPDX-License-Identifier: Apache-2.0
2- // © 2023-2024 Nikolay Melnikov <n.melnikov@depra.org>
2+ // © 2023-2026 Depra <n.melnikov@depra.org>
33
44using System ;
55using System . Collections . Generic ;
@@ -14,16 +14,23 @@ public sealed class ComponentSerializeReference : SerializeReferenceAttribute
1414
1515 public ComponentSerializeReference ( string nameSubstring ) => _nameSubstring = nameSubstring ;
1616
17- public override IEnumerable < Type > GetTypes ( Type referenceType ) =>
18- from assembly in AppDomain . CurrentDomain . GetAssemblies ( )
19- from extractedType in assembly . GetTypes ( )
20- where extractedType . IsPublic &&
21- extractedType . IsValueType &&
22- ! extractedType . IsGenericType &&
23- extractedType . FullName ! . Contains ( _nameSubstring ) &&
24- ! IsDefined ( extractedType , HideSerializeReferenceAttribute . TYPE )
25- // TODO: Uncomment this line after obsolete serialization is removed.
26- // && extractedType.GetCustomAttribute<SerializableAttribute>() != null
27- select extractedType ;
17+ public override IEnumerable < Type > GetDerivedTypes ( Type referenceType )
18+ {
19+ #if UNITY_EDITOR
20+ return from extractedType in UnityEditor . TypeCache . GetTypesDerivedFrom ( referenceType )
21+ where extractedType . IsPublic &&
22+ extractedType . IsValueType &&
23+ ! extractedType . IsGenericType &&
24+ extractedType . FullName ! . Contains ( _nameSubstring ) &&
25+ ! IsDefined ( extractedType , HideSerializeReferenceAttribute . TYPE )
26+ // TODO: Uncomment this line after obsolete serialization is removed.
27+ // && extractedType.GetCustomAttribute<SerializableAttribute>() != null
28+ select extractedType ;
29+ #else
30+ return Array . Empty < Type > ( ) ;
31+ #endif
32+ }
33+
34+ public override IEnumerable < Type > GetGenericTypes ( Type referenceType ) => Array . Empty < Type > ( ) ;
2835 }
2936}
0 commit comments