public void Initialize() { // ここのチェックは、開発中だけでいい #if UNITY_EDITOR if (BgmAudioSource == null) { Debug.Log("SerializeFieldResourceManager:BgmAudioSource error"); } if (SeAudioSource == null) { Debug.Log("SerializeFieldResourceManager:SeAudioSource error"); } #endif CurrentBgm = Enum.Bgm.None; BgmAudioUseIndex = 0; SeAudioUseIndex = 0; }
public void PlayBgm(Enum.Bgm bgm) { if (bgm == CurrentBgm) { return; } int currentIndex = BgmAudioUseIndex; BgmAudioUseIndex++; if (BgmAudioUseIndex >= BgmAudioSource.Length) { BgmAudioUseIndex = 0; } int nextIndex = BgmAudioUseIndex; AudioSource source = GetBgmAudioSource(nextIndex); source.clip = BgmAudioClipList[(int)bgm]; source.Play(); source.loop = true; CurrentBgm = bgm; float[] weights; if (BgmAudioUseIndex == 0) { weights = new float[2] { 1.0f, 0.0f }; } else { weights = new float[2] { 0.0f, 1.0f }; } SoundAudioMixer.TransitionToSnapshots(AudioMixerSnapshot_BgmCrossFade, weights, 1f); }