AudioImportPostProcessor.cs 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. using UnityEngine;
  2. using UnityEditor;
  3. namespace OVR
  4. {
  5. /*
  6. -----------------------
  7. AudioImportPostProcessor()
  8. -----------------------
  9. */
  10. public class AudioImportPostProcessor : AssetPostprocessor {
  11. static void OnPostprocessAllAssets( string[] importedAssets, string[] deletedAssets, string[] movedAssets, string[] movedFromAssetPaths ) {
  12. AudioManager audioManager = AudioManager.Instance;
  13. if ( audioManager != null ) {
  14. // find the asset path to the loaded audio manager prefab
  15. #if UNITY_2018_2_OR_NEWER
  16. Object prefabObject = PrefabUtility.GetCorrespondingObjectFromSource(audioManager);
  17. #else
  18. Object prefabObject = PrefabUtility.GetPrefabParent( audioManager );
  19. #endif
  20. if ( prefabObject != null ) {
  21. string path = AssetDatabase.GetAssetPath( prefabObject );
  22. // check to see if the AudioManager prefab has been reimported.
  23. // if so, rebuild everything
  24. foreach ( string asset in importedAssets ) {
  25. if ( asset.ToLower() == path.ToLower() ) {
  26. // in the event the audio manager is selected, deselect it first before reloading
  27. Debug.Log( "[AudioManager] AudioManager prefab reloaded: " + path );
  28. Selection.objects = new Object[0] { };
  29. // unfortunately even saving the audio manager prefab will trigger this action
  30. //string msg = "The Audio Manager was reloaded. If you are going to be making modifications to the Audio Manager, ";
  31. //msg += "please verify you have the latest version before proceeding. If in doubt, restart Unity before making modifications.";
  32. //EditorUtility.DisplayDialog( "Audio Manager Prefab Reloaded", msg, "OK" );
  33. // do the actual reload
  34. AudioManager.OnPrefabReimported();
  35. break;
  36. }
  37. }
  38. }
  39. }
  40. }
  41. }
  42. } // namespace OVR