コード例 #1
0
 public void PlayBgMusic(AudioClip clip, float voulume = 1, bool loop = true, SoundFadeState state = SoundFadeState.NONE)
 {
     if ((this.audioBg == null) && this.audioBg.mute)
     {
         return;
     }
     soundFadeState = SoundFadeState.NONE;
     if (clip == null || (this.audioBg == null))
     {
         C_DebugHelper.LogError("musicName :" + clip.name + "-Sound Clip Does Not Exists !");
     }
     else
     {
         audioBg.clip = clip;
         audioBg.loop = loop;
         audioBg.Play();
         if (state != SoundFadeState.NONE)
         {
             this.soundFadeState = state;
         }
         else
         {
             audioBg.volume = audioBgMusicVolumn;
         }
         audioBg.volume = voulume;
     }
 }
コード例 #2
0
    /// <summary>
    /// 播放背景音乐
    /// </summary>
    /// <param name="musicName"></param>
    /// <param name="isLocal"></param>
    /// <param name="loop"></param>
    public void PlayBgMusic(string musicName, bool isLocal = false, bool loop = true, SoundFadeState state = SoundFadeState.NONE)
    {
        if ((this.audioBg == null) && this.audioBg.mute)
        {
            return;
        }
        soundFadeState = SoundFadeState.NONE;
        string    name = musicName;
        AudioClip clip = C_Singleton <LocalAssetMgr> .Instance.Load_Music(name, isLocal);

        if (clip == null || (this.audioBg == null))
        {
            C_DebugHelper.LogError("musicName :" + musicName + "-Sound Clip Does Not Exists !");
        }
        else
        {
            audioBg.clip = clip;
            audioBg.loop = loop;
            audioBg.Play();

            if (state != SoundFadeState.NONE)
            {
                this.soundFadeState = state;
            }
            else
            {
                audioBg.volume = audioBgMusicVolumn;
            }
        }
    }
コード例 #3
0
    public void PlayFadeOutBgMusic(string musicName, bool isLocal = false, bool loop = true, float fadetime = 0f, float voulume = 0f)
    {
        _aliveBgMusic          = true;
        audioBgFadeTime        = fadetime;
        audioBgMusicFadeVolumn = voulume;

        //  PlayBgMusic(musicName, isLocal, loop, SoundFadeState.FADE_OUT);
        this.soundFadeState = SoundFadeState.FADE_OUT;
    }
コード例 #4
0
 void UpdateMusicFadeOut()
 {
     if (this.audioBg != null)
     {
         this.audioBg.volume = this.audioBgMusicVolumn * (1 - curSoundTime / audioBgFadeTime);
     }
     if (this.curSoundTime >= audioBgFadeTime)
     {
         this.soundFadeState = SoundFadeState.NONE;
         this.ClearFade();
     }
     else
     {
         this.curSoundTime += Time.deltaTime;
     }
 }
コード例 #5
0
 void UpdateMusicFadeIn()
 {
     if (this.audioBg != null)
     {
         audioBgMusicVolumn = this.audioBg.volume = audioBgMusicFadeVolumn * (curSoundTime / audioBgFadeTime);
     }
     //按照一定的时间减少
     if (this.curSoundTime >= audioBgFadeTime)
     {
         curSoundTime        = audioBgFadeTime;
         this.soundFadeState = SoundFadeState.NONE;
         this.ClearFade();
     }
     else
     {
         this.curSoundTime += Time.deltaTime;
     }
 }
コード例 #6
0
 void ClearFade()
 {
     curSoundTime    = 0;
     soundFadeState  = SoundFadeState.NONE;
     audioBgFadeTime = 0f;
 }