Ejemplo n.º 1
0
    public static void PlayBg(string str, bool bLoop = true)
    {
        if (string.IsNullOrEmpty(str))
        {
            return;
        }
                #if true
        AudioClip clip = null;

        clip = Resources.Load("Sounds/" + str) as AudioClip;
        if (clip == null)
        {
            //if (Config.a.IsSoundDebug)
            Debug.LogError("Can't Find SoundClip = " + str);
        }

        if (bgMusic == null)
        {
            bgMusic           = soundObject.AddComponent <SoundBehaviour>();
            bgMusic.IsBgSound = true;
        }
        bgMusic.SetSound(
            clip,
            bLoop,
            Pitch,
            Sound.IsMute);
        bgMusic.Volume = 1f;
#else
        if (bAssetBundle)
        {
            AssetBundleManager.a.GetAssetAsync <AudioClip>("Sounds/" + str + ".mp3").completed += (a) => {
                AudioClip ac = ((AssetBundleRequest)a).asset as AudioClip;
                if (ac != null)
                {
                    AsyncPlay(ac, bLoop, true);
                }
                else
                {
                    AssetBundleManager.a.GetAssetAsync <AudioClip>("Sounds/" + str + ".wav").completed += (b) => {
                        ac = ((AssetBundleRequest)b).asset as AudioClip;
                        if (ac != null)
                        {
                            AsyncPlay(ac, bLoop, true);
                        }
                    };
                }
            };
        }
        else
        {
            Resources.LoadAsync <AudioClip>("Sounds/" + str).completed += (a) => {
                AudioClip ac = ((ResourceRequest)a).asset as AudioClip;
                if (ac != null)
                {
                    AsyncPlay(ac, bLoop, true);
                }
            };
        }
#endif
    }