|
|
|
|
|
|
using System; |
|
|
|
using System.Collections.Generic; |
|
|
|
using System.Reflection; |
|
|
|
using UnityEditor; |
|
|
|
using UnityEngine.Perception.Randomization.Parameters; |
|
|
|
using UnityEngine.Perception.Randomization.Samplers; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static StaticData() |
|
|
|
{ |
|
|
|
GatherParameterAndSamplerTypes(); |
|
|
|
parameterTypes = GetConstructableDerivedTypes<Parameter>(); |
|
|
|
samplerTypes = GetConstructableDerivedTypes<ISampler>(); |
|
|
|
static void GatherParameterAndSamplerTypes() |
|
|
|
static Type[] GetConstructableDerivedTypes<T>() |
|
|
|
var paramAssembly = typeof(Parameter).Assembly; |
|
|
|
var allAssemblies = AppDomain.CurrentDomain.GetAssemblies(); |
|
|
|
var assemblies = new List<Assembly> { paramAssembly }; |
|
|
|
foreach (var assembly in allAssemblies) |
|
|
|
{ |
|
|
|
foreach (var asm in assembly.GetReferencedAssemblies()) |
|
|
|
{ |
|
|
|
if (asm.FullName == paramAssembly.GetName().FullName) |
|
|
|
{ |
|
|
|
assemblies.Add(assembly); |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
var parameterTypesList = new List<Type>(); |
|
|
|
var samplerTypesList = new List<Type>(); |
|
|
|
foreach (var assembly in assemblies) |
|
|
|
var collection = TypeCache.GetTypesDerivedFrom<T>(); |
|
|
|
var types = new List<Type>(); |
|
|
|
foreach (var type in collection) |
|
|
|
foreach (var type in assembly.GetTypes()) |
|
|
|
{ |
|
|
|
var isNotAbstract = (type.Attributes & TypeAttributes.Abstract) == 0; |
|
|
|
if (typeof(Parameter).IsAssignableFrom(type) && isNotAbstract && |
|
|
|
ParameterDisplayName.GetDisplayName(type) != null) |
|
|
|
parameterTypesList.Add(type); |
|
|
|
else if (typeof(ISampler).IsAssignableFrom(type) && |
|
|
|
isNotAbstract && SamplerDisplayName.GetDisplayName(type) != null) |
|
|
|
{ |
|
|
|
samplerTypesList.Add(type); |
|
|
|
} |
|
|
|
} |
|
|
|
if (!type.IsAbstract && !type.IsInterface) |
|
|
|
types.Add(type); |
|
|
|
|
|
|
|
parameterTypes = parameterTypesList.ToArray(); |
|
|
|
samplerTypes = samplerTypesList.ToArray(); |
|
|
|
return types.ToArray(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |