Pegorari/tagarela

Update TagarelaAudioSpectrum.cs to Unity 5/Unity 2017 audio to fix `UnityEditor.AudioImporter' does not contain a definition for `loadType' and to display audio

kinoc opened this issue · 0 comments

kinoc commented

The following is need to fix UnityEditor.AudioImporter' does not contain a definition for loadType'

    //workaround to prevent the error in the function getData when Audio Importer loadType is "compressed in memory"
    string path = AssetDatabase.GetAssetPath(aud);
    AudioImporter audioImporter = AssetImporter.GetAtPath(path) as AudioImporter;
    AudioImporterSampleSettings audioImporterSampleSettings = audioImporter.defaultSampleSettings;

    //AudioClipLoadType audioLoadTypeBackup = audioImporter.loadType;
    AudioClipLoadType audioLoadTypeBackup = audioImporterSampleSettings.loadType;

    //audioImporter.loadType = AudioClipLoadType.Streaming;
    audioImporterSampleSettings.loadType = AudioClipLoadType.DecompressOnLoad;// AudioClipLoadType.CompressedInMemory;
    audioImporter.defaultSampleSettings = audioImporterSampleSettings;
    AssetDatabase.ImportAsset(path);

    //getData after the loadType changed
    aud.GetData(samples, 0);

    //restore the loadType
    //audioImporter.loadType = audioLoadTypeBackup;
    audioImporterSampleSettings.loadType = audioLoadTypeBackup;
    audioImporter.defaultSampleSettings = audioImporterSampleSettings;