private static SerializedObject GetSerializedObject(AssetAuditor.AssetType assetType)
        {
            SerializedObject so = null;

            switch (assetType)
            {
            case AssetAuditor.AssetType.Texture:
                so = new SerializedObject(TextureImporter.GetAtPath(AssetAuditorPreferences.ProxyTexturePath));
                break;

            case AssetAuditor.AssetType.Model:
                so = new SerializedObject(ModelImporter.GetAtPath(AssetAuditorPreferences.ProxyModelPath));
                break;

            case AssetAuditor.AssetType.Audio:
                so = new SerializedObject(AudioImporter.GetAtPath(AssetAuditorPreferences.ProxyAudioPath));
                break;

            case AssetAuditor.AssetType.Folder:
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
            return(so);
        }
Beispiel #2
0
        public static void FixByOneKey(string projectCode, string folder, bool isCombProj = false)
        {
            string root = Path.GetFullPath(".") + Path.DirectorySeparatorChar + "Assets" + Path.DirectorySeparatorChar;

            string searchPath = root + folder + (isCombProj ? Path.DirectorySeparatorChar + projectCode : "");

            if (!Directory.Exists(searchPath))
            {
                return;
            }

            List <string> filePath = new List <string>();

            filePath.AddRange(
                Directory.GetFiles(searchPath, "*.*", SearchOption.AllDirectories)
                );
            int counter = -1;

            foreach (string file in filePath)
            {
                string tempFolder = file.Substring(root.Length);
                EditorUtility.DisplayProgressBar("Search File", tempFolder, counter / (float)filePath.Count);
                counter++;

                string ext = Path.GetExtension(file).ToLower();
                if (ext.Equals(".mp3") || ext.Equals(".wav") || ext.Equals(".ogg") || ext.Equals(".m4a"))
                {
                    string    path          = file.Substring(file.IndexOf("Assets/"));
                    AudioClip audio         = AssetDatabase.LoadAssetAtPath <AudioClip>(path);
                    var       audioImporter = (AudioImporter)AudioImporter.GetAtPath(path);
                    var       isDirty       = false;
                    if (audio && audio.length > MAX_LENGTH &&
                        audioImporter.defaultSampleSettings.loadType != AudioClipLoadType.Streaming)
                    {
                        var setting = audioImporter.defaultSampleSettings;
                        setting.loadType = AudioClipLoadType.Streaming;
                        audioImporter.defaultSampleSettings = setting;
                        isDirty = true;
                    }
                    if (audio && audioImporter.forceToMono == false)
                    {
                        audioImporter.forceToMono = true;
                        isDirty = true;

                        SerializedObject   serializedObject = new UnityEditor.SerializedObject(audioImporter);
                        SerializedProperty normalize        = serializedObject.FindProperty("m_Normalize");
                        normalize.boolValue = false;
                        serializedObject.ApplyModifiedProperties();
                    }
                    if (isDirty)
                    {
                        audioImporter.SaveAndReimport();
                        EditorUtility.SetDirty(audio);
                    }
                }
            }

            EditorUtility.ClearProgressBar();
            AssetDatabase.Refresh();
        }
Beispiel #3
0
    public void AudioMethod()
    {
#if UNITY_EDITOR
        var allModel = Path.Combine(Application.dataPath, "Resources/sound");
        //var import = ModelImporter.GetAtPath("Assets/Resources/sound") as ModelImporter;
        Debug.Log("allModel " + allModel);
        var resDir   = new DirectoryInfo(allModel);
        var fileInfo = resDir.GetFiles("*.wav", SearchOption.AllDirectories);
        AssetDatabase.StartAssetEditing();
        foreach (FileInfo file in fileInfo)
        {
            Debug.Log("Directory name " + file.FullName);
            var ass    = file.FullName.Replace(Application.dataPath, "Assets");
            var import = AudioImporter.GetAtPath(ass) as AudioImporter;
            //Debug.Log("import "+import);

            import.format             = AudioImporterFormat.Compressed;
            import.compressionBitrate = 32000;

            Debug.Log("import " + import.compressionBitrate);
            AssetDatabase.WriteImportSettingsIfDirty(ass);
        }
        AssetDatabase.StopAssetEditing();
        AssetDatabase.Refresh();
#endif
    }
Beispiel #4
0
    private void ApplyClipChanges(AudioInformation info, bool writeChanges)
    {
        Selection.objects = new Object[] { }; // unselect to get "Apply" to work automatically.

        // ReSharper disable once AccessToStaticMemberViaDerivedType
        var importer = (AudioImporter)AudioImporter.GetAtPath(info.FullPath);
        AudioImporterSampleSettings settings = importer.defaultSampleSettings;

        importer.forceToMono       = info.ForceMono;
        importer.loadInBackground  = info.LoadBG;
        importer.preloadAudioData  = info.Preload;
        settings.loadType          = info.LoadType;
        settings.compressionFormat = info.CompressionFormat;
        if (settings.compressionFormat == AudioCompressionFormat.Vorbis)
        {
            settings.quality = info.Quality;
        }
        settings.sampleRateSetting = info.SampleRateSetting;
        if (settings.sampleRateSetting == AudioSampleRateSetting.OverrideSampleRate)
        {
            settings.sampleRateOverride = (uint)info.SampleRateOverride;
        }

        importer.defaultSampleSettings = settings;

        AssetDatabase.ImportAsset(info.FullPath, ImportAssetOptions.ForceUpdate);
        info.HasChanged = true;

        if (writeChanges)
        {
            WriteFile(_clipList);
        }
    }
Beispiel #5
0
 void OnWizardCreate()
 {
     if (wave != null)
     {
         wave.Publish(path);
         AudioImporter.GetAtPath(path).SaveAndReimport();
     }
 }
    public static void ChangeAudio3DSettings(AudioClip a, bool threeD)
    {
        string        path = AssetDatabase.GetAssetPath(a);
        AudioImporter ai   = AudioImporter.GetAtPath(path) as AudioImporter;

        ai.threeD = threeD;
        AssetDatabase.ImportAsset(path, ImportAssetOptions.ForceSynchronousImport);
        Debug.Log("AudioClip \"" + path + "\" 3D is now " + ai.threeD);
    }
Beispiel #7
0
    public static void set_audio_for_2D(AudioClip aClip)
    {
        string        path          = AssetDatabase.GetAssetPath(aClip);
        AudioImporter audioImporter = AudioImporter.GetAtPath(path) as AudioImporter;

        audioImporter.threeD = false;
        //audioImporter.loadType = AudioClipLoadType.Streaming;
        AssetDatabase.ImportAsset(path);
    }
Beispiel #8
0
    private static void CompVorbis70()
    {
        AudioClip[] clip = Selection.GetFiltered <AudioClip>(SelectionMode.DeepAssets);

        AssetDatabase.StartAssetEditing();
        {
            int guidCount = clip.Length;
            for (int i = 0; i < guidCount; ++i)
            {
                string assetPath = AssetDatabase.GetAssetPath(clip[i]);
                EditorUtility.DisplayProgressBar(string.Format("Setting Import Settings [{0} / {1}]", i, guidCount), assetPath, i / (float)guidCount);

                AudioImporter importer = (AudioImporter)AudioImporter.GetAtPath(assetPath);
                if (importer != null)
                {
                    bool changed = false;

                    AudioImporterSampleSettings settings = importer.defaultSampleSettings;
                    if (changed |= (settings.loadType != AudioClipLoadType.CompressedInMemory))
                    {
                        settings.loadType = AudioClipLoadType.CompressedInMemory;
                    }

                    if (changed |= (settings.compressionFormat != AudioCompressionFormat.Vorbis))
                    {
                        settings.compressionFormat = AudioCompressionFormat.Vorbis;
                    }

                    if (changed |= (settings.quality != 0.7f))
                    {
                        settings.quality = 0.7f;
                    }

                    if (changed |= (settings.sampleRateSetting != AudioSampleRateSetting.PreserveSampleRate))
                    {
                        settings.sampleRateSetting = AudioSampleRateSetting.PreserveSampleRate;
                    }

                    if (changed == true)
                    {
                        importer.defaultSampleSettings = settings;
                        importer.SaveAndReimport();
                    }
                }
            }
            EditorUtility.ClearProgressBar();
        }
        AssetDatabase.StopAssetEditing();

        AssetDatabase.SaveAssets();
    }
Beispiel #9
0
    private void BuildCache()
    {
        var filePaths = AssetDatabase.GetAllAssetPaths();

        var audioInfo = new AudioInfoData();

        _filterClips = null;
        _pageNumber  = 0;

        var updatedTime = DateTime.Now.Ticks;

        foreach (var aPath in filePaths)
        {
            if (!aPath.EndsWith(".wav", StringComparison.InvariantCultureIgnoreCase) &&
                !aPath.EndsWith(".mp3", StringComparison.InvariantCultureIgnoreCase) &&
                !aPath.EndsWith(".ogg", StringComparison.InvariantCultureIgnoreCase) &&
                !aPath.EndsWith(".aiff", StringComparison.InvariantCultureIgnoreCase))
            {
                continue;
            }

            // ReSharper disable once AccessToStaticMemberViaDerivedType
            var importer = (AudioImporter)AudioImporter.GetAtPath(aPath);

            var bitrate = importer.compressionBitrate;

            if (bitrate < 0)
            {
                bitrate = 156000;
            }

            // ReSharper disable once UseObjectOrCollectionInitializer
            var newClip = new AudioInformation(aPath, Path.GetFileNameWithoutExtension(aPath), importer.threeD, bitrate, importer.forceToMono, importer.format, importer.loadType);

            newClip.LastUpdated = updatedTime;

            audioInfo.AudioInfor.Add(newClip);
        }

        audioInfo.AudioInfor.RemoveAll(delegate(AudioInformation obj) {
            return(obj.LastUpdated < updatedTime);
        });

        // write file
        if (!WriteFile(audioInfo))
        {
            return;
        }

        LoadAndTranslateFile();
    }
    private void BuildCache()
    {
        string[] filePaths = AssetDatabase.GetAllAssetPaths();

        var audioInfo = new AudioInfoData();

        filterClips = null;
        pageNumber  = 0;

        var updatedTime = DateTime.Now.Ticks;

        for (var i = 0; i < filePaths.Length; i++)
        {
            var aPath = filePaths[i];

            if (!aPath.EndsWith(".wav", StringComparison.InvariantCultureIgnoreCase) &&
                !aPath.EndsWith(".mp3", StringComparison.InvariantCultureIgnoreCase) &&
                !aPath.EndsWith(".ogg", StringComparison.InvariantCultureIgnoreCase))
            {
                continue;
            }

            var importer = (AudioImporter)AudioImporter.GetAtPath(aPath);

            var bitrate = importer.compressionBitrate;
            if (bitrate < 0)
            {
                bitrate = 156000;
            }

            var newClip = new AudioInfo(aPath, Path.GetFileNameWithoutExtension(aPath), importer.threeD, bitrate, importer.forceToMono, importer.format, importer.loadType);
            newClip._lastUpdated = updatedTime;

            audioInfo.audioInfo.Add(newClip);
        }

        audioInfo.audioInfo.RemoveAll(delegate(AudioInfo obj) {
            return(obj._lastUpdated < updatedTime);
        });

        // write file
        if (!WriteFile(audioInfo))
        {
            return;
        }

        LoadAndTranslateFile();
    }
Beispiel #11
0
    // forceMono 是否单声道
    // bSensitive 时延是否敏感
    private static void DealAudioPath(string strPath, bool forceMono, bool bSensitive = false, bool compressSampleRate = true)
    {
        string[] arrFiles = FileHelper.GetAllChildFiles(strPath, ".ogg", SearchOption.AllDirectories);
        int      len      = arrFiles.Length;

        for (int i = 0; i < len; i++)
        {
            string assetPath = arrFiles [i];
            EditorUtility.DisplayProgressBar(strPath, assetPath, ((float)i + 1) / len);
            AudioClip     clip     = AssetDatabase.LoadAssetAtPath <AudioClip>(assetPath);
            AudioImporter importer = AudioImporter.GetAtPath(assetPath) as AudioImporter;

            DealAudioImporter(clip, importer, forceMono, bSensitive, compressSampleRate);
        }
        EditorUtility.ClearProgressBar();
    }
        private void BuildCache()
        {
            var filePaths = AssetDatabase.GetAllAssetPaths();

            var audioInfo = new AudioInfoData();

            _filterClips = null;
            _pageNumber  = 0;

            var updatedTime = DateTime.Now.Ticks;

            foreach (var aPath in filePaths)
            {
                if (!aPath.EndsWith(".wav", StringComparison.InvariantCultureIgnoreCase) &&
                    !aPath.EndsWith(".mp3", StringComparison.InvariantCultureIgnoreCase) &&
                    !aPath.EndsWith(".ogg", StringComparison.InvariantCultureIgnoreCase) &&
                    !aPath.EndsWith(".aiff", StringComparison.InvariantCultureIgnoreCase))
                {
                    continue;
                }

                // ReSharper disable once AccessToStaticMemberViaDerivedType
                var importer = (AudioImporter)AudioImporter.GetAtPath(aPath);

                // ReSharper disable once UseObjectOrCollectionInitializer
                AudioImporterSampleSettings settings = importer.defaultSampleSettings;
                var newClip = new AudioInformation(aPath, Path.GetFileNameWithoutExtension(aPath), importer.forceToMono, importer.loadInBackground, importer.preloadAudioData,
                                                   settings.loadType, settings.compressionFormat, settings.quality, settings.sampleRateSetting, int.Parse(settings.sampleRateOverride.ToString()));

                newClip.LastUpdated = updatedTime;

                audioInfo.AudioInfor.Add(newClip);
            }

            audioInfo.AudioInfor.RemoveAll(delegate(AudioInformation obj)
            {
                return(obj.LastUpdated < updatedTime);
            });

            // write file
            if (!WriteFile(audioInfo))
            {
                return;
            }

            LoadAndTranslateFile();
        }
	public static void SetAudioFilesAs2D(){
		Debug.Log(Selection.activeObject.GetType());
		Object[] audios = Selection.GetFiltered(typeof(AudioClip), SelectionMode.Assets);

		int amount = 0;
		foreach(AudioClip a in audios){
			string path = AssetDatabase.GetAssetPath(a);
			AudioImporter ai = AudioImporter.GetAtPath(path) as AudioImporter;

			if(ai.threeD){
				ai.threeD = false;
				amount++;
			}
		}

		Debug.Log(""+amount+" AudioClips converted to 2D.");
	}
Beispiel #14
0
        public const int MAX_LENGTH = 10;         //最大声音时间 ,单位秒

        public static string Execute(string projectCode, string folder, bool isCombProj = false)
        {
            string root = Path.GetFullPath(".") + Path.DirectorySeparatorChar + "Assets" + Path.DirectorySeparatorChar;

            string searchPath = root + folder + (isCombProj ? Path.DirectorySeparatorChar + projectCode:"");

            if (!Directory.Exists(searchPath))
            {
                return("");
            }

            List <string> filePath = new List <string>();

            filePath.AddRange(
                Directory.GetFiles(searchPath, "*.*", SearchOption.AllDirectories)
                );
            int counter = -1;

            foreach (string file in filePath)
            {
                string tempFolder = file.Substring(root.Length);
                EditorUtility.DisplayProgressBar("Search File", tempFolder, counter / (float)filePath.Count);
                counter++;

                string ext = Path.GetExtension(file).ToLower();
                if (ext.Equals(".mp3") || ext.Equals(".wav") || ext.Equals(".ogg") || ext.Equals(".m4a"))
                {
                    string    path          = file.Substring(file.IndexOf("Assets/"));
                    AudioClip audio         = AssetDatabase.LoadAssetAtPath <AudioClip> (path);
                    var       audioImporter = (AudioImporter)AudioImporter.GetAtPath(path);
                    if (audio && audio.length > MAX_LENGTH && audioImporter.defaultSampleSettings.loadType != AudioClipLoadType.Streaming)
                    {
                        EditorUtility.ClearProgressBar();
                        return("此声音文件没有设置成Streaming: " + tempFolder);
                    }
                    if (audio && audioImporter.forceToMono == false)
                    {
                        EditorUtility.ClearProgressBar();
                        return("此声音文件没有设置成Mono(单声道): " + tempFolder);
                    }
                }
            }

            EditorUtility.ClearProgressBar();
            return("");
        }
Beispiel #15
0
    void SetAudioImporterFormat(AudioClip audio)
    {
        if (audio == null)
        {
            return;
        }

        string        assetPath = AssetDatabase.GetAssetPath(audio);
        AudioImporter importer  = AudioImporter.GetAtPath(assetPath) as AudioImporter;

        if (importer != null)
        {
            importer.threeD   = false;
            importer.loadType = AudioImporterLoadType.StreamFromDisc;

            AssetDatabase.ImportAsset(assetPath);
            AssetDatabase.Refresh();
        }
    }
    private void ApplyClipChanges(AudioInfo info, bool writeChanges)
    {
        Selection.objects = new UnityEngine.Object[] { };         // unselect to get "Apply" to work automatically.

        var importer = (AudioImporter)AudioImporter.GetAtPath(info._fullPath);

        importer.compressionBitrate = info._compressionBitrate;
        importer.forceToMono        = info._forceMono;
        importer.format             = info._format;
        importer.loadType           = info._loadType;
        importer.threeD             = info._is3d;

        AssetDatabase.ImportAsset(info._fullPath, ImportAssetOptions.ForceUpdate);
        info._hasChanged = true;

        if (writeChanges)
        {
            WriteFile(clipList);
        }
    }
Beispiel #17
0
    private void ApplyClipChanges(AudioInformation info, bool writeChanges)
    {
        Selection.objects = new Object[] { }; // unselect to get "Apply" to work automatically.

        // ReSharper disable once AccessToStaticMemberViaDerivedType
        var importer = (AudioImporter)AudioImporter.GetAtPath(info.FullPath);

        importer.compressionBitrate = info.CompressionBitrate;

        importer.forceToMono = info.ForceMono;
        importer.format      = info.Format;
        importer.loadType    = info.LoadType;
        importer.threeD      = info.Is3D;

        AssetDatabase.ImportAsset(info.FullPath, ImportAssetOptions.ForceUpdate);
        info.HasChanged = true;

        if (writeChanges)
        {
            WriteFile(_clipList);
        }
    }
Beispiel #18
0
    private static void ClearHighSampleRate()
    {
        AudioClip[] clip = Selection.GetFiltered <AudioClip>(SelectionMode.DeepAssets);

        AssetDatabase.StartAssetEditing();
        {
            int guidCount = clip.Length;
            for (int i = 0; i < guidCount; ++i)
            {
                string assetPath = AssetDatabase.GetAssetPath(clip[i]);
                EditorUtility.DisplayProgressBar(string.Format("Setting Import Settings [{0} / {1}]", i, guidCount), assetPath, i / (float)guidCount);

                AudioImporter importer = (AudioImporter)AudioImporter.GetAtPath(assetPath);
                if (importer != null)
                {
                    bool changed = false;

                    AudioImporterSampleSettings settings = importer.defaultSampleSettings;

                    if (changed |= clip[i].frequency > 48000)
                    {
                        settings.sampleRateSetting  = AudioSampleRateSetting.OverrideSampleRate;
                        settings.sampleRateOverride = 48000;
                    }


                    if (changed == true)
                    {
                        importer.defaultSampleSettings = settings;
                        importer.SaveAndReimport();
                    }
                }
            }
            EditorUtility.ClearProgressBar();
        }
        AssetDatabase.StopAssetEditing();

        AssetDatabase.SaveAssets();
    }
    public static void SetAudioFilesAs3D()
    {
        EditorApplication.Beep();
        Object[] audios = Selection.GetFiltered(typeof(AudioClip), SelectionMode.Assets);

        int amount = 0;

        foreach (AudioClip a in audios)
        {
            string        path = AssetDatabase.GetAssetPath(a);
            AudioImporter ai   = AudioImporter.GetAtPath(path) as AudioImporter;

            if (!ai.threeD)
            {
                ai.threeD = true;
                amount++;
            }
            AssetDatabase.ImportAsset(path, ImportAssetOptions.ForceSynchronousImport);
        }

        Debug.Log("" + amount + " AudioClips converted to 3D.");
    }
Beispiel #20
0
    // ------------------------------------------------------------------
    // Desc:
    // ------------------------------------------------------------------

    void ApplySettings()
    {
        if (Selection.activeObject is Texture2D)
        {
            string          path          = AssetDatabase.GetAssetPath(Selection.activeObject);
            TextureImporter firstImporter = TextureImporter.GetAtPath(path) as TextureImporter;

            try {
                int i = 0;
                foreach (Object o in Selection.objects)
                {
                    if ((o is Texture2D) == false)
                    {
                        continue;
                    }

                    path = AssetDatabase.GetAssetPath(o);
                    TextureImporter importer = TextureImporter.GetAtPath(path) as TextureImporter;

                    importer.textureFormat    = firstImporter.textureFormat;
                    importer.maxTextureSize   = firstImporter.maxTextureSize;
                    importer.grayscaleToAlpha = firstImporter.grayscaleToAlpha;
                    importer.generateCubemap  = firstImporter.generateCubemap;
                    importer.npotScale        = firstImporter.npotScale;
                    importer.isReadable       = firstImporter.isReadable;
                    importer.mipmapEnabled    = firstImporter.mipmapEnabled;
                    importer.borderMipmap     = firstImporter.borderMipmap;
#if UNITY_3_4
                    importer.correctGamma = firstImporter.correctGamma;
#else
                    importer.generateMipsInLinearSpace = firstImporter.generateMipsInLinearSpace;
#endif
                    importer.mipmapFilter            = firstImporter.mipmapFilter;
                    importer.fadeout                 = firstImporter.fadeout;
                    importer.mipmapFadeDistanceStart = firstImporter.mipmapFadeDistanceStart;
                    importer.mipmapFadeDistanceEnd   = firstImporter.mipmapFadeDistanceEnd;
                    importer.convertToNormalmap      = firstImporter.convertToNormalmap;
                    importer.normalmap               = firstImporter.normalmap;
                    importer.normalmapFilter         = firstImporter.normalmapFilter;
                    importer.heightmapScale          = firstImporter.heightmapScale;
                    importer.lightmap                = firstImporter.lightmap;
                    importer.anisoLevel              = firstImporter.anisoLevel;
                    importer.filterMode              = firstImporter.filterMode;
                    importer.wrapMode                = firstImporter.wrapMode;
                    importer.mipMapBias              = firstImporter.mipMapBias;
                    importer.textureType             = firstImporter.textureType;

                    EditorUtility.DisplayProgressBar("Process Textures...",
                                                     "Process Texture " + o.name,
                                                     (float)i / (float)Selection.objects.Length);
                    AssetDatabase.ImportAsset(path, ImportAssetOptions.ForceUpdate | ImportAssetOptions.ForceSynchronousImport);
                    ++i;
                }
                EditorUtility.ClearProgressBar();
            }
            catch (System.Exception) {
                EditorUtility.ClearProgressBar();
                throw;
            }
        }
        else if (Selection.activeObject is AudioClip)
        {
            string        path          = AssetDatabase.GetAssetPath(Selection.activeObject);
            AudioImporter firstImporter = AudioImporter.GetAtPath(path) as AudioImporter;

            try {
                int i = 0;
                foreach (Object o in Selection.objects)
                {
                    if ((o is AudioClip) == false)
                    {
                        continue;
                    }

                    path = AssetDatabase.GetAssetPath(o);
                    AudioImporter importer = AudioImporter.GetAtPath(path) as AudioImporter;

                    importer.format             = firstImporter.format;
                    importer.compressionBitrate = firstImporter.compressionBitrate;
                    importer.threeD             = firstImporter.threeD;
                    importer.forceToMono        = firstImporter.forceToMono;
                    importer.hardware           = firstImporter.hardware;
                    importer.loopable           = firstImporter.loopable;

                    EditorUtility.DisplayProgressBar("Process AudioClips...",
                                                     "Process AudioClip " + o.name,
                                                     (float)i / (float)Selection.objects.Length);
                    AssetDatabase.ImportAsset(path, ImportAssetOptions.ForceUpdate | ImportAssetOptions.ForceSynchronousImport);
                    ++i;
                }
                EditorUtility.ClearProgressBar();
            }
            catch (System.Exception) {
                EditorUtility.ClearProgressBar();
                throw;
            }
        }
    }
            public override void InitDetailCheckObject(Object obj)
            {
                AudioClip    clip               = obj as AudioClip;
                AudioChecker checker            = currentChecker as AudioChecker;
                string       compression        = buildInType;
                int          quality            = 0;
                string       sampleRateSetting  = buildInType;
                int          overrideSampleRate = 0;

                string androidOverride          = buildInType;
                string androidLoadType          = buildInType;
                string androidCompression       = buildInType;
                int    androidQuality           = 0;
                string androidSampleRateSetting = buildInType;
                int    androidSampleRate        = 0;

                string iosOverride          = buildInType;
                string iosLoadType          = buildInType;
                string iosCompression       = buildInType;
                int    iosQuality           = 0;
                string iosSampleRateSetting = buildInType;
                int    iosSampleRate        = 0;

                AudioImporter importer = AudioImporter.GetAtPath(assetPath) as AudioImporter;

                if (importer != null)
                {
                    compression        = importer.defaultSampleSettings.compressionFormat.ToString();
                    quality            = Mathf.Clamp((int)(importer.defaultSampleSettings.quality * 100), 1, 100);
                    sampleRateSetting  = importer.defaultSampleSettings.sampleRateSetting.ToString();
                    overrideSampleRate = (int)importer.defaultSampleSettings.sampleRateOverride;

                    AudioImporterSampleSettings androidSettings = importer.GetOverrideSampleSettings(platformAndroid);
                    androidOverride          = importer.ContainsSampleSettingsOverride(platformAndroid).ToString();
                    androidLoadType          = androidSettings.loadType.ToString();
                    androidCompression       = androidSettings.compressionFormat.ToString();
                    androidQuality           = Mathf.Clamp((int)(androidSettings.quality * 100), 1, 100);
                    androidSampleRateSetting = androidSettings.sampleRateSetting.ToString();
                    androidSampleRate        = (int)androidSettings.sampleRateOverride;

                    AudioImporterSampleSettings iosSettings = importer.GetOverrideSampleSettings(platformIOS);
                    iosOverride          = importer.ContainsSampleSettingsOverride(platformIOS).ToString();
                    iosLoadType          = iosSettings.loadType.ToString();
                    iosCompression       = iosSettings.compressionFormat.ToString();
                    iosQuality           = Mathf.Clamp((int)(iosSettings.quality * 100), 1, 100);
                    iosSampleRateSetting = iosSettings.sampleRateSetting.ToString();
                    iosSampleRate        = (int)iosSettings.sampleRateOverride;
                }
                checkMap.Add(checker.audioLength, clip.length);
                checkMap.Add(checker.audioType, clip.loadType.ToString());
                checkMap.Add(checker.audioChannel, clip.channels);
                checkMap.Add(checker.audioCompression, compression);
                checkMap.Add(checker.audioQuality, quality);
                checkMap.Add(checker.audioSampleRateSetting, sampleRateSetting);
                checkMap.Add(checker.audioSampleRate, overrideSampleRate);
                checkMap.Add(checker.audioPostfix, ResourceCheckerHelper.GetAssetPostfix(assetPath));

                checkMap.Add(checker.audioAndroidOverride, androidOverride);
                checkMap.Add(checker.audioAndroidLoadType, androidLoadType);
                checkMap.Add(checker.audioAndroidCompressionFormat, androidCompression);
                checkMap.Add(checker.audioAndroidQuality, androidQuality);
                checkMap.Add(checker.audioAndroidSampleRateSetting, androidSampleRateSetting);
                checkMap.Add(checker.audioAndroidSampleRate, androidSampleRate);

                checkMap.Add(checker.audioIOSOverride, iosOverride);
                checkMap.Add(checker.audioIOSLoadType, iosLoadType);
                checkMap.Add(checker.audioIOSCompressionFormat, iosCompression);
                checkMap.Add(checker.audioIOSQuality, iosQuality);
                checkMap.Add(checker.audioIOSSampleRateSetting, iosSampleRateSetting);
                checkMap.Add(checker.audioIOSSampleRate, iosSampleRate);
            }
        public void SetAudioClipConfig(AudioClip clip)
        {
            string        path          = AssetDatabase.GetAssetPath(clip);
            AudioImporter audioImporter = AudioImporter.GetAtPath(path) as AudioImporter;

            if (audioImporter == null)
            {
                return;
            }
            AudioImporterSampleSettings settings = audioImporter.defaultSampleSettings;

            switch (target)
            {
            case ResourceTarget.Default:
                settings = audioImporter.defaultSampleSettings;
                break;

            case ResourceTarget.Android:
                settings = audioImporter.GetOverrideSampleSettings("Android");
                break;

            case ResourceTarget.IOS:
                settings = audioImporter.GetOverrideSampleSettings("IOS");
                break;
            }

            if (bForceToMono)
            {
                audioImporter.forceToMono = audioConfig.forceToMono;
            }
            if (bLoadInBackground)
            {
                audioImporter.loadInBackground = audioConfig.loadInBackground;
            }
            if (bAudioCompressionFormat)
            {
                settings.compressionFormat = audioConfig.defaultAudioSettings.compressionFormat;
            }
            if (bAudioLoadType)
            {
                settings.loadType = audioConfig.defaultAudioSettings.loadType;
            }
            if (bQuality)
            {
                settings.quality = audioConfig.defaultAudioSettings.quality;
            }
            if (bAudioSampleRateSetting)
            {
                settings.sampleRateSetting = audioConfig.defaultAudioSettings.sampleRateSetting;
            }
            switch (target)
            {
            case ResourceTarget.Default:
                audioImporter.defaultSampleSettings = settings;
                break;

            case ResourceTarget.Android:
                audioImporter.SetOverrideSampleSettings("Android", settings);
                break;

            case ResourceTarget.IOS:
                audioImporter.SetOverrideSampleSettings("IOS", settings);
                break;
            }
            audioImporter.SaveAndReimport();
        }
    public override void OnInspectorGUI()
    {
        if (source == null)
        {
            return;
        }
        #region ClipType handler
        ClipType clipType = script.clipType;
        clipType = (ClipType)EditorGUILayout.EnumPopup("Clip Type", clipType);
        if (clipType != script.clipType)
        {
            SoundManagerEditorTools.RegisterObjectChange("Change Clip Type", script);
            script.clipType = clipType;
            if (script.clipType != ClipType.AudioClip)
            {
                source.clip = null;
            }
            EditorUtility.SetDirty(script);
        }

        switch (script.clipType)
        {
        case ClipType.ClipFromSoundManager:
            string clipName = script.clipName;
            clipName = EditorGUILayout.TextField("Audio Clip Name", clipName);
            if (clipName != script.clipName)
            {
                SoundManagerEditorTools.RegisterObjectChange("Change Clip Name", script);
                script.clipName = clipName;
                EditorUtility.SetDirty(script);
            }
            break;

        case ClipType.ClipFromGroup:
            string groupName = script.groupName;
            groupName = EditorGUILayout.TextField("SFXGroup Name", groupName);
            if (groupName != script.groupName)
            {
                SoundManagerEditorTools.RegisterObjectChange("Change SFXGroup Name", script);
                script.groupName = groupName;
                EditorUtility.SetDirty(script);
            }
            break;

        case ClipType.AudioClip:
        default:
            AudioClip clip = source.clip;
            clip = EditorGUILayout.ObjectField("Audio Clip", clip, typeof(AudioClip), false) as AudioClip;
            if (clip != source.clip)
            {
                SoundManagerEditorTools.RegisterObjectChange("Change Audio Clip", script);
                source.clip = clip;
                EditorUtility.SetDirty(script);
            }
            if (source.clip != null)
            {
                AudioImporter importerInfo = AudioImporter.GetAtPath(AssetDatabase.GetAssetPath(source.clip)) as AudioImporter;
                EditorGUILayout.HelpBox("This is a " + (importerInfo.threeD ? "3D" : "2D") + " Sound.", MessageType.None, false);
            }
            break;
        }
        #endregion

        #region audio source settings
        EditorGUILayout.Space();
        source.mute          = EditorGUILayout.Toggle("Mute", source.mute);
        source.bypassEffects = EditorGUILayout.Toggle("Bypass Effects", source.bypassEffects);
        source.playOnAwake   = EditorGUILayout.Toggle("Play On Awake", source.playOnAwake);
        source.loop          = EditorGUILayout.Toggle("Loop", source.loop);
        EditorGUILayout.Space();
        source.priority = EditorGUILayout.IntSlider("Priority", source.priority, 0, 255);
        EditorGUILayout.Space();
        source.volume = EditorGUILayout.Slider("Volume", source.volume, 0f, 1f);
        source.pitch  = EditorGUILayout.Slider("Pitch", source.pitch, -3f, 3f);
        EditorGUILayout.Space();

        script.ShowEditor3D = EditorGUILayout.Foldout(script.ShowEditor3D, "3D Sound Settings");
        if (script.ShowEditor3D)
        {
            EditorGUI.indentLevel++;
            {
                source.dopplerLevel = EditorGUILayout.Slider("Doppler Level", source.dopplerLevel, 0f, 5f);
                EditorGUILayout.Space();
                AudioRolloffMode mode = source.rolloffMode;
                mode = (AudioRolloffMode)EditorGUILayout.EnumPopup("Volume Rolloff", mode);
                if (mode != AudioRolloffMode.Custom)
                {
                    source.rolloffMode = mode;
                    if (GUI.changed && notAvailable)
                    {
                        notAvailable = false;
                    }
                }
                else
                {
                    notAvailable = true;
                }

                if (notAvailable)
                {
                    GUI.color              = Color.red;
                    EditorGUI.indentLevel += 2;
                    {
                        EditorGUILayout.LabelField("Custom Volume Rolloff not available", EditorStyles.whiteLabel);
                    }
                    EditorGUI.indentLevel -= 2;
                    GUI.color              = Color.white;
                }
                EditorGUI.indentLevel++;
                {
                    float minD = source.minDistance;
                    minD = EditorGUILayout.FloatField("Min Distance", minD);
                    if (minD < 0f)
                    {
                        minD = 0f;
                    }
                    source.minDistance = minD;
                }
                EditorGUI.indentLevel--;
                source.panLevel = EditorGUILayout.Slider("Pan Level", source.panLevel, 0f, 1f);
                source.spread   = EditorGUILayout.Slider("Spread", source.spread, 0f, 360f);

                float maxD = source.maxDistance;
                maxD = EditorGUILayout.FloatField("Max Distance", maxD);
                if (maxD < source.minDistance + 3f)
                {
                    maxD = source.minDistance + 3f;
                }
                source.maxDistance = maxD;

                if (GUI.changed)
                {
                    CalculateCurve();
                }

                GUI.enabled = false;
                EditorGUILayout.BeginHorizontal();
                {
                    curve       = EditorGUILayout.CurveField(curve, Color.red, new Rect(0f, 0f, source.maxDistance, 1f), GUILayout.Height(100f), GUILayout.ExpandWidth(true));
                    panCurve    = EditorGUILayout.CurveField(panCurve, Color.green, new Rect(0f, 0f, source.maxDistance, 1f), GUILayout.Height(100f), GUILayout.ExpandWidth(true));
                    spreadCurve = EditorGUILayout.CurveField(spreadCurve, Color.blue, new Rect(0f, 0f, source.maxDistance, 360f), GUILayout.Height(100f), GUILayout.ExpandWidth(true));
                }
                EditorGUILayout.EndHorizontal();
                GUI.enabled = true;

                EditorGUILayout.BeginHorizontal();
                {
                    GUI.color = Color.red;
                    EditorGUILayout.LabelField("Volume", EditorStyles.whiteLabel, GUILayout.ExpandWidth(true));
                    GUI.color = Color.green;
                    EditorGUILayout.LabelField("Pan", EditorStyles.whiteLabel, GUILayout.ExpandWidth(true));
                    GUI.color = Color.blue;
                    EditorGUILayout.LabelField("Spread", EditorStyles.whiteLabel, GUILayout.ExpandWidth(true));
                    GUI.color = Color.white;
                }
                EditorGUILayout.EndHorizontal();
            }
            EditorGUI.indentLevel--;
        }
        EditorGUILayout.Space();
        script.ShowEditor2D = EditorGUILayout.Foldout(script.ShowEditor2D, "2D Sound Settings");
        if (script.ShowEditor2D)
        {
            EditorGUI.indentLevel++;
            {
                source.pan = EditorGUILayout.Slider("Pan 2D", source.pan, -1f, 1f);
                EditorGUILayout.Space();
            }
            EditorGUI.indentLevel--;
        }
        #endregion

        #region events
        EditorGUILayout.Space();
        script.ShowEventTriggers = EditorGUILayout.Foldout(script.ShowEventTriggers, "Event Trigger Settings");
        if (script.ShowEventTriggers)
        {
            for (int i = 0; i < script.numSubscriptions; i++)
            {
                EditorGUI.indentLevel++;
                {
                    EditorGUILayout.BeginVertical(EditorStyles.objectFieldThumb, GUILayout.ExpandWidth(true));
                    {
                        if (script.audioSubscriptions[i].sourceComponent == null)
                        {
                            EditorGUILayout.HelpBox("Drag a Component from THIS GameObject Below (Optional)", MessageType.None);
                        }

                        EditorGUILayout.BeginHorizontal();
                        var sourceComponent = ComponentField("Component", script.audioSubscriptions[i].sourceComponent);
                        if (GUILayout.Button("Clear"))
                        {
                            sourceComponent = null;
                        }
                        GUI.color = Color.red;
                        if (GUILayout.Button("Remove"))
                        {
                            RemoveEvent(i);
                            return;
                        }
                        GUI.color = Color.white;
                        if (sourceComponent != script.audioSubscriptions[i].sourceComponent)
                        {
                            SoundManagerEditorTools.RegisterObjectChange("Change Event Component", script);
                            script.audioSubscriptions[i].sourceComponent = sourceComponent;
                            EditorUtility.SetDirty(script);
                        }
                        EditorGUILayout.EndHorizontal();

                        int skippedStandardEvents = 0;

                        List <string> sourceComponentMembers = new List <string>();
                        if (sourceComponent != null)
                        {
                            sourceComponentMembers =
                                sourceComponent.GetType()
                                .GetEvents(BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance)
                                .Where(f => f.EventHandlerType.GetMethod("Invoke").GetParameters().Length == 0 && f.EventHandlerType.GetMethod("Invoke").ReturnType == typeof(void) && !IsAlreadyBound(f.Name, i))
                                .Select(m => m.Name).ToList();
                        }

                        AudioSourceStandardEvent[] standardEvents = Enum.GetValues(typeof(AudioSourceStandardEvent)).Cast <AudioSourceStandardEvent>().ToArray();
                        foreach (AudioSourceStandardEvent standardEvent in standardEvents)
                        {
                            if (!IsAlreadyBound(standardEvent.ToString(), i))
                            {
                                sourceComponentMembers.Add(standardEvent.ToString());
                            }
                            else
                            {
                                skippedStandardEvents++;
                            }
                        }
                        sourceComponentMembers.Add(nullEvent);

                        int numStandardEvents = standardEvents.Length - skippedStandardEvents;

                        string[] sourceComponentMembersArray = sourceComponentMembers.ToArray();
                        var      memberIndex = findIndex(sourceComponentMembersArray, script.audioSubscriptions[i].methodName);

                        if (memberIndex == -1)
                        {
                            memberIndex = sourceComponentMembers.Count - 1;
                            script.audioSubscriptions[i].methodName = "";
                        }

                        var selectedIndex = EditorGUILayout.Popup("Compatible Events", memberIndex, sourceComponentMembersArray);
                        if (selectedIndex >= 0 && selectedIndex < sourceComponentMembersArray.Length)
                        {
                            var memberName = sourceComponentMembersArray[selectedIndex];
                            if (memberName != script.audioSubscriptions[i].methodName)
                            {
                                SoundManagerEditorTools.RegisterObjectChange("Change Event", script);
                                script.audioSubscriptions[i].methodName = memberName;
                                EditorUtility.SetDirty(script);
                            }
                        }
                        if (selectedIndex == sourceComponentMembersArray.Length - 1)
                        {
                            EditorGUILayout.HelpBox("No event configuration selected.", MessageType.None);
                        }
                        else if (selectedIndex < sourceComponentMembersArray.Length - numStandardEvents - 1 && !script.audioSubscriptions[i].componentIsValid)
                        {
#if !(UNITY_WP8 || UNITY_METRO)
                            EditorGUILayout.HelpBox("Configuration is invalid.", MessageType.Error);
#else
                            EditorGUILayout.HelpBox("Configuration is invalid. Keep in mind that custom event configurations are not supported in the Win8Phone and WinStore platforms.", MessageType.Error);
#endif
                        }
                        else
                        {
                            if (selectedIndex + numStandardEvents < sourceComponentMembersArray.Length - 1)
                            {
                                if (script.audioSubscriptions[i].isStandardEvent)
                                {
                                    script.BindStandardEvent(script.audioSubscriptions[i].standardEvent, false);
                                }
                                script.audioSubscriptions[i].isStandardEvent = false;
                            }
                            else
                            {
                                script.audioSubscriptions[i].isStandardEvent = true;
                                script.audioSubscriptions[i].standardEvent   = (AudioSourceStandardEvent)Enum.Parse(typeof(AudioSourceStandardEvent), sourceComponentMembersArray[selectedIndex]);
                                script.BindStandardEvent(script.audioSubscriptions[i].standardEvent, true);

                                if (IsColliderEvent(script.audioSubscriptions[i].standardEvent))
                                {
                                    EditorGUI.indentLevel += 2;
                                    {
                                        //tags
                                        EditorGUILayout.BeginHorizontal();

                                        bool filterTags = script.audioSubscriptions[i].filterTags;
                                        filterTags = EditorGUILayout.Toggle(filterTags, GUILayout.Width(40f));
                                        if (filterTags != script.audioSubscriptions[i].filterTags)
                                        {
                                            SoundManagerEditorTools.RegisterObjectChange("Filter Tags", script);
                                            script.audioSubscriptions[i].filterTags = filterTags;
                                            EditorUtility.SetDirty(script);
                                        }
                                        EditorGUILayout.LabelField("Filter Tags:", GUILayout.Width(110f));

                                        GUI.enabled = filterTags;
                                        int tagMask = script.audioSubscriptions[i].tagMask;
                                        tagMask = EditorGUILayout.MaskField(tagMask, UnityEditorInternal.InternalEditorUtility.tags, GUILayout.ExpandWidth(true));
                                        if (tagMask != script.audioSubscriptions[i].tagMask)
                                        {
                                            SoundManagerEditorTools.RegisterObjectChange("Change Tag Filter", script);
                                            script.audioSubscriptions[i].tagMask = tagMask;
                                            script.audioSubscriptions[i].tags.Clear();
                                            for (int t = 0; t < UnityEditorInternal.InternalEditorUtility.tags.Length; t++)
                                            {
                                                if ((tagMask & 1 << t) != 0)
                                                {
                                                    script.audioSubscriptions[i].tags.Add(UnityEditorInternal.InternalEditorUtility.tags[t]);
                                                }
                                            }
                                            EditorUtility.SetDirty(script);
                                        }
                                        GUI.enabled = true;

                                        EditorGUILayout.EndHorizontal();


                                        //layers
                                        EditorGUILayout.BeginHorizontal();

                                        bool filterLayers = script.audioSubscriptions[i].filterLayers;
                                        filterLayers = EditorGUILayout.Toggle(filterLayers, GUILayout.Width(40f));
                                        if (filterLayers != script.audioSubscriptions[i].filterLayers)
                                        {
                                            SoundManagerEditorTools.RegisterObjectChange("Filter Layers", script);
                                            script.audioSubscriptions[i].filterLayers = filterLayers;
                                            EditorUtility.SetDirty(script);
                                        }
                                        EditorGUILayout.LabelField("Filter Layers:", GUILayout.Width(110f));

                                        GUI.enabled = filterLayers;
                                        int layerMask = script.audioSubscriptions[i].layerMask;
                                        layerMask = EditorGUILayout.LayerField(layerMask, GUILayout.ExpandWidth(true));
                                        if (layerMask != script.audioSubscriptions[i].layerMask)
                                        {
                                            SoundManagerEditorTools.RegisterObjectChange("Change Layer Filter", script);
                                            script.audioSubscriptions[i].layerMask = layerMask;
                                            EditorUtility.SetDirty(script);
                                        }
                                        GUI.enabled = true;

                                        EditorGUILayout.EndHorizontal();


                                        //names
                                        EditorGUILayout.BeginHorizontal();

                                        bool filterNames = script.audioSubscriptions[i].filterNames;
                                        filterNames = EditorGUILayout.Toggle(filterNames, GUILayout.Width(40f));
                                        if (filterNames != script.audioSubscriptions[i].filterNames)
                                        {
                                            SoundManagerEditorTools.RegisterObjectChange("Filter Names", script);
                                            script.audioSubscriptions[i].filterNames = filterNames;
                                            EditorUtility.SetDirty(script);
                                        }

                                        EditorGUILayout.LabelField("Filter Names:", GUILayout.Width(110f));

                                        GUI.enabled = filterNames;
                                        int nameMask = script.audioSubscriptions[i].nameMask;
                                        nameMask = EditorGUILayout.MaskField(nameMask, script.audioSubscriptions[i].allNames.ToArray(), GUILayout.ExpandWidth(true));
                                        if (nameMask != script.audioSubscriptions[i].nameMask)
                                        {
                                            SoundManagerEditorTools.RegisterObjectChange("Change Name Filter", script);
                                            script.audioSubscriptions[i].nameMask = nameMask;
                                            script.audioSubscriptions[i].names.Clear();
                                            for (int n = 0; n < script.audioSubscriptions[i].allNames.Count; n++)
                                            {
                                                if ((nameMask & 1 << n) != 0)
                                                {
                                                    script.audioSubscriptions[i].names.Add(script.audioSubscriptions[i].allNames[n]);
                                                }
                                            }
                                            EditorUtility.SetDirty(script);
                                        }
                                        GUI.enabled = true;

                                        EditorGUILayout.EndHorizontal();

                                        if (filterNames)
                                        {
                                            EditorGUI.indentLevel += 2;
                                            {
                                                EditorGUILayout.BeginHorizontal();

                                                script.audioSubscriptions[i].nameToAdd = EditorGUILayout.TextField(script.audioSubscriptions[i].nameToAdd);
                                                if (GUILayout.Button("Add Name"))
                                                {
                                                    if (!string.IsNullOrEmpty(script.audioSubscriptions[i].nameToAdd) && !script.audioSubscriptions[i].names.Contains(script.audioSubscriptions[i].nameToAdd))
                                                    {
                                                        SoundManagerEditorTools.RegisterObjectChange("Add Name Filter", script);
                                                        script.audioSubscriptions[i].allNames.Add(script.audioSubscriptions[i].nameToAdd);
                                                        script.audioSubscriptions[i].nameToAdd = "";
                                                        GUIUtility.keyboardControl             = 0;
                                                        EditorUtility.SetDirty(script);
                                                    }
                                                }
                                                if (GUILayout.Button("Clear Names"))
                                                {
                                                    SoundManagerEditorTools.RegisterObjectChange("Clear Name Filter", script);
                                                    script.audioSubscriptions[i].allNames.Clear();
                                                    script.audioSubscriptions[i].names.Clear();
                                                    EditorUtility.SetDirty(script);
                                                }
                                                EditorGUILayout.EndHorizontal();
                                            }
                                            EditorGUI.indentLevel -= 2;
                                        }
                                    }
                                    EditorGUI.indentLevel -= 2;
                                }
                            }
                            if (sourceComponent != null && sourceComponentMembersArray.Length - numStandardEvents == 1)
                            {
                                EditorGUILayout.HelpBox("There are no compatible custom events on this Component. Only void parameterless events are allowed.", MessageType.None);
                            }
                            AudioSourceAction actionType = script.audioSubscriptions[i].actionType;
                            actionType = (AudioSourceAction)EditorGUILayout.EnumPopup("AudioSource Action", actionType);
                            if (actionType != script.audioSubscriptions[i].actionType)
                            {
                                SoundManagerEditorTools.RegisterObjectChange("Change AudioSource Action", script);
                                script.audioSubscriptions[i].actionType = actionType;
                                EditorUtility.SetDirty(script);
                            }
                            if (actionType == AudioSourceAction.PlayCapped)
                            {
                                string cappedName = script.audioSubscriptions[i].cappedName;
                                cappedName = EditorGUILayout.TextField("Cap ID", cappedName);
                                if (cappedName != script.audioSubscriptions[i].cappedName)
                                {
                                    SoundManagerEditorTools.RegisterObjectChange("Change Cap ID", script);
                                    script.audioSubscriptions[i].cappedName = cappedName;
                                    EditorUtility.SetDirty(script);
                                }
                            }
                        }
                    }
                    EditorGUILayout.EndVertical();
                }
                EditorGUI.indentLevel--;
            }

            EditorGUILayout.BeginHorizontal();
            {
                GUILayout.FlexibleSpace();
                if (GUILayout.Button("Add Event Trigger"))
                {
                    AddEvent();
                }
                GUILayout.FlexibleSpace();
            }
            EditorGUILayout.EndHorizontal();
        }
        #endregion
    }
Beispiel #24
0
        private void LoadFile(string fsFilePath)
        {
            try
            {
                string sourceFileName = Path.GetFileName(fsFilePath);
                string destAssetPath  = Path.Combine(TempRelativeFolderPath, sourceFileName);

                if (!sourceFileName.Contains(TempRelativeFolderPath))
                {
                    destAssetPath = GeneratePath(TempRelativeFolderPath, sourceFileName);

                    if (string.IsNullOrEmpty(destAssetPath))
                    {
                        throw new ApplicationException("Can't locate audio path. ");
                    }

                    string destFsFilePath = Path.Combine(rootProjectFolder, destAssetPath);

                    soundManager.SetState(StateId.CopyToTempFolderInProgress, "Copy file from " + fsFilePath + " to " + destFsFilePath);

                    try
                    {
                        if (File.Exists(destFsFilePath))
                        {
                            File.Delete(destFsFilePath);
                        }
                        File.Copy(fsFilePath, destFsFilePath);
                    }
                    catch (UnityException exp)
                    {
                        Debug.LogError(exp.Message);
                    }
#if UNITY_EDITOR
                    AssetDatabase.ImportAsset(destAssetPath, ImportAssetOptions.ForceUncompressedImport);
                    AssetDatabase.SaveAssets();
                    AssetDatabase.Refresh();
#endif
                }


                audioImporter = AudioImporter.GetAtPath(destAssetPath) as AudioImporter;
                if (audioImporter == null)
                {
                    soundManager.SetState(StateId.Abort, "Aborted  as file " + destAssetPath + " has incompatible format");
                    return;
                }

                audioImporter.preloadAudioData = false;
                audioImporter.forceToMono      = false;
                audioImporter.loadInBackground = false;

                audioImporter.defaultSampleSettings = audioImporterSettings;
                soundManager.SetState(StateId.LoadingAudioData, "Import " + destAssetPath);

                audioImporter.SaveAndReimport();

#if UNITY_EDITOR
                audioClip = AssetDatabase.LoadAssetAtPath(destAssetPath, typeof(AudioClip)) as AudioClip;
#endif
                if (audioClip == null || !audioClip.LoadAudioData())
                {
                    soundManager.SetState(StateId.Abort, "Aborted: Can't load " + destAssetPath + " as audioclip");
                    return;
                }

                soundManager.audioClip     = audioClip;
                soundManager.audioImporter = audioImporter;
                soundManager.SetState(StateId.DataLoaded, "Loaded " + destAssetPath);
            }
            catch (UnityException exp)
            {
                Debug.LogError(exp.Message);
                throw;
            }
        }