Exemplo n.º 1
0
        /// <summary>
        /// This function is for post processing project imported audio assets.
        /// </summary>
        /// <param name="importConfiguration">Takes in the import configuration asset.</param>
        /// <param name="assetPostprocessor">Takes in the asset postprocessor class.</param>
        public static void ProcessAudioAsset(ConfigurationAsset importConfiguration, AssetPostprocessor assetPostprocessor)
        {
            // Trying to modify the audio importer settings.
            try
            {
                // Getting the audio asset impoprter settings
                var audioImporter = assetPostprocessor.assetImporter as AudioImporter;

                // Getting the  default audio importer sample settings from the new audio imported.
                AudioImporterSampleSettings audioConfiguration = audioImporter.defaultSampleSettings;

                // Applying the configured audio settings data to the imported audio asset.
                audioConfiguration.loadType          = importConfiguration.AudioImportConfiguration.LoadType;
                audioConfiguration.sampleRateSetting = importConfiguration.AudioImportConfiguration.SampleRate;
                audioConfiguration.compressionFormat = importConfiguration.AudioImportConfiguration.CompressionFormat;

                // Assigning configured audio importer configurations.
                audioImporter.defaultSampleSettings = audioConfiguration;

                // Checking for active audio overide platorm option.
                bool platformOverideEnabled = importConfiguration.AudioImportConfiguration.AudioOveridePlatormOption != PlatformOption.None;

                // Checking if platform settings overide is enabled.
                if (platformOverideEnabled)
                {
                    // Overiding platform settings for selected runtime platform.
                    audioImporter.SetOverrideSampleSettings(importConfiguration.AudioImportConfiguration.AudioOveridePlatormOption.ToString(), audioConfiguration);
                }
            }
            catch (Exception e)
            {
                // Throwing a new system exception.
                Debugger.ThrowException(e);
            }
        }
        /// <summary>
        /// Updates all assets from the configuration asset's included diretories.
        /// </summary>
        /// <param name="configurationAsset">This function takes in a configuration asset file and use the data to find and update project affected assets.</param>
        public static void OnUpdateIncludedAssetsUsingConfiguration(ConfigurationAsset configurationAsset)
        {
            // Checking if configuration file is valid
            bool isValidConfigurationAssetFile = AssetImportDirectory.IsValidConfigurationAsset(configurationAsset);

            // Checking if a configuration asset is not null.
            if (isValidConfigurationAssetFile)
            {
                // Checking if the configuration asset's importer assets library has included directories assigned.
                bool configurationIncludesDirectories = configurationAsset.GetIncludedAssetsDirectoryLibraryCount() > 0;

                // Checking if directories are included.
                if (configurationIncludesDirectories)
                {
                    // Getting a list of all included asset directories in the configuration asset file.
                    AssetsDirectoryLibrary includedAssetDirectoryLibrary = configurationAsset.GetIncludedAssetsDirectoryLibrary();

                    // Checking through all the found included directories assigned in the configuration asset file.
                    foreach (string directory in includedAssetDirectoryLibrary.Directories)
                    {
                        // Reimporting assets from the included directory.
                        AssetsReimporter.ReimportAssetsAtPath(directory, configurationAsset);
                    }
                }
                else
                {
                    // Checking if the configuration asset allow debug is enabled to log to messages to the console.
                    if (configurationAsset.AllowDebug)
                    {
                        // This message that will be logged to the unity's debug console.
                        string logMessage = "There are currently no included asset directories to update.";

                        // Logging a new warning message to the unity debug console.
                        Debugger.LogWarning(className: classLogName, message: logMessage);
                    }

                    return;
                }
            }
            else
            {
                // Checking if the configuration asset allow debug is enabled.
                if (configurationAsset.AllowDebug)
                {
                    // This message that will be logged to the unity's debug console.
                    string logMessage = "Configuration file missing.";

                    // Logging a new warning message to the unity debug console.
                    Debugger.LogWarning(className: classLogName, message: logMessage);
                }

                return;
            }
        }
        /// <summary>
        /// Re-imports assets from a given asset path.
        /// </summary>
        /// <param name="assetsPath">Takes in a string object called asset path as the assets to re-import from directory path.</param>
        /// <param name="configurationAsset">Takes in a configuration asset file used to configure re-imported assets.</param>
        public static void ReimportAssetsAtPath(string assetsPath, ConfigurationAsset configurationAsset)
        {
            // Searching the asset folders to find importable assts that can be retroactively updated.
            string[] importableAssetFilesEntries = Utilities.GetMultipleExtensionFileEntries(assetsPath);

            // Checking if there were file entries found in the directories.
            bool importableAssetsFound = importableAssetFilesEntries.Length > 0;

            // Checking if assets were found.
            if (importableAssetsFound)
            {
                // Going through found assets in the directory.
                foreach (string importableAsset in importableAssetFilesEntries)
                {
                    // Reimport an asset at the give directory.
                    AssetDatabase.ImportAsset(importableAsset);

                    // Checking if configuration aaset's debug is enabled.
                    if (configurationAsset.AllowDebug)
                    {
                        // Message to log in the unity debug console.
                        string logMessage = "Asset at path : " + importableAsset + " has been updated successfully.";

                        // Log a new message to the unity debug console.
                        Debugger.Log(className: classLogName, message: logMessage);
                    }
                }

                // Refreshing the asset data base.
                AssetDatabase.Refresh();
            }
            else
            {
                // Checking if configuration aaset's debug is enabled.
                if (configurationAsset.AllowDebug)
                {
                    // Message to log in the unity debug console.
                    string logMessage = "No assets to update at path : " + assetsPath;

                    // Logging a new message to the unity debug console.
                    Debugger.Log(className: classLogName, message: logMessage);
                }

                return;
            }
        }
        /// <summary>
        /// Assigns asset directories to newly created configuration asset files.
        /// This static function also adds the project affected or included asset directories to a newly created configuration asset file.
        /// </summary>
        /// <param name="configurationAsset">Takes in the newly created configuration asset.</param>
        /// <param name="assetDirectory">Takes in the asset directory path.</param>
        public static void AddConfigurationIncludedAssetDirectory(ConfigurationAsset configurationAsset, string assetDirectory)
        {
            // Checking if asset importer configuration doesn't include any directories.
            bool configurationHasNoIncludedAssetDirectories = configurationAsset.GetIncludedAssetsDirectoryLibraryCount() <= 0;

            // Checking if asset importer configuration loaded successfully and that it doesn't include directories.
            if (AssetImportDirectory.IsValidConfigurationAsset(configurationAsset) && configurationHasNoIncludedAssetDirectories)
            {
                // Getting the directory of the newly created configuration asset.
                string newConfigurationAssetDirectory = AssetImportDirectory.GetAssetDirectory(assetDirectory);

                // Assigning the directory reference to the asset importer.
                configurationAsset.AddConfigurationAssetIncludedDirectoryToLibrary(newConfigurationAssetDirectory);

                // Checking for sub directories to include in the asset importer configuration directory.
                string[] subDirectoriesToInclude = AssetDatabase.GetSubFolders(newConfigurationAssetDirectory);

                // Checking if sun directories are found/initialized.
                bool subDirectoriesFound = subDirectoriesToInclude.Length > 0;

                // --Checking if sub directories were found in the asset directory.
                if (subDirectoriesFound)
                {
                    // Looping through found included sub directories to add to the asset importer configuration asset file.
                    foreach (string directory in subDirectoriesToInclude)
                    {
                        // Adding the scriptable object import configuration asset path to the newely created configuration asset file.
                        configurationAsset.AddConfigurationAssetIncludedDirectoryToLibrary(directory);
                    }
                }

                // Save asset data base.
                AssetDatabase.SaveAssets();

                // Refreshing the assets data base.
                AssetDatabase.Refresh();

                // Message to log in the unity debug console window.
                string logMessage = "A new import configuration asset file was successfully created at path : " + newConfigurationAssetDirectory;

                // Logging configuration asset creation successs message to the unity debugger console.
                Debugger.Log(className: classLogName, message: logMessage);
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// This function is for post processing project imported texture assets.
        /// </summary>
        /// <param name="importConfiguration">Takes in the import configuration asset.</param>
        /// <param name="assetPostprocessor">Takes in the asset postprocessor class.</param>
        public static void ProcessTextureAsset(ConfigurationAsset importConfiguration, AssetPostprocessor assetPostprocessor)
        {
            // Trying to modify the texture importer with import configuration.
            try
            {
                // Converting texture overide platorm options to a string.
                string runtimePlatformName = importConfiguration.TextureImportConfiguration.m_TextureOveridePlatormOption.ToString();

                // Getting the texture impoprter settings from the imported asset.
                var textureImporter = assetPostprocessor.assetImporter as TextureImporter;

                // Getting the max size enum and converting it to a int value.
                int maximumTextureSize = (int)importConfiguration.TextureImportConfiguration.MaximumTextureSize;

                // Assigning texture importer platform settings maximum texture size.
                textureImporter.maxTextureSize = maximumTextureSize;

                // Assigning new settings.
                textureImporter.anisoLevel = importConfiguration.TextureImportConfiguration.AnisotropicFilteringLevel;

                // Getting current platform texture settings.
                var platformTextureSettings = textureImporter.GetPlatformTextureSettings(runtimePlatformName);

                // Checking if platform overide settings is enabled.
                platformTextureSettings.overridden = importConfiguration.TextureImportConfiguration.m_TextureOveridePlatormOption != PlatformOption.None;

                // Overiding setting for selected runtime platform.
                platformTextureSettings.maxTextureSize = maximumTextureSize;

                // Assigning final configured settings to the texture importer.
                textureImporter.SetPlatformTextureSettings(platformTextureSettings);
            }
            catch (Exception e)
            {
                // Throwing a new system exception.
                Debugger.ThrowException(e);
            }
        }
        private static void CreateImportConfiguration()
        {
            // Creating a new importer configuration asset file instance.
            ConfigurationAsset assetImportConfigurationAsset = CreateInstance <ConfigurationAsset>();

            // Getting the path to save newely created scriptable object import configuration asset.
            string importConfigurationAssetSavePath = EditorUtility.SaveFilePanelInProject("Asset Importer", "Asset Import Configuration", "asset", "");

            // Checking if the configuration asset save path exist.
            bool configurationAssetSavePathExist = !string.IsNullOrEmpty(importConfigurationAssetSavePath);

            // Checking if the importer configuration asset's instance was created.
            bool isConfigurationAssetCreated = assetImportConfigurationAsset != null;

            // Check if the importer configuration instance and the asset save path exist.
            if (isConfigurationAssetCreated && configurationAssetSavePathExist)
            {
                // Getting the selected import configuration asset directory where the configuration asset is created.
                string configurationAssetCreationDirectory = AssetImportDirectory.GetAssetDirectory(importConfigurationAssetSavePath);

                // Creating a new scriptable object import configuration asset to the import configuration path.
                AssetDatabase.CreateAsset(assetImportConfigurationAsset, importConfigurationAssetSavePath);

                // Save data base assets.
                AssetDatabase.SaveAssets();
            }
            else
            {
                // Warning message to log in the unity debug console window.
                string warningLogMessage = "Asset importer toolkit : Configuration file creation operation cancelled/failed: Import configuration asset file not created.";

                // Logging a new warning message to the console when the configuration asset file creation is cancelled by the user.
                Debugger.LogWarning(className: classLogName, message: warningLogMessage);

                return;
            }
        }
Exemplo n.º 7
0
 /// <summary>
 /// This function takes a configuration asset and checks if it's not null.
 /// </summary>
 /// <param name="configurationAsset">Takes in a configuration asset.</param>
 /// <returns>Return true if the configuration asset is not null or invalid.</returns>
 public static bool IsValidConfigurationAsset(ConfigurationAsset configurationAsset)
 {
     // Return true if configuration is not null.
     return(configurationAsset != null);
 }