void ApplySettingsToSelectedAudioClips()
    {
        foreach (AudioClip audioClip in _selectedAudioClips)
        {
            string        path = AssetDatabase.GetAssetPath(audioClip);
            AudioImporter ai   = AssetImporter.GetAtPath(path) as AudioImporter;

            ai.format             = _format;
            ai.loadType           = _loadType;
            ai.forceToMono        = _forceToMono;
            ai.threeD             = _3dSound;
            ai.compressionBitrate = _compression * 1000;

            AssetDatabase.ImportAsset(path);

            string pathOfAudioClip = AssetDatabase.GetAssetPath(audioClip.GetInstanceID());
            string prefabPath      = Path.GetDirectoryName(pathOfAudioClip) + "/" + audioClip.name + "_go.prefab";

            if (_createWrapperPrefabs)
            {
                GameObject goWrapper = new GameObject();
                goWrapper.name = audioClip.name;
                PsaiAudioClipWrapper coWrapper = goWrapper.AddComponent <PsaiAudioClipWrapper>();
                coWrapper._audioClip = audioClip;
                PrefabUtility.CreatePrefab(prefabPath, goWrapper);
                GameObject.DestroyImmediate(goWrapper);
            }
            else
            {
                if (File.Exists(prefabPath))
                {
                    bool delSuccess = FileUtil.DeleteFileOrDirectory(prefabPath);
                    if (delSuccess)
                    {
                        Debug.Log("successfully deleted Wrapper prefab " + prefabPath);
                    }
                    else
                    {
                        Debug.LogWarning("Wrapper prefab " + prefabPath + " could not be deleted. Please delete it manually in the Project window to save some disk space. It's not harmful though.");
                    }
                }
            }
        }
        AssetDatabase.Refresh();
        EditorApplication.RepaintProjectWindow();
    }
        private IEnumerator LoadSegmentAsync_Coroutine(AudioPlaybackLayerChannelUnity audioPlaybackChannel)
        {
            if (AudioPlaybackLayerChannelUnity._tryToUseWrappers)
            {
                ResourceRequest request = Resources.LoadAsync(audioPlaybackChannel.PathToClipWrapper, typeof(GameObject));
                yield return(request);

#if (!PSAI_NOLOG)
                if (LogLevel.debug <= Logger.Instance.LogLevel)
                {
                    string logMessage = "LoadSegmentAsync_Coroutine [Wrappers] complete, asset=" + request.asset.name;
                    logMessage += "  ImmediatePlaybackIsPending=" + audioPlaybackChannel.PlaybackIsPending;
                    Logger.Instance.Log(logMessage, LogLevel.debug);
                }
#endif

                GameObject wrapperGameObject = request.asset as GameObject;

                if (wrapperGameObject == null)
                {
#if (!PSAI_NOLOG)
                    if (LogLevel.errors <= Logger.Instance.LogLevel)
                    {
                        Logger.Instance.Log("The Wrapper prefab '" + audioPlaybackChannel.PathToClipWrapper + "' was not found! Please run the psaiMultiAudioObjectEditor on your soundtrack folder, and make sure 'create Wrappers' is enabled.", LogLevel.errors);
                    }
#endif
                }
                else
                {
                    PsaiAudioClipWrapper wrapperComponent = wrapperGameObject.GetComponent <PsaiAudioClipWrapper>();
                    if (wrapperComponent == null || wrapperComponent._audioClip == null)
                    {
                        Debug.LogError("a Wrapper prefab for AudioClip '" + audioPlaybackChannel.PathToClip + "' was found, but it was invalid. Please re-run the psaiMultiAudioObjectEditor on your soundtrack folder, and make sure 'create Wrappers' is enabled.");
                    }
                    else
                    {
                        audioPlaybackChannel.AudioClip = wrapperComponent._audioClip;
                    }
                }
            }
            else
            {
                ResourceRequest request = Resources.LoadAsync(audioPlaybackChannel.PathToClip, typeof(AudioClip));
                yield return(request);

#if (!PSAI_NOLOG)
                if (LogLevel.debug <= Logger.Instance.LogLevel)
                {
                    string logMessage = "LoadSegmentAsync_Coroutine [No Wrappers] complete, asset=" + request.asset.name;
                    logMessage += "  ImmediatePlaybackIsPending=" + audioPlaybackChannel.PlaybackIsPending + "   audioPlaybackChannel.GetHashCode()" + audioPlaybackChannel.GetHashCode();
                    Logger.Instance.Log(logMessage, LogLevel.debug);
                }
#endif

                AudioClip clip = request.asset as AudioClip;

                if (clip == null)
                {
#if (!PSAI_NOLOG)
                    if (LogLevel.errors <= Logger.Instance.LogLevel)
                    {
                        Logger.Instance.Log("The AudioClip '" + audioPlaybackChannel.PathToClip + "' was not found!", LogLevel.errors);
                    }
#endif
                }
                else
                {
                    audioPlaybackChannel.AudioClip = clip;
                }
            }

            if (audioPlaybackChannel.PlaybackIsPending)
            {
                while (!audioPlaybackChannel.IsReadyToPlay())
                {
                    yield return(null);

#if (!PSAI_NOLOG)
                    if (LogLevel.warnings <= Logger.Instance.LogLevel)
                    {
                        Logger.Instance.Log("ImmediatePlayback is pending but AudioClip is not ready to play!", LogLevel.warnings);
                    }
#endif
                }

                audioPlaybackChannel.PlayBufferedClipImmediately();
            }
        }
        PsaiResult IAudioPlaybackLayerChannel.LoadSegment(Segment segment)
        {
            _segmentToLoad = segment;
            AudioClip      = null;

#if UNITY_PRO_LICENSE
            if (_psaiAsyncLoader == null)
            {
                GameObject psaiObject = PsaiCoreManager.Instance.gameObject;

                if (psaiObject == null)
                {
                    #if !(PSAI_NOLOG)
                    if (LogLevel.errors <= Logger.Instance.LogLevel)
                    {
                        Logger.Instance.Log("No 'Psai' object found in the Scene! Please make sure to add the Psai.prefab from the Psai.unitypackage to your Scene", LogLevel.errors);
                    }
                    #endif
                    return(PsaiResult.initialization_error);
                }
                _psaiAsyncLoader = psaiObject.AddComponent <PsaiAsyncLoader>();
            }
#endif


            // careful! Using Path.Combine for the subfolders does not work for the Resources subfolders,
            // neither does "\\" double backslashes. So leave it like this, it works for WebPlayer and Standalone.
            // not checked yet for iOS and Android. If in doubt, leave out the subfolders.

            //string pathToClip = null;
            string psaiBinaryDirectoryName = Logik.Instance.m_psaiCoreBinaryDirectoryName;
            if (psaiBinaryDirectoryName.Length > 0)
            {
                PathToClip = psaiBinaryDirectoryName + "/" + segment.audioData.filePathRelativeToProjectDir;
            }
            else
            {
                PathToClip = segment.audioData.filePathRelativeToProjectDir;
            }


#if UNITY_PRO_LICENSE
            {
                _audioSource.clip = null;       // we reset the clip to prevent the situation in ScheduleSegmentPlayback(), where the previous clip was reported as readyToPlay, causing problems.
                _psaiAsyncLoader.LoadSegmentAsync(this);
            }
            return(PsaiResult.OK);
#else
            if (_tryToUseWrappers)
            {
                GameObject wrapperGameObject = (GameObject)UnityEngine.Resources.Load(PathToClipWrapper, typeof(GameObject));
                if (wrapperGameObject != null)
                {
                    PsaiAudioClipWrapper wrapperComponent = wrapperGameObject.GetComponent <PsaiAudioClipWrapper>();
                    if (wrapperComponent == null || wrapperComponent._audioClip == null)
                    {
                        Debug.LogError("a Wrapper prefab for AudioClip '" + _segmentToLoad.audioData.filePathRelativeToProjectDir + "' was found, but it was invalid. Please re-run the psaiMultiAudioObjectEditor on your soundtrack folder, and make sure 'create Wrappers' is enabled.");
                    }
                    else
                    {
                        AudioClip = wrapperComponent._audioClip;

                        #if (!PSAI_NOLOG)
                        if (LogLevel.debug <= Logger.Instance.LogLevel)
                        {
                            Logger.Instance.Log("success: audioClip loaded from Wrapper (synchronous)", LogLevel.debug);
                        }
                        #endif
                    }
                }
            }

            // Fallback: Load Clip directly.
            if (AudioClip == null)
            {
                AudioClip = UnityEngine.Resources.Load(PathToClip) as AudioClip;

#if (!PSAI_NOLOG)
                if (_tryToUseWrappers && !_psaiWrapperWarningHasBeenShown && LogLevel.warnings <= Logger.Instance.LogLevel)
                {
                    Logger.Instance.Log("Due to an issue in Unity 4.x AudioClips will in some cases not be streamed from disk, even if their import settings are set accordingly. This may cause framerate drops whenever a new Segment is loaded. Psai provides a workaround for this, by wrapping each AudioClip in a dedicated GameObject. To have the Wrappers created, please right-click on your soundtrack folder in the Project window, and run the 'psai Multi Audio Object Editor'. Make sure 'use Wrappers' is enabled.", LogLevel.warnings);
                    _psaiWrapperWarningHasBeenShown = true;
                }
#endif
            }


            /* final check to return PsaiResult and write Log */
            if (AudioClip == null)
            {
#if (!PSAI_NOLOG)
                if (LogLevel.errors <= Logger.Instance.LogLevel)
                {
                    Logger.Instance.Log("Segment not found: " + PathToClipWrapper, LogLevel.errors);
                }
#endif
                return(PsaiResult.file_notFound);
            }
            else
            {
#if (!PSAI_NOLOG)
                if (LogLevel.debug <= Logger.Instance.LogLevel)
                {
                    Logger.Instance.Log("LoadSegment() OK - segment.Name:" + segment.Name + " _audioSource.clip: " + _audioSource.clip + " PathToClip:" + PathToClip, LogLevel.debug);
                }
#endif
                return(PsaiResult.OK);
            }
#endif
        }