5 using System.Collections.Generic;
6 using System.Reflection;
8 using SiliconStudio.Core.Diagnostics;
9 using SiliconStudio.Core.Reflection;
11 namespace SiliconStudio.Assets.Compiler
20 private readonly
Logger log = GlobalLogger.GetLogger(
"AssetsCompiler.AttributeBasedRegistry");
22 private readonly HashSet<Assembly> registeredAssemblies =
new HashSet<Assembly>();
30 var assemblies = AssemblyRegistry.Find(AssemblyCommonCategories.Assets);
31 foreach (var assembly
in assemblies)
32 AnalyseAssembly(assembly);
34 AssemblyRegistry.AssemblyRegistered += AssemblyRegistered;
41 private void AnalyseAssembly(Assembly assembly)
43 if (assembly == null)
throw new ArgumentNullException(
"assembly");
45 if (registeredAssemblies.Contains(assembly))
49 foreach (var type
in assembly.GetTypes())
52 if (!typeof(
Asset).IsAssignableFrom(type) || !type.IsClass)
56 var compilerAttribute = type.GetCustomAttribute<T>();
58 if (compilerAttribute == null)
63 var compilerType = Type.GetType(compilerAttribute.CompilerTypeName);
64 if (compilerType == null)
66 log.Error(
"Unable to find compiler [{0}] for asset [{1}]", compilerAttribute.CompilerTypeName, type);
70 var compilerInstance = Activator.CreateInstance(compilerType) as I;
71 if (compilerInstance == null)
73 log.Error(
"Invalid compiler type [{0}], must inherit from IAssetCompiler", compilerAttribute.CompilerTypeName);
77 RegisterCompiler(type, compilerInstance);
81 log.Error(
"Unable to instantiate compiler [{0}]", ex, compilerAttribute.CompilerTypeName);
84 registeredAssemblies.Add(assembly);
Assembly Assembly
Gets the assembly that has been registered.
Base implementation for ILogger.
An event occuring when an assembly is registered with AssemblyRegistry.
Common categories that can be used with AssemblyRegistry
const string Assets
The assembly is containing assets data.
HashSet< string > Categories
Gets the new categories registered for the specified Assembly
Main interface for compiling an Asset.
AttributeBasedRegistry()
Create an instance of that registry
Attribute to define for a IAssetCompiler for a Asset.