public ImportedAnimationSheet ImportSpritesAndAnimationSheet(string assetPath, string additionalCommandLineArguments = null) { if (!IsValidAsset(assetPath)) { return(null); } // making sure config is valid if (sharedData == null) { LoadOrCreateUserConfig(); } // create a job AnimationImportJob job = CreateAnimationImportJob(assetPath, additionalCommandLineArguments); IAnimationImporterPlugin importer = _importerPlugins[GetExtension(assetPath)]; ImportedAnimationSheet animationSheet = importer.Import(job, sharedData); animationSheet.assetDirectory = job.assetDirectory; animationSheet.name = job.name; CreateSprites(animationSheet); return(animationSheet); }
public static void RegisterImporter(IAnimationImporterPlugin importer, params string[] extensions) { foreach (var extension in extensions) { _importerPlugins[extension] = importer; } }
// check if there is a configured importer for the specified extension public static bool IsConfiguredForAssets(DefaultAsset[] assets) { foreach (var asset in assets) { string assetPath = AssetDatabase.GetAssetPath(asset); string extension = GetExtension(assetPath); if (!string.IsNullOrEmpty(assetPath)) { if (_importerPlugins.ContainsKey(extension)) { IAnimationImporterPlugin importer = _importerPlugins[extension]; if (importer != null) { if (!importer.IsConfigured()) { return(false); } } } } } return(true); }
private ImportedAnimationSheet ImportJob(AnimationImportJob job) { job.SetProgress(0); IAnimationImporterPlugin importer = _importerPlugins[GetExtension(job.fileName)]; ImportedAnimationSheet animationSheet = importer.Import(job, sharedData); animationSheet.assetDirectory = job.assetDirectory; animationSheet.name = job.name; animationSheet.ApplySpriteNamingScheme(sharedData.spriteNamingScheme); job.SetProgress(0.3f, "creating sprites"); CreateSprites(animationSheet, job); job.SetProgress(0.7f, "creating animations"); if (job.createUnityAnimations) { CreateAnimations(animationSheet, job); job.SetProgress(0.9f); if (job.importAnimatorController == ImportAnimatorController.AnimatorController) { CreateAnimatorController(animationSheet); } else if (job.importAnimatorController == ImportAnimatorController.AnimatorOverrideController) { CreateAnimatorOverrideController(animationSheet, job.useExistingAnimatorController); } } return(animationSheet); }
private ImportedAnimationSheet ImportJob(AnimationImportJob job) { job.SetProgress(0); IAnimationImporterPlugin importer = _importerPlugins[GetExtension(job.fileName)]; if (sharedData.namingScheme == NamingScheme.ItsName) { AssetDatabase.RenameAsset(job.directoryPathForSprites + "\\Sprites.png", job.name); } ImportedAnimationSheet animationSheet = importer.Import(job, sharedData); job.SetProgress(0.3f); if (animationSheet != null) { animationSheet.assetDirectory = job.assetDirectory; animationSheet.name = job.name; animationSheet.ApplySpriteNamingScheme(sharedData.spriteNamingScheme); CreateSprites(animationSheet, job); job.SetProgress(0.6f); if (job.createUnityAnimations) { CreateAnimations(animationSheet, job); job.SetProgress(0.8f); if (job.importAnimatorController == ImportAnimatorController.AnimatorController) { CreateAnimatorController(animationSheet, job); } else if (job.importAnimatorController == ImportAnimatorController.AnimatorOverrideController) { CreateAnimatorOverrideController(animationSheet, job); } } if (sharedData.namingScheme == NamingScheme.ItsName) { AssetDatabase.RenameAsset(job.imageAssetFilename, "Sprites"); } } return(animationSheet); }
// ================================================================================ // querying existing assets // -------------------------------------------------------------------------------- // check if this is a valid file; we are only looking at the file extension here public static bool IsValidAsset(string path) { string extension = GetExtension(path); if (!string.IsNullOrEmpty(path)) { if (_importerPlugins.ContainsKey(extension)) { IAnimationImporterPlugin importer = _importerPlugins[extension]; if (importer != null) { return(importer.IsValid()); } } } return(false); }
private ImportedAnimationSheet ImportJob(AnimationImportJob job) { job.SetProgress(0); IAnimationImporterPlugin importer = importerPlugins[GetExtension(job.FileName)]; ImportedAnimationSheet animationSheet = importer.Import(job, SharedData); job.SetProgress(0.3f); if (animationSheet != null) { animationSheet.AssetDirectory = job.AssetDirectory; animationSheet.Name = job.Name; animationSheet.ApplySpriteNamingScheme(SharedData.SpriteNamingScheme); CreateSprites(animationSheet, job); job.SetProgress(0.6f); if (job.CreateUnityAnimations) { CreateAnimations(animationSheet, job); job.SetProgress(0.8f); if (job.ImportAnimatorController == ImportAnimatorController.AnimatorController) { CreateAnimatorController(animationSheet); } else if (job.ImportAnimatorController == ImportAnimatorController.AnimatorOverrideController) { CreateAnimatorOverrideController(animationSheet, job.UseExistingAnimatorController); } } } return(animationSheet); }