コード例 #1
0
    private IEnumerator SwapCoroutine(EMusicState track, bool fadeIn, bool startImmediate)
    {
        if (startImmediate)
        {
            myAudiosource.volume = 0;
        }
        while (myAudiosource.volume > 0)
        {
            myAudiosource.volume -= Time.deltaTime * fadeOutSpeed;
            yield return(null);
        }

        currentTrack = track;
        AssignClip();
        if (myAudiosource.clip != null)
        {
            myAudiosource.Play();
        }

        if (fadeIn)
        {
            while (myAudiosource.volume < maxVolume)
            {
                myAudiosource.volume += Time.deltaTime * fadeInSpeed;
                yield return(null);
            }
        }
        else
        {
            myAudiosource.volume = maxVolume;
        }
    }
コード例 #2
0
 public void SwapTrack(EMusicState track, bool fadeIn, bool startImmediate)
 {
     if (TrackSwapCoroutine != null)
     {
         StopCoroutine(TrackSwapCoroutine);
     }
     TrackSwapCoroutine = StartCoroutine(SwapCoroutine(track, fadeIn, startImmediate));
 }
コード例 #3
0
 private void Awake()
 {
     if (StaticMusicPlayer == null)
     {
         StaticMusicPlayer = this;
         DontDestroyOnLoad(this.gameObject);
         myAudiosource = GetComponent <AudioSource>();
         maxVolume     = myAudiosource.volume;
         currentTrack  = EMusicState.Menu;
         AssignClip();
         if (myAudiosource.clip != null)
         {
             myAudiosource.Play();
         }
     }
     else
     {
         Destroy(this.gameObject);
     }
 }