1. Help us improve the editor usability and artist workflows. Join our discussion to provide your feedback.
    Dismiss Notice
  2. We're looking for feedback on Unity Starter Kits! Let us know what you’d like.
    Dismiss Notice
  3. We’re giving 2017.1 beta testers a chance to win t-shirts and a Nintendo Switch. Read more on the blog.
    Dismiss Notice
  4. We want to know how you learned Unity! Help us by taking this quick survey and have a chance at a $25 gift card
    Dismiss Notice
  5. Are you an artist or level designer going to Unite Europe? Join our roundtables there to discuss artist features.
    Dismiss Notice
  6. Unity 5.6 is now released.
    Dismiss Notice
  7. Check out all the fixes for 5.6 on the patch releases page.
    Dismiss Notice

Changing import settings for multiple audio files

Discussion in 'Scripting' started by jingato, Feb 13, 2011.

  1. jingato

    jingato

    Joined:
    Jun 23, 2010
    Posts:
    274
    Hi. I have a large number of audio files and I want to change the import settings for all of them.I did some searches on how to do this but I had no luck I found this one post

    http://forum.unity3d.com/threads/46398-Batch-audio-clip-import-settings-modifier?highlight=AudioImporter

    but it doesn't seem to work with 3.2. They must have changed something

    this line shows an an error in 3.2

    Code (csharp):
    Any ideas on how to get this to work?

    Thanks
     
  2. kiles

    kiles

    Joined:
    Apr 2, 2011
    Posts:
    6
    Hi, they have changed some things. Try this fast-modified version:

    Code (csharp):
    1.  
    2.  
    3. using UnityEngine;
    4. using UnityEditor;
    5.  
    6. // /////////////////////////////////////////////////////////////////////////////////////////////////////////
    7. //
    8. // Batch audio import settings modifier.
    9. //
    10. // Modifies all selected audio clips in the project window and applies the requested modification on the
    11. // audio clips. Idea was to have the same choices for multiple files as you would have if you open the
    12. // import settings of a single audio clip. Put this into Assets/Editor and once compiled by Unity you find
    13. // the new functionality in Custom -> Sound. Enjoy! :-)
    14. //
    15. // April 2010. Based on Martin Schultz's texture import settings batch modifier.
    16. //
    17. // /////////////////////////////////////////////////////////////////////////////////////////////////////////
    18. public class ChangeAudioImportSettings : ScriptableObject {
    19.  
    20.     [MenuItem ("Custom/Sound/Toggle audio compression/Disable")]
    21.     static void ToggleCompression_Disable() {
    22.         SelectedToggleCompressionSettings(AudioImporterFormat.Native);
    23.     }
    24.  
    25.     [MenuItem ("Custom/Sound/Toggle audio compression/Enable")]
    26.     static void ToggleCompression_Enable() {
    27.         SelectedToggleCompressionSettings(AudioImporterFormat.Compressed);
    28.     }
    29.  
    30.     // ----------------------------------------------------------------------------
    31.  
    32.     [MenuItem ("Custom/Sound/Set audio compression bitrate (kbps)/32")]
    33.     static void SetCompressionBitrate_32kbps() {
    34.         SelectedSetCompressionBitrate(32000);
    35.     }
    36.  
    37.     [MenuItem ("Custom/Sound/Set audio compression bitrate (kbps)/64")]
    38.     static void SetCompressionBitrate_64kbps() {
    39.         SelectedSetCompressionBitrate(64000);
    40.     }
    41.  
    42.     [MenuItem ("Custom/Sound/Set audio compression bitrate (kbps)/96")]
    43.     static void SetCompressionBitrate_96kbps() {
    44.         SelectedSetCompressionBitrate(96000);
    45.     }
    46.  
    47.     [MenuItem ("Custom/Sound/Set audio compression bitrate (kbps)/128")]
    48.     static void SetCompressionBitrate_128kbps() {
    49.         SelectedSetCompressionBitrate(128000);
    50.     }
    51.  
    52.     [MenuItem ("Custom/Sound/Set audio compression bitrate (kbps)/144")]
    53.     static void SetCompressionBitrate_144kbps() {
    54.         SelectedSetCompressionBitrate(144000);
    55.     }
    56.  
    57.     [MenuItem ("Custom/Sound/Set audio compression bitrate (kbps)/156 (default)")]
    58.     static void SetCompressionBitrate_156kbps() {
    59.         SelectedSetCompressionBitrate(156000);
    60.     }
    61.  
    62.     [MenuItem ("Custom/Sound/Set audio compression bitrate (kbps)/160")]
    63.     static void SetCompressionBitrate_160kbps() {
    64.         SelectedSetCompressionBitrate(160000);
    65.     }
    66.  
    67.     [MenuItem ("Custom/Sound/Set audio compression bitrate (kbps)/192")]
    68.     static void SetCompressionBitrate_192kbps() {
    69.         SelectedSetCompressionBitrate(192000);
    70.     }
    71.  
    72.     [MenuItem ("Custom/Sound/Set audio compression bitrate (kbps)/224")]
    73.     static void SetCompressionBitrate_224kbps() {
    74.         SelectedSetCompressionBitrate(224000);
    75.     }
    76.  
    77.     [MenuItem ("Custom/Sound/Set audio compression bitrate (kbps)/240")]
    78.     static void SetCompressionBitrate_240kbps() {
    79.         SelectedSetCompressionBitrate(240000);
    80.     }
    81.  
    82.     // ----------------------------------------------------------------------------
    83.  
    84.     [MenuItem ("Custom/Sound/load type/Stream from disc")]
    85.     static void ToggleDecompressOnLoad_Disable() {
    86.         SelectedToggleDecompressOnLoadSettings(AudioImporterLoadType.StreamFromDisc);
    87.     }
    88.  
    89.     [MenuItem ("Custom/Sound/load type/Descompress on Load")]
    90.     static void ToggleDecompressOnLoad_Enable() {
    91.         SelectedToggleDecompressOnLoadSettings(AudioImporterLoadType.DecompressOnLoad);
    92.     }
    93.    
    94.     [MenuItem ("Custom/Sound/load type/CompressedInMemory")]
    95.     static void ToggleDecompressOnLoad_Enable2() {
    96.         SelectedToggleDecompressOnLoadSettings(AudioImporterLoadType.CompressedInMemory);
    97.     }
    98.  
    99.     // ----------------------------------------------------------------------------
    100.  
    101.     [MenuItem ("Custom/Sound/Toggle 3D sound/Disable")]
    102.     static void Toggle3DSound_Disable() {
    103.         SelectedToggle3DSoundSettings(false);
    104.     }
    105.  
    106.     [MenuItem ("Custom/Sound/Toggle 3D sound/Enable")]
    107.     static void Toggle3DSound_Enable() {
    108.         SelectedToggle3DSoundSettings(true);
    109.     }
    110.  
    111.     // ----------------------------------------------------------------------------
    112.  
    113.     [MenuItem ("Custom/Sound/Toggle mono/Auto")]
    114.     static void ToggleForceToMono_Auto() {
    115.         SelectedToggleForceToMonoSettings(false);
    116.     }
    117.  
    118.     [MenuItem ("Custom/Sound/Toggle mono/Forced")]
    119.     static void ToggleForceToMono_Forced() {
    120.         SelectedToggleForceToMonoSettings(true);
    121.     }
    122.  
    123.     // ----------------------------------------------------------------------------
    124.      [MenuItem ("Custom/Sound/Hardware Decoding/Enabled")]
    125.     static void enable_Hardware_yes() {
    126.         enableHardwareDecoding(true);
    127.     }
    128.     [MenuItem ("Custom/Sound/Hardware Decoding/Disabled")]
    129.     static void enable_Hardware_no() {
    130.         enableHardwareDecoding(false);
    131.     }
    132.    
    133.    
    134.    
    135.     static void enableHardwareDecoding ( bool enable )
    136.     {
    137.         Object[] audioclips = GetSelectedAudioclips();
    138.         Selection.objects = new Object[0];
    139.         foreach (AudioClip audioclip in audioclips) {
    140.             string path = AssetDatabase.GetAssetPath(audioclip);
    141.             AudioImporter audioImporter = AssetImporter.GetAtPath(path) as AudioImporter;
    142.             audioImporter.hardware = enable;
    143.             AssetDatabase.ImportAsset(path);
    144.         }
    145.     }
    146.  
    147.     static void SelectedToggleCompressionSettings(AudioImporterFormat newFormat) {
    148.  
    149.         Object[] audioclips = GetSelectedAudioclips();
    150.         Selection.objects = new Object[0];
    151.         foreach (AudioClip audioclip in audioclips) {
    152.             string path = AssetDatabase.GetAssetPath(audioclip);
    153.             AudioImporter audioImporter = AssetImporter.GetAtPath(path) as AudioImporter;
    154.             audioImporter.format = newFormat;
    155.             AssetDatabase.ImportAsset(path);
    156.         }
    157.     }
    158.  
    159.     static void SelectedSetCompressionBitrate(float newCompressionBitrate) {
    160.  
    161.         Object[] audioclips = GetSelectedAudioclips();
    162.         Selection.objects = new Object[0];
    163.         foreach (AudioClip audioclip in audioclips) {
    164.             string path = AssetDatabase.GetAssetPath(audioclip);
    165.             AudioImporter audioImporter = AssetImporter.GetAtPath(path) as AudioImporter;
    166.             audioImporter.compressionBitrate = (int)newCompressionBitrate;
    167.             AssetDatabase.ImportAsset(path);
    168.         }
    169.     }
    170.  
    171.     static void SelectedToggleDecompressOnLoadSettings(AudioImporterLoadType enabled) {
    172.  
    173.         Object[] audioclips = GetSelectedAudioclips();
    174.         Selection.objects = new Object[0];
    175.         foreach (AudioClip audioclip in audioclips) {
    176.             string path = AssetDatabase.GetAssetPath(audioclip);
    177.             AudioImporter audioImporter = AssetImporter.GetAtPath(path) as AudioImporter;
    178.             audioImporter.loadType = enabled;
    179.             AssetDatabase.ImportAsset(path);
    180.         }
    181.     }
    182.  
    183.     static void SelectedToggle3DSoundSettings(bool enabled) {
    184.  
    185.         Object[] audioclips = GetSelectedAudioclips();
    186.         Selection.objects = new Object[0];
    187.         foreach (AudioClip audioclip in audioclips) {
    188.             string path = AssetDatabase.GetAssetPath(audioclip);
    189.             AudioImporter audioImporter = AssetImporter.GetAtPath(path) as AudioImporter;
    190.             audioImporter.threeD = enabled;
    191.             AssetDatabase.ImportAsset(path);
    192.         }
    193.     }
    194.  
    195.     static void SelectedToggleForceToMonoSettings(bool enabled) {
    196.  
    197.         Object[] audioclips = GetSelectedAudioclips();
    198.         Selection.objects = new Object[0];
    199.         foreach (AudioClip audioclip in audioclips) {
    200.             string path = AssetDatabase.GetAssetPath(audioclip);
    201.             AudioImporter audioImporter = AssetImporter.GetAtPath(path) as AudioImporter;
    202.             audioImporter.forceToMono = enabled;
    203.             AssetDatabase.ImportAsset(path);
    204.         }
    205.     }
    206.  
    207.     static Object[] GetSelectedAudioclips()
    208.     {
    209.         return Selection.GetFiltered(typeof(AudioClip), SelectionMode.DeepAssets);
    210.     }
    211. }
    212.  
    213.  
    214.  
     
    chrismarch and gamescorpion like this.
  3. JakeT

    JakeT

    Joined:
    Nov 14, 2010
    Posts:
    33
    worked perfectly for me. I was using this to turn off 3D sound for about 300 files. Just saved me an hour :)
     
  4. michaelvoigt

    michaelvoigt

    Joined:
    Oct 16, 2007
    Posts:
    17
    I am doing a children's book with about 1500 files in 30 folders, this script saved me about 4 hours!

    I needed to change settings on all of them.

    Thank you!
     
  5. kevork

    kevork

    Joined:
    Aug 28, 2011
    Posts:
    31
    This was a great help Kiles!

    One small improvement that could be made is checking to see whether the asset actually changed before Re-Importing it.

    For example:

    Code (csharp):
    1.  
    2.     static void SelectedToggle3DSoundSettings(bool enabled) {
    3.  
    4.         Object[] audioclips = GetSelectedAudioclips();
    5.         Selection.objects = new Object[0];
    6.         foreach (AudioClip audioclip in audioclips) {
    7.             string path = AssetDatabase.GetAssetPath(audioclip);
    8.             AudioImporter audioImporter = AssetImporter.GetAtPath(path) as AudioImporter;
    9.             audioImporter.threeD = enabled;
    10.             AssetDatabase.ImportAsset(path);
    11.         }
    12.     }
    13.  
    to


    Code (csharp):
    1.  
    2.     static void SelectedToggle3DSoundSettings(bool enabled) {
    3.  
    4.         Object[] audioclips = GetSelectedAudioclips();
    5.         Selection.objects = new Object[0];
    6.         foreach (AudioClip audioclip in audioclips) {
    7.             string path = AssetDatabase.GetAssetPath(audioclip);
    8.             AudioImporter audioImporter = AssetImporter.GetAtPath(path) as AudioImporter;
    9.             if(audioImporter.threeD != enabled)
    10.             {
    11.                  audioImporter.threeD = enabled;
    12.                  AssetDatabase.ImportAsset(path);
    13.             }
    14.         }
    15.     }
    16.  
    Thanks again!
     
  6. bernardfrancois

    bernardfrancois

    Joined:
    Oct 29, 2009
    Posts:
    370
    Thanks a lot! I just wanted to find out how to write such a script myself when I stumbled upon this, so this saved me quite a lot of time.
     
  7. philipghu

    philipghu

    Joined:
    Oct 23, 2011
    Posts:
    6
    Great!!
     
  8. kedi189

    kedi189

    Joined:
    Oct 15, 2009
    Posts:
    7
    thanks a lot for sharing this script! Saved us a lot of time.
     
  9. KyleStaves

    KyleStaves

    Joined:
    Nov 4, 2009
    Posts:
    820
    Thanks for the share, the time savings when working with a billion tiny audio files is awesome.
     
  10. DuckOfDoom

    DuckOfDoom

    Joined:
    Apr 15, 2012
    Posts:
    7
    I want to thank you too for this, saved me a lot of time!
     
  11. NickK85

    NickK85

    Joined:
    Oct 3, 2012
    Posts:
    1
    Thanks for this kiles it's rad!
     
  12. omidnoor

    omidnoor

    Joined:
    Feb 22, 2013
    Posts:
    1
    Unity 4 question:

    Hi, I dont know if its a noob one, but I have a question about this script and a related use.

    I want to record a clip using Microphone and save it to my project resource folder, so that I can then load it into an AudioClip and play it. The problem is that i want 3d to be disabled while importing it for playback, also I cant seem to understand how I could use this script even if i want to manually disable 3d for multiple files. Any help?

    Thanks
     
  13. CH

    CH

    Joined:
    Jul 4, 2012
    Posts:
    109
  14. Invent4

    Invent4

    Joined:
    Aug 20, 2012
    Posts:
    9
    Thanks for sharing!
    Nice script. This should be present as natural options of Unity Editor...
     
  15. CH

    CH

    Joined:
    Jul 4, 2012
    Posts:
    109
  16. CH

    CH

    Joined:
    Jul 4, 2012
    Posts:
    109
    dmko likes this.
  17. Poxican

    Poxican

    Joined:
    Oct 17, 2012
    Posts:
    5
    I love this script, I use it daily.

    I used to have a similar one that had a visual interface I could dock in the inspector, but I can't find that one anywhere now. I don't know what it would involve technically, but I wonder if this one could be modified to support that, rather than having to go through nested menus?
     
  18. doctorsleem

    doctorsleem

    Joined:
    May 15, 2013
    Posts:
    1
    People who give away little tools like this are my heroes. Thank you.
     
    ryanreptoid likes this.
  19. angrypenguin

    angrypenguin

    Joined:
    Dec 29, 2011
    Posts:
    9,470
    Cheers, great timesaver. :)
     
  20. ryanreptoid

    ryanreptoid

    Joined:
    Aug 12, 2012
    Posts:
    69
    This is great, thanks!
     
  21. lilboylost

    lilboylost

    Joined:
    Feb 12, 2014
    Posts:
    253
    Thank you
     
  22. gamescorpion

    gamescorpion

    Joined:
    Feb 15, 2014
    Posts:
    113
    Thank you for this amazing script! Just saved me an hour as well! :)

    God Bless!

    Nav
     
  23. Diet-Chugg

    Diet-Chugg

    Joined:
    Jul 4, 2012
    Posts:
    49
    Love intuitive design? Hate Cluttered Unneeded MenuItems? Want this tool to feel more like Unity Native Multiple selected items?

    Me too! So I made it happen. This version gets rid of the menu at the top and instead makes it so when you select two audio clips in the project folder - Bam! The audio settings are right there in the inspector! Lovely. :) Change the settings to what you need and hit apply to change all the audio.

    My version is not perfect and I'm sure it can be taken further but I'd need some help:
    1. Anyone know how to get it to properly show your multiple clips defaults and mixed settings
    2. How do you grey out features that should be not selectable?
    3. One or two of these buttons don't do anything yet. Anyone know how to get them working?
    This only works in Unity 4.6. Feel free to try it elsewhere but get rid of the "&& UNITY_4_6" part of the first line in my script.

    To make this work just Use my modified ChangeAudioImportSettings.cs and add the AudioClipEditor.cs class into the same Editor folder. Have at it:

    Code (CSharp):
    1.  
    2. using UnityEngine;
    3. using UnityEditor;
    4.  
    5. // /////////////////////////////////////////////////////////////////////////////////////////////////////////
    6. //
    7. // Batch audio import settings modifier.
    8. //
    9. // Modifies all selected audio clips in the project window and applies the requested modification on the
    10. // audio clips. Idea was to have the same choices for multiple files as you would have if you open the
    11. // import settings of a single audio clip. Put this into Assets/Editor and once compiled by Unity you find
    12. // the new functionality in Custom -> Sound. Enjoy! :-)
    13. //
    14. // April 2010. Based on Martin Schultz's texture import settings batch modifier.
    15. //
    16. // /////////////////////////////////////////////////////////////////////////////////////////////////////////
    17. public class ChangeAudioImportSettings : ScriptableObject {
    18.  
    19. //    [MenuItem ("Custom/Sound/Toggle audio compression/Disable")]
    20.     static void ToggleCompression_Disable() {
    21.         SelectedToggleCompressionSettings(AudioImporterFormat.Native);
    22.     }
    23.  
    24. //    [MenuItem ("Custom/Sound/Toggle audio compression/Enable")]
    25.     static void ToggleCompression_Enable() {
    26.         SelectedToggleCompressionSettings(AudioImporterFormat.Compressed);
    27.     }
    28.  
    29.     // ----------------------------------------------------------------------------
    30.  
    31. //    [MenuItem ("Custom/Sound/Set audio compression bitrate (kbps)/32")]
    32.     static void SetCompressionBitrate_32kbps() {
    33.         SelectedSetCompressionBitrate(32000);
    34.     }
    35.  
    36. //    [MenuItem ("Custom/Sound/Set audio compression bitrate (kbps)/64")]
    37.     static void SetCompressionBitrate_64kbps() {
    38.         SelectedSetCompressionBitrate(64000);
    39.     }
    40.  
    41. //    [MenuItem ("Custom/Sound/Set audio compression bitrate (kbps)/96")]
    42.     static void SetCompressionBitrate_96kbps() {
    43.         SelectedSetCompressionBitrate(96000);
    44.     }
    45.  
    46. //    [MenuItem ("Custom/Sound/Set audio compression bitrate (kbps)/128")]
    47.     static void SetCompressionBitrate_128kbps() {
    48.         SelectedSetCompressionBitrate(128000);
    49.     }
    50.  
    51. //    [MenuItem ("Custom/Sound/Set audio compression bitrate (kbps)/144")]
    52.     static void SetCompressionBitrate_144kbps() {
    53.         SelectedSetCompressionBitrate(144000);
    54.     }
    55.  
    56. //    [MenuItem ("Custom/Sound/Set audio compression bitrate (kbps)/156 (default)")]
    57.     static void SetCompressionBitrate_156kbps() {
    58.         SelectedSetCompressionBitrate(156000);
    59.     }
    60.  
    61. //    [MenuItem ("Custom/Sound/Set audio compression bitrate (kbps)/160")]
    62.     static void SetCompressionBitrate_160kbps() {
    63.         SelectedSetCompressionBitrate(160000);
    64.     }
    65.  
    66. //    [MenuItem ("Custom/Sound/Set audio compression bitrate (kbps)/192")]
    67.     static void SetCompressionBitrate_192kbps() {
    68.         SelectedSetCompressionBitrate(192000);
    69.     }
    70.  
    71. //    [MenuItem ("Custom/Sound/Set audio compression bitrate (kbps)/224")]
    72.     static void SetCompressionBitrate_224kbps() {
    73.         SelectedSetCompressionBitrate(224000);
    74.     }
    75.  
    76. //    [MenuItem ("Custom/Sound/Set audio compression bitrate (kbps)/240")]
    77.     static void SetCompressionBitrate_240kbps() {
    78.         SelectedSetCompressionBitrate(240000);
    79.     }
    80.  
    81.     // ----------------------------------------------------------------------------
    82.  
    83. //    [MenuItem ("Custom/Sound/load type/Stream from disc")]
    84.     static void ToggleDecompressOnLoad_Disable() {
    85.         SelectedToggleDecompressOnLoadSettings(AudioImporterLoadType.StreamFromDisc);
    86.     }
    87.  
    88. //    [MenuItem ("Custom/Sound/load type/Descompress on Load")]
    89.     static void ToggleDecompressOnLoad_Enable() {
    90.         SelectedToggleDecompressOnLoadSettings(AudioImporterLoadType.DecompressOnLoad);
    91.     }
    92.  
    93. //    [MenuItem ("Custom/Sound/load type/CompressedInMemory")]
    94.     static void ToggleDecompressOnLoad_Enable2() {
    95.         SelectedToggleDecompressOnLoadSettings(AudioImporterLoadType.CompressedInMemory);
    96.     }
    97.  
    98.     // ----------------------------------------------------------------------------
    99.  
    100. //    [MenuItem ("Custom/Sound/Toggle 3D sound/Disable")]
    101.     static void Toggle3DSound_Disable() {
    102.         SelectedToggle3DSoundSettings(false);
    103.     }
    104.  
    105. //    [MenuItem ("Custom/Sound/Toggle 3D sound/Enable")]
    106.     static void Toggle3DSound_Enable() {
    107.         SelectedToggle3DSoundSettings(true);
    108.     }
    109.  
    110.     // ----------------------------------------------------------------------------
    111.  
    112. //    [MenuItem ("Custom/Sound/Toggle mono/Auto")]
    113.     static void ToggleForceToMono_Auto() {
    114.         SelectedToggleForceToMonoSettings(false);
    115.     }
    116.  
    117. //    [MenuItem ("Custom/Sound/Toggle mono/Forced")]
    118.     static void ToggleForceToMono_Forced() {
    119.         SelectedToggleForceToMonoSettings(true);
    120.     }
    121.  
    122.     // ----------------------------------------------------------------------------
    123. //    [MenuItem ("Custom/Sound/Hardware Decoding/Enabled")]
    124.     static void enable_Hardware_yes() {
    125.         enableHardwareDecoding(true);
    126.     }
    127. //    [MenuItem ("Custom/Sound/Hardware Decoding/Disabled")]
    128.     static void enable_Hardware_no() {
    129.         enableHardwareDecoding(false);
    130.     }
    131.  
    132.  
    133.  
    134.     public static void enableHardwareDecoding ( bool enable )
    135.     {
    136.         Object[] audioclips = GetSelectedAudioclips();
    137. //        Selection.objects = new Object[0];
    138.         foreach (AudioClip audioclip in audioclips) {
    139.             string path = AssetDatabase.GetAssetPath(audioclip);
    140.             AudioImporter audioImporter = AssetImporter.GetAtPath(path) as AudioImporter;
    141.             audioImporter.hardware = enable;
    142.             AssetDatabase.ImportAsset(path);
    143.         }
    144.     }
    145.  
    146.     public static void SelectedToggleCompressionSettings(AudioImporterFormat newFormat) {
    147.  
    148.         Object[] audioclips = GetSelectedAudioclips();
    149. //        Selection.objects = new Object[0];
    150.         foreach (AudioClip audioclip in audioclips) {
    151.             string path = AssetDatabase.GetAssetPath(audioclip);
    152.             AudioImporter audioImporter = AssetImporter.GetAtPath(path) as AudioImporter;
    153.             audioImporter.format = newFormat;
    154.             AssetDatabase.ImportAsset(path);
    155.         }
    156.     }
    157.  
    158.     public static void SelectedSetCompressionBitrate(float newCompressionBitrate) {
    159.  
    160.         Object[] audioclips = GetSelectedAudioclips();
    161. //        Selection.objects = new Object[0];
    162.         foreach (AudioClip audioclip in audioclips) {
    163.             string path = AssetDatabase.GetAssetPath(audioclip);
    164.             AudioImporter audioImporter = AssetImporter.GetAtPath(path) as AudioImporter;
    165.             audioImporter.compressionBitrate = (int)newCompressionBitrate;
    166.             AssetDatabase.ImportAsset(path);
    167.         }
    168.     }
    169.  
    170.     public static void SelectedToggleDecompressOnLoadSettings(AudioImporterLoadType enabled) {
    171.  
    172.         Object[] audioclips = GetSelectedAudioclips();
    173. //        Selection.objects = new Object[0];
    174.         foreach (AudioClip audioclip in audioclips) {
    175.             string path = AssetDatabase.GetAssetPath(audioclip);
    176.             AudioImporter audioImporter = AssetImporter.GetAtPath(path) as AudioImporter;
    177.             audioImporter.loadType = enabled;
    178.             AssetDatabase.ImportAsset(path);
    179.         }
    180.     }
    181.  
    182.     public static void SelectedToggle3DSoundSettings(bool enabled) {
    183.  
    184.         Object[] audioclips = GetSelectedAudioclips();
    185. //        Selection.objects = new Object[0];
    186.         foreach (AudioClip audioclip in audioclips) {
    187.             string path = AssetDatabase.GetAssetPath(audioclip);
    188.             AudioImporter audioImporter = AssetImporter.GetAtPath(path) as AudioImporter;
    189.             audioImporter.threeD = enabled;
    190.             AssetDatabase.ImportAsset(path);
    191.         }
    192.     }
    193.  
    194.     public static void SelectedToggleForceToMonoSettings(bool enabled) {
    195.  
    196.         Object[] audioclips = GetSelectedAudioclips();
    197. //        Selection.objects = new Object[0];
    198.         foreach (AudioClip audioclip in audioclips) {
    199.             string path = AssetDatabase.GetAssetPath(audioclip);
    200.             AudioImporter audioImporter = AssetImporter.GetAtPath(path) as AudioImporter;
    201.             audioImporter.forceToMono = enabled;
    202.             AssetDatabase.ImportAsset(path);
    203.         }
    204.     }
    205.  
    206.     static Object[] GetSelectedAudioclips()
    207.     {
    208.         return Selection.GetFiltered(typeof(AudioClip), SelectionMode.DeepAssets);
    209.     }
    210. }
    211.  
    212.  
    Code (CSharp):
    1.  
    2. #if UNITY_EDITOR && UNITY_4_6
    3. using UnityEngine;
    4. using UnityEditor;
    5. using UnityEditorInternal;
    6. using System;
    7. using System.Collections;
    8. using System.Collections.Generic;
    9.  
    10. namespace StarterKit
    11. {
    12.  
    13.     [CustomEditor(typeof(AudioClip)),CanEditMultipleObjects]
    14.     public class AudioClipEditor : Editor
    15.     {
    16.  
    17.         public static bool isLocal = true;
    18.  
    19.         public static SerializedProperty audioFormat;
    20.         public static SerializedProperty audioType;
    21.         public static SerializedProperty is3D;
    22.         public static SerializedProperty loadType;
    23.         public static SerializedProperty useHardware;
    24.         public static SerializedProperty compressionSize;
    25.  
    26.  
    27.         AudioImporterFormat format;
    28.         bool isSelected3D;
    29.         bool isSelectedForceMono;
    30.         bool isSelectedHardwareDecoding;
    31.         bool isSelectedGaplessLooping;
    32.         AudioImporterLoadType selectedLoadType = AudioImporterLoadType.CompressedInMemory;
    33.         int selectedCompression;
    34.  
    35.  
    36.         public void OnEnable()
    37.         {
    38.             if(Selection.objects.Length <= 1)
    39.                 return;
    40.             foreach (SerializedProperty prop in serializedObject.GetIterator())
    41.             {
    42.                 Debug.Log(prop.name);
    43.                 Debug.Log(prop.type.Colorize("blue"));
    44.             }
    45.             audioFormat = serializedObject.FindProperty("m_Format");
    46.             audioType = serializedObject.FindProperty("m_Type");
    47.             useHardware = serializedObject.FindProperty("m_UseHardware");
    48.             is3D = serializedObject.FindProperty("m_3D");
    49.             compressionSize = serializedObject.FindProperty("m_AudioData");//.FindPropertyRelative("size");
    50.             Debug.Log(compressionSize.type);
    51. //            selectedCompression = compressionSize.intValue;
    52.             format = (AudioImporterFormat)Enum.ToObject(typeof(AudioImporterFormat),audioFormat.intValue);
    53.             selectedLoadType = (AudioImporterLoadType)Enum.ToObject(typeof(AudioImporterLoadType),audioType.intValue);
    54.             isSelected3D = is3D.boolValue;
    55.         }
    56.  
    57.  
    58.         public override void OnInspectorGUI ()
    59.         {
    60.             if(Selection.objects.Length <= 1)
    61.                 return;
    62.             GUI.enabled = true;
    63.             EditorGUILayout.LabelField("Adding Multi Clip Editing");
    64. //            AudioImporterFormat audioFormat = AudioImporterFormat.Native;
    65.             format = (AudioImporterFormat)EditorGUILayout.EnumPopup("Audio Format",(Enum)format);
    66.             isSelected3D = EditorGUILayout.Toggle("3D Sound",isSelected3D);
    67.             isSelectedForceMono = EditorGUILayout.Toggle("Force to mono",isSelectedForceMono);
    68.  
    69.             selectedLoadType = (AudioImporterLoadType)EditorGUILayout.EnumPopup("LoadType",(Enum)selectedLoadType);
    70.  
    71.             isSelectedHardwareDecoding = EditorGUILayout.Toggle("Hardware Decoding",isSelectedHardwareDecoding);
    72.             isSelectedGaplessLooping = EditorGUILayout.Toggle("Gapless looping",isSelectedGaplessLooping);
    73.             selectedCompression = EditorGUILayout.IntSlider("Compression (kbps)",selectedCompression,45,500);
    74.  
    75.  
    76.             EditorGUILayout.BeginHorizontal();
    77.             EditorGUILayout.Space();
    78.             if(GUILayout.Button("Apply"))
    79.             {
    80.                 ChangeAudioImportSettings.SelectedToggle3DSoundSettings(isSelected3D);
    81.                 ChangeAudioImportSettings.SelectedToggleForceToMonoSettings(isSelectedForceMono);
    82.                 ChangeAudioImportSettings.enableHardwareDecoding(isSelectedHardwareDecoding);
    83.                 ChangeAudioImportSettings.SelectedToggleCompressionSettings(format);
    84.                 ChangeAudioImportSettings.SelectedToggleDecompressOnLoadSettings(selectedLoadType);
    85.                 ChangeAudioImportSettings.SelectedSetCompressionBitrate(selectedCompression*1000f);
    86. //                serializedObject.ApplyModifiedProperties();
    87.             }
    88.             EditorGUILayout.EndHorizontal();
    89.         }
    90.  
    91.  
    92.  
    93.  
    94.     }
    95. }
    96. #endif
    97.  
    btw, your script saved me tons of work. Thanks!

    ADDITIONAL NOTE: This will no longer be a problem in Unity5. It will be built in!
     
    Last edited: Feb 17, 2015