Exemplo n.º 1
0
        //=============================================================================
        // process
        //=============================================================================
        /// <summary>
        /// set importer
        /// </summary>
        private void ImportCustomAudio(CustomAudioImporter customImporter)
        {
            if (customImporter == null || !customImporter.IsEnable)
            {
                return;
            }

            AudioImporter audioImporter = assetImporter as AudioImporter;
            CustomAudioImporterSettingValue customSettings = customImporter.ImporterSetting;

            if (customSettings.ForceToMono.IsConfigurable)
            {
                audioImporter.forceToMono = customSettings.ForceToMono;
            }

            if (customSettings.LoadInBackGround.IsConfigurable)
            {
                audioImporter.loadInBackground = customSettings.LoadInBackGround;
            }

#if UNITY_2017_1_OR_NEWER
            if (customSettings.Ambisonic.IsConfigurable)
            {
                audioImporter.ambisonic = customSettings.Ambisonic;
            }
#endif

            if (customSettings.PreloadAudioData.IsConfigurable)
            {
                audioImporter.preloadAudioData = customSettings.PreloadAudioData;
            }

            audioImporter.defaultSampleSettings = SetCustomAudioSettings(customSettings);

            // override settings
            if (customImporter.OverrideForAndroidSetting.IsConfigurable)
            {
                audioImporter.SetOverrideSampleSettings("Android", SetCustomAudioSettings(customImporter.OverrideForAndroidSetting));
            }
            else
            {
                audioImporter.ClearSampleSettingOverride("Android");
            }

            if (customImporter.OverrideForiOSSetting.IsConfigurable)
            {
                audioImporter.SetOverrideSampleSettings("iOS", SetCustomAudioSettings(customImporter.OverrideForiOSSetting));
            }
            else
            {
                audioImporter.ClearSampleSettingOverride("iOS");
            }

            if (customImporter.IsLogger)
            {
                Debug.Log(string.Format("CustomAudioImporter : " + customImporter.Log + "\nProcessed : {0}", assetPath));
            }
        }
Exemplo n.º 2
0
        private void OverwriteImportSettings(AudioImporter target, AudioImporter reference)
        {
            target.defaultSampleSettings = reference.defaultSampleSettings;
            target.forceToMono           = reference.forceToMono;
            target.preloadAudioData      = reference.preloadAudioData;

            foreach (var g in NodeGUIUtility.SupportedBuildTargetGroups)
            {
                var platformName = BuildTargetUtility.TargetToAssetBundlePlatformName(g,
                                                                                      BuildTargetUtility.PlatformNameType.AudioImporter);

                if (reference.ContainsSampleSettingsOverride(platformName))
                {
                    var setting = reference.GetOverrideSampleSettings(platformName);
                    if (!target.SetOverrideSampleSettings(platformName, setting))
                    {
                        LogUtility.Logger.LogError("AudioImporter",
                                                   string.Format("Failed to set override setting for {0}: {1}", platformName, target.assetPath));
                    }
                }
                else
                {
                    target.ClearSampleSettingOverride(platformName);
                }
            }

            target.loadInBackground = reference.loadInBackground;
            target.ambisonic        = reference.ambisonic;
        }
Exemplo n.º 3
0
        private void OverwriteImportSettings(AudioImporter importer)
        {
            var reference = referenceImporter as AudioImporter;

            UnityEngine.Assertions.Assert.IsNotNull(reference);

            importer.defaultSampleSettings = reference.defaultSampleSettings;
            importer.forceToMono           = reference.forceToMono;
            importer.preloadAudioData      = reference.preloadAudioData;

            foreach (var g in NodeGUIUtility.SupportedBuildTargetGroups)
            {
                var platformName = BuildTargetUtility.TargetToAssetBundlePlatformName(g,
                                                                                      BuildTargetUtility.PlatformNameType.AudioImporter);

                if (reference.ContainsSampleSettingsOverride(platformName))
                {
                    var setting = reference.GetOverrideSampleSettings(platformName);
                    if (!importer.SetOverrideSampleSettings(platformName, setting))
                    {
                        LogUtility.Logger.LogError("AudioImporter",
                                                   string.Format("Failed to set override setting for {0}: {1}", platformName, importer.assetPath));
                    }
                }
                else
                {
                    importer.ClearSampleSettingOverride(platformName);
                }
            }

            // using "!UNITY_5_6_OR_NEWER" instead of "Unity_5_6" because loadInBackground became obsolete after Unity 5.6b3.
#if !UNITY_5_6_OR_NEWER
            importer.loadInBackground = reference.loadInBackground;
#endif

#if UNITY_2017_1_OR_NEWER
            importer.ambisonic = reference.ambisonic;
#endif
        }
Exemplo n.º 4
0
    /// <summary>
    /// Attempt to apply the given settings to the asset found at the path
    /// </summary>
    /// <param name="assetPath">Path to the asset</param>
    /// <param name="importSettings">Settings to apply</param>
    public static void ApplyImportSettingsToAsset(string assetPath, ImportSettings importSettings)
    {
        if (importSettings != null)
        {
            AssetImporter importer = AssetImporter.GetAtPath(assetPath);

            #region Apply Texture Import Settings
            if (importer.GetType() == typeof(TextureImporter) && importSettings.UseTextureSettings == true)
            {
                TextureImporter textureImporter = (TextureImporter)importer;

                //User wants to override the Android texture settings, create the appropriate settings and override them for Android
                if (importSettings.OverrideAndroidTextureSettings == true)
                {
                    TextureImporterPlatformSettings androidTextureSettings = new TextureImporterPlatformSettings()
                    {
                        name           = "Android",
                        maxTextureSize = (int)importSettings.AndroidMaxTextureSize,
                        overridden     = true
                    };

                    textureImporter.SetPlatformTextureSettings(androidTextureSettings);
                }
                else
                {
                    //Make sure to stop overriding the Android settings, if they're disabled
                    textureImporter.ClearPlatformTextureSettings("Android");
                }

                textureImporter.filterMode     = importSettings.TetxureFilterMode;
                textureImporter.maxTextureSize = (int)importSettings.MaxTextureSize;
                textureImporter.anisoLevel     = importSettings.FilterLevel;
                s_validAssetCount++;
            }
            #endregion

            #region Apply Audio Import Settings
            if (importer.GetType() == typeof(AudioImporter) && importSettings.UseAudioSettings == true)
            {
                AudioImporter audioImporter = (AudioImporter)importer;

                AudioImporterSampleSettings audioImportSettings = new AudioImporterSampleSettings()
                {
                    sampleRateSetting  = importSettings.AudioSampleRate,
                    sampleRateOverride = (uint)importSettings.SampleRateOverride,
                    compressionFormat  = importSettings.CompressionFormat,
                    loadType           = importSettings.AudioLoadType
                };

                //User wants to override the Android audio settings, create the appropriate settings and override them for Android
                if (importSettings.OverrideAndroidAudioSettings == true)
                {
                    AudioImporterSampleSettings androidAudioImportSettings = new AudioImporterSampleSettings()
                    {
                        sampleRateSetting  = importSettings.AndroidAudioSampleRate,
                        sampleRateOverride = (uint)importSettings.AndroidSampleRateOverride,
                        compressionFormat  = importSettings.AndroidCompressionFormat,
                        loadType           = importSettings.AndroidAudioClipLoadType
                    };

                    audioImporter.SetOverrideSampleSettings("Android", androidAudioImportSettings);
                }
                else
                {
                    //Make sure to stop overriding the Android settings, if they're disabled
                    audioImporter.ClearSampleSettingOverride("Android");
                }

                audioImporter.defaultSampleSettings = audioImportSettings;
                s_validAssetCount++;
            }
            #endregion

            AssetDatabase.ImportAsset(assetPath, ImportAssetOptions.ForceUpdate);
        }
        else
        {
            Debug.Log($"No import settings found for asset { assetPath } ");
        }
    }