public void CueMusic(MusicBase music) { if (musics.Contains(music)) { musics.Remove(music); } musics.Add(music); musics = musics.OrderBy(m => m.Priority).ToList(); if (musics.Count > maxMusicCount) { musics.RemoveAt(0); } var newMusic = musics.Last(); if (newMusic == current) { return; } var oldMusic = current; current = newMusic; if (oldMusic != null) { Tween.Tween01((v) => { oldMusic.Volume = 1f - v; }, Duration, () => { oldMusic.Stop(); newMusic.Volume = 1f; newMusic.Start(); }); } else { newMusic.Volume = 1f; newMusic.Start(); } }
public void CueEnd(MusicBase music) { if (!musics.Contains(music)) { return; } musics.Remove(music); var newMusic = musics.LastOrDefault(); if (newMusic == current) { return; } var oldMusic = current; current = newMusic; if (newMusic != null) { newMusic.Volume = 0f; newMusic.Resume(); } Tween.Tween01((v) => { oldMusic.Volume = 1f - v; if (newMusic != null) { newMusic.Volume = v; } }, Duration, () => { oldMusic.Stop(); if (newMusic != null) { newMusic.Volume = 1f; } }); }