- Home /
Audio Importer: how do you override platform specific settings from code?
Hello everyone, I'm writing a script to set the import parameters for every imported asset in my project, right now changing the default settings is working, but I'm having issues overriding the platform specific settings for the audio assets. The code I wrote is the following:
#if UNITY_EDITOR
using UnityEditor;
using UnityEngine;
internal class AudioImporter : AssetPostprocessor
{
void OnPreprocessAudio()
{
AudioImporter audioImporter = assetImporter as AudioImporter;
audioImporter.preloadAudioData = false;
audioImporter.loadInBackground = false;
AudioImporterSampleSettings audioImporterSampleSettingsWebGL = new AudioImporterSampleSettings();
audioImporterSampleSettingsWebGL.compressionFormat = AudioCompressionFormat.AAC;
audioImporterSampleSettingsWebGL.loadType = AudioClipLoadType.Streaming;
audioImporterSampleSettingsWebGL.quality = 0.5f;
bool successfullOverride = audioImporter.SetOverrideSampleSettings("WebGL", audioImporterSampleSettingsWebGL);
}
}
#endif
The boolean successfullOverride
is always false.
I've also tried with audioImporter.SetOverrideSampleSettings(BuildTarget.WebGL.ToString(), audioImporterSampleSettingsWebGL);
.
Thank you in advance.
Answer by justDeek · Mar 18, 2017 at 08:13 AM
Try
audioImporter.SetOverrideSampleSettings ("WebGL", audioImporterSampleSettingsWebGL); //platform options: "Webplayer", "Standalone", "iOS", "Android", "WebGL", "PS4", "PSP2", "XBoxOne", "Samsung TV"
instead of
bool successfullOverride = audioImporter.SetOverrideSampleSettings("WebGL", audioImporterSampleSettingsWebGL);
This doesn't give you a bool value but at least it should override the platform-specific settings.
Your answer
Follow this Question
Related Questions
Adding m4a support to Windows Unity Pro 2.6.1? 1 Answer
Can I generate prefab instances based on locators inside a 3d model file? 2 Answers
How do I import audio and what type of audio do i need (mp3, etc.) 1 Answer
Complete Packages wont run correctly in Unity 1 Answer
How to adjust the compression of audio loaded through WWW? 1 Answer