Esempio n. 1
0
 /// <summary>
 /// Register an AssetImporter object to be used when attempting to load an asset
 /// of the given type, or an asset file with one of the given extensions.
 /// </summary>
 /// <param name="assetImporter"></param>
 /// <param name="assetFileExtensions"></param>
 public static void RegisterAssetImporter<T>(
     AbstractAssetImporter assetImporter, params string[] assetFileExtensions)
 {
     var assetType = typeof(T);
     if (RegisteredAssetImportersByType.ContainsKey(assetType))
     {
         throw new AssetImporterRegistrationException(
             String.Format("An asset importer has already been " +
                           "associated with the type '{0}'.", assetType));
     }
     RegisteredAssetImportersByType.Add(assetType, assetImporter);
     RegisterAssetImporter(assetImporter, assetFileExtensions);
 }
Esempio n. 2
0
 /// <summary>
 /// Register an AssetImporter object to b used when attempting to load an asset
 /// file with one of the given extensions.
 /// 
 /// This is useful if you have multiple different asset importers for the same
 /// asset type but different asset file extensions. If two asset importers have
 /// the same associated asset type, but different asset file extensions, the
 /// AssetLoader will be able to determine the asset importer to use when given a
 /// file, but will not be able to distinguish the asset importer to use when
 /// given the asset type.
 /// 
 /// To further illustrate:
 /// <code>
 ///     AssetLoader.RegisterAssetImporter<Texture2D>(new AssetImporter1(), "doc", "xml");
 ///     AssetLoader.RegisterAssetImporter(new AssetImporter2(), "docx");
 /// </code>
 /// 
 /// In the above example, it is assumed that AssetImporter1 and AssetImporter2 both import
 /// Texture2D objects. Calling AssetLoader.Load<Texture2D>(fileName) would use AssetImporter1
 /// to import the asset, as well as AssetLoader.LoadUsingExtension("something.doc"), but
 /// AssetLoader.LoadUsingExtension("something.docx") would use AssetImporter2, and
 /// AssetLoader.Load<Texture2D>("something.docx") would *still* attempt to use AssetImporter1,
 /// since that's the only asset importer associated with Texture2D.
 /// </summary>
 /// <param name="assetImporter"></param>
 /// <param name="assetFileExtensions"></param>
 public static void RegisterAssetImporter(
     AbstractAssetImporter assetImporter, params string[] assetFileExtensions)
 {
     foreach (var ext in assetFileExtensions)
     {
         var truncated = ext[0] == '.' ? ext.Substring(1) : ext;
         if (RegisteredAssetImportersByExtension.ContainsKey(truncated))
         {
             throw new AssetImporterRegistrationException(
                 String.Format("An asset importer has already been " + 
                               "associated with the extension '.{0}'", truncated));
         }
         RegisteredAssetImportersByExtension.Add(truncated, assetImporter);
     }
 }