private void OnAudioManagerApplyMusicCue(On.AudioManager.orig_ApplyMusicCue orig, AudioManager self, MusicCue musicCue, float delayTime, float transitionTime, bool applySnapshot) { var changed = false; var infosFieldInfo = musicCue.GetType() .GetField("channelInfos", BindingFlags.NonPublic | BindingFlags.Instance); var infos = (MusicCue.MusicChannelInfo[])infosFieldInfo.GetValue(musicCue); foreach (var info in infos) { var audioFieldInfo = info.GetType().GetField("clip", BindingFlags.NonPublic | BindingFlags.Instance); var origAudio = (AudioClip)audioFieldInfo.GetValue(info); if (origAudio != null) { var possibleReplace = GetAudioClip(origAudio.name); if (possibleReplace != null) { // Change Audio Clip audioFieldInfo.SetValue(info, possibleReplace); changed = true; } } } if (changed) { infosFieldInfo.SetValue(musicCue, infos); } orig(self, musicCue, delayTime, transitionTime, applySnapshot); }
private void StartMusic() { MusicCue musicCue = ScriptableObject.CreateInstance <MusicCue>(); List <MusicCue.MusicChannelInfo> channelInfos = new List <MusicCue.MusicChannelInfo>(); MusicCue.MusicChannelInfo channelInfo = new MusicCue.MusicChannelInfo(); channelInfo.SetAttr("clip", CagneyCarnation.Music); channelInfos.Add(channelInfo); musicCue.SetAttr("channelInfos", channelInfos.ToArray()); GameManager.instance.AudioManager.ApplyMusicCue(musicCue, 0, 0, false); }
public static MusicSegment ParseMusicSegment(byte[] data) { using (var reader = new BinaryReader(new MemoryStream(data))) { var musicSegment = new MusicSegment(data.Length); musicSegment.Id = reader.ReadUInt32(); musicSegment.MidiBehavior = (MidiInteractiveMusicBehavior)reader.ReadByte(); musicSegment.Properties = reader.ReadAudioProperties(); musicSegment.ChildCount = reader.ReadUInt32(); musicSegment.ChildIds = new uint[musicSegment.ChildCount]; for (var i = 0; i < musicSegment.ChildCount; i++) { musicSegment.ChildIds[i] = reader.ReadUInt32(); } musicSegment.GridPeriodTime = reader.ReadDouble(); musicSegment.GridOffsetTime = reader.ReadDouble(); musicSegment.Tempo = reader.ReadSingle(); musicSegment.TimeSignatureUpper = reader.ReadByte(); musicSegment.TimeSignatureLower = reader.ReadByte(); musicSegment.Unknown = reader.ReadByte(); musicSegment.StingerCount = reader.ReadUInt32(); musicSegment.Stingers = new Stinger[musicSegment.StingerCount]; for (var i = 0; i < musicSegment.StingerCount; i++) { Stinger stinger = default; stinger.TriggerId = reader.ReadUInt32(); stinger.SegmentId = reader.ReadUInt32(); stinger.PlayAt = (StingerKeyPoint)reader.ReadUInt32(); stinger.CueId = reader.ReadUInt32(); stinger.DoNotRepeatIn = reader.ReadUInt32(); stinger.AllowPlayingInNextSegment = reader.ReadUInt32() == 1; musicSegment.Stingers[i] = stinger; } musicSegment.EndTrimOffset = reader.ReadDouble(); musicSegment.MusicCueCount = reader.ReadUInt32(); musicSegment.MusicCues = new MusicCue[musicSegment.MusicCueCount]; for (var i = 0; i < musicSegment.MusicCueCount; i++) { MusicCue musicCue = default; musicCue.Id = reader.ReadUInt32(); musicCue.Time = reader.ReadDouble(); musicCue.CustomNameLength = reader.ReadUInt32(); if (musicCue.CustomNameLength > 0) { musicCue.CustomName = String.Concat(reader.ReadChars((int)musicCue.CustomNameLength - 1)); reader.BaseStream.Position++; // Skip null byte } musicSegment.MusicCues[i] = musicCue; } return(musicSegment); } }
private void Load(SceneInfo sceneInfo, bool doTransition, Action beforeEnterScene = null) { // Make sure players are carried over if (PlayerManager.Instance != null) { foreach (PlayerComponent player in PlayerManager.Instance.Players) { DontDestroyOnLoad(player.gameObject); } } SceneInfo currentScene = CurrentScene; MusicCue nextMusic = sceneInfo.music; bool switchMusic = nextMusic != currentScene?.music; void BeforeEnterScene() { beforeEnterScene?.Invoke(); if (switchMusic) { AudioManager.PlayMusicSafe(nextMusic, MusicFadeType.LinearOutIn, transition.TransitionDuration / 2f); } // Reset time scale when loading a new scene Time.timeScale = 1f; } if (doTransition) { if (switchMusic) { AudioManager.StopMusicSafe(transition.TransitionDuration / 2f); } transition.Play(sceneInfo, BeforeEnterScene); } else { // FIXME: How do we fade here? if (switchMusic) { AudioManager.PlayMusicSafe(nextMusic, MusicFadeType.LinearOutIn, 0.4f, restart: true); } BeforeEnterScene(); sceneInfo.Load(); } }
public void PlayBGM(MusicCue musicCue) { switch (musicCue) { case MusicCue.Title: PlayTrackLooping(titleClip); break; case MusicCue.Map: PlayTrackLooping(mapClip); break; case MusicCue.GameplayWorld1: MusicClipPair musicClipPair = world1Clips[Mathf.FloorToInt(Random.value * world1Clips.Count)]; PlayTracksLooping(musicClipPair); break; default: Debug.LogError("No handling for music cue: " + musicCue); break; } }
static void AudioManager_ApplyMusicCue(On.AudioManager.orig_ApplyMusicCue orig, AudioManager self, MusicCue musicCue, float delayTime, float transitionTime, bool applySnapshot) { orig(self, musicCue, delayTime, transitionTime, applySnapshot); }
protected static void PlayBossMusic(UnityEngine.Audio.AudioMixerSnapshot mixerSnapshot, MusicCue musicCue) { //set the audio mixer snapshot if (mixerSnapshot != null) { mixerSnapshot.TransitionTo(1f); } // play the boss music music GameManager instance = GameManager.instance; instance.AudioManager.ApplyMusicCue(musicCue, 0f, 0f, false); }
private MusicCue.MusicChannelInfo MusicCueGetChannelInfo(On.MusicCue.orig_GetChannelInfo orig, MusicCue self, MusicChannels channels) { if (_musicObj.GetComponent <AudioController>() == null) { _musicObj.SetActive(true); _musicObj.transform.position = new Vector2(75f, 15f); _music = _musicObj.AddComponent <AudioSource>(); _music.clip = Doppelgänger.Audio["DoppelgangerMusic"]; _music.loop = true; _music.bypassReverbZones = _music.bypassEffects = true; _music.volume = 0f; _musicObj.AddComponent <AudioController>(); } return(orig(self, channels)); }