コード例 #1
0
        // This function is used to add configuration settings to imported audio assets.
        private void OnPreprocessAudio()
        {
            // Defining a new import configuration asset.
            ConfigurationAsset audioImportConfiguration;

            // Getting asset path directry in lower case type.
            string assetDirectory = AssetImportDirectory.GetAssetDirectory(assetImporter.assetPath.ToLower());

            // Getting import configuration asset file for the imported texture asset.
            audioImportConfiguration = Configurations.GetAssetImportConfiguration(assetDirectory);

            // Validating the import configuration asset.
            bool configurationAssetIsValid = AssetImportDirectory.IsValidConfigurationAsset(audioImportConfiguration);

            // Checking if import configurations asset file is valid.
            if (configurationAssetIsValid)
            {
                // Checking if the imported asset directories is included or affected by the configuration asset.
                if (audioImportConfiguration.IncludedAssetDirectoryLibrary.Directories.Contains(assetDirectory))
                {
                    // Post processing asset file using import settings.
                    AssetImporterPostProcessor.ProcessAudioAsset(audioImportConfiguration, this);

                    // Checking if the configuration asset allow debug is enabled.
                    if (audioImportConfiguration.AllowDebug)
                    {
                        // This message that will be logged to the unity's debug console.
                        string logMessage = "The imported audio asset(s) has been configured successfully.";

                        // Logging a new message to the unity debug console.
                        Debugger.Log(className: classLogName, message: logMessage);
                    }
                }
            }
        }
コード例 #2
0
        /// <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;
            }
        }
コード例 #3
0
        /// <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);
            }
        }
        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;
            }
        }