Esempio n. 1
0
    /// <summary>
    /// 特效声音的播放, 需要管理内存, 第三个参数支持循环播放声效
    /// </summary>
    /// <param name="fx">Fx.</param>
    public int SoundFxPlay(SoundFx fx, System.Action SoundFinished = null, bool loop = false)
    {
        int layer = -1;

        if (!bMute)
        {
            string fileName = getSoundFx(fx);
            if (string.IsNullOrEmpty(fileName))
            {
                ConsoleEx.DebugLog("Can't find Sound Effect. Sound Type = " + fx.ToString());
            }
            else
            {
                AudioClip clip = null;
                clip  = PrefabLoader.loadFromUnPack(AUDIO_ROOT_PATH + fileName, false, cached) as AudioClip;
                layer = Core.SoundEng.PlayClip(clip, AUDIO_EFFECT, loop);

                if (SoundFinished != null)
                {
                    AsyncTask.QueueOnMainThread(SoundFinished, clip.length);
                }

                mAudioLoader.RefAsset(AUDIO_ROOT_PATH + fileName);
            }
        }
        return(layer);
    }