public IEnumerator Start() { // The goal now is to find the clip this scene will be playing. // For this, we find the single root gameObject (which is the gameObject // to which we are attached), // then we get its GameSongController to find the audio clip, // and its FlyingTextSpawner to display the lyrics. if (Settings.VerboseLogging) { Debug.Log("[Beat Singer] Attached to scene."); Debug.Log($"[Beat Singer] Lyrics are enabled: {Settings.DisplayLyrics}."); } textSpawner = FindObjectOfType <FlyingTextSpawner>(); songController = FindObjectOfType <GameSongController>(); var sceneSetup = FindObjectOfType <GameplayCoreSceneSetup>(); if (songController == null || sceneSetup == null) { yield break; } if (textSpawner == null) { var installer = FindObjectOfType <EffectPoolsInstaller>(); var container = (Zenject.DiContainer)ContainerField.GetValue(installer); textSpawner = container.InstantiateComponentOnNewGameObject <FlyingTextSpawner>(); } var sceneSetupData = (GameplayCoreSceneSetupData)SceneSetupDataField.GetValue(sceneSetup); if (sceneSetupData == null) { yield break; } audio = (AudioTimeSyncController)AudioTimeSyncField.GetValue(songController); IBeatmapLevel level = sceneSetupData.difficultyBeatmap.level; List <Subtitle> subtitles = new List <Subtitle>(); Debug.Log($"[Beat Singer] Corresponding song data found: {level.songName} by {level.songAuthorName} ({(level.songSubName != null ? level.songSubName : "No sub-name")})."); if (LyricsFetcher.GetLocalLyrics(sceneSetupData.difficultyBeatmap.level.levelID, subtitles)) { Debug.Log("[Beat Singer] Found local lyrics."); Debug.Log($"[Beat Singer] These lyrics can be uploaded online using the ID: \"{level.GetLyricsHash()}\"."); // Lyrics found locally, continue with them. SpawnText("Lyrics found locally", 3f); } else { Debug.Log("[Beat Singer] Did not find local lyrics, trying online lyrics..."); // When this coroutine ends, it will call the given callback with a list // of all the subtitles we found, and allow us to react. // If no subs are found, the callback is not called. yield return(StartCoroutine(LyricsFetcher.GetOnlineLyrics(level, subtitles))); if (subtitles.Count != 0) { goto FoundOnlineLyrics; } yield return(StartCoroutine(LyricsFetcher.GetMusixmatchLyrics(level.songName, level.songAuthorName, subtitles))); if (subtitles.Count != 0) { goto FoundOnlineLyrics; } yield return(StartCoroutine(LyricsFetcher.GetMusixmatchLyrics(level.songName, level.songSubName, subtitles))); if (subtitles.Count != 0) { goto FoundOnlineLyrics; } yield break; FoundOnlineLyrics: SpawnText("Lyrics found online", 3f); } StartCoroutine(DisplayLyrics(subtitles)); }
public IEnumerator Start() { // The goal now is to find the clip this scene will be playing. // For this, we find the single root gameObject (which is the gameObject // to which we are attached), // then we get its GameSongController to find the audio clip, // and its FlyingTextSpawner to display the lyrics. if (Settings.VerboseLogging) { Debug.Log("[Beat Singer] Attached to scene."); Debug.Log($"[Beat Singer] Lyrics are enabled: {Settings.DisplayLyrics}."); } if (!Settings.DisplayLyrics) { yield break; } //Create a FlyingTextSpawner (Based on Custom Miss Text) var installer = Resources.FindObjectsOfTypeAll <EffectPoolsInstaller>().FirstOrDefault(); if (installer != null) { var containers = Resources.FindObjectsOfTypeAll <MonoInstallerBase>(); foreach (MonoInstallerBase a in containers) { if (textSpawner == null) { try { var container = a.GetProperty <DiContainer>("Container"); textSpawner = container.InstantiateComponentOnNewGameObject <FlyingTextSpawner>("CustomMissTextSpawner"); } catch (Exception ex) { Debug.Log("Exception creating TextSpawner"); } } } // .First().GetProperty<DiContainer>("Container"); // textSpawner = container.InstantiateComponentOnNewGameObject<FlyingTextSpawner>("CustomMissTextSpawner"); Debug.Log("Text Spawner Attempted"); } // songController = FindObjectOfType<GameSongController>(); var sceneSetup = BS_Utils.Plugin.LevelData; if (textSpawner == null) { Debug.Log("Null TextSpawner, breaking"); yield break; } //Set Text Spawner Properties (fontSize, Color, Shake) textSpawner.SetField("_fontSize", Settings.FontSize); textSpawner.SetField("_shake", Settings.Shake); textSpawner.SetField("_color", Settings.TextColor); audio = Resources.FindObjectsOfTypeAll <AudioTimeSyncController>().FirstOrDefault(); if (BS_Utils.Plugin.LevelData.GameplayCoreSceneSetupData.practiceSettings != null) { SpawnText("Practice Mode. \n" + "Ignoring Lyrics", 2f); yield break; } if (BS_Utils.Plugin.LevelData.GameplayCoreSceneSetupData.gameplayModifiers.songSpeedMul != 1f) { SpawnText("NonStandard Speed. \n" + "Ignoring Lyrics", 2f); yield break; } IBeatmapLevel level = sceneSetup.GameplayCoreSceneSetupData.difficultyBeatmap.level; List <Subtitle> subtitles = new List <Subtitle>(); Debug.Log($"[Beat Singer] Corresponding song data found: {level.songName} by {level.songAuthorName} / {level.songSubName}."); if (LyricsFetcher.GetLocalLyrics(sceneSetup.GameplayCoreSceneSetupData.difficultyBeatmap.level, subtitles)) { Debug.Log("[Beat Singer] Found local lyrics."); Debug.Log($"[Beat Singer] These lyrics can be uploaded online using the ID: \"{level.GetLyricsHash()}\"."); // Lyrics found locally, continue with them. SpawnText("Lyrics found locally", 3f); } else { Debug.Log("[Beat Singer] Did not find local lyrics, trying online lyrics..."); // When this coroutine ends, it will call the given callback with a list // of all the subtitles we found, and allow us to react. // If no subs are found, the callback is not called. yield return(StartCoroutine(LyricsFetcher.GetOnlineLyrics(level, subtitles))); if (subtitles.Count != 0) { goto FoundOnlineLyrics; } yield return(StartCoroutine(LyricsFetcher.GetMusixmatchLyrics(level.songName, level.songAuthorName, subtitles))); if (subtitles.Count != 0) { goto FoundOnlineLyrics; } yield return(StartCoroutine(LyricsFetcher.GetMusixmatchLyrics(level.songName, level.songSubName, subtitles))); if (subtitles.Count != 0) { goto FoundOnlineLyrics; } yield break; FoundOnlineLyrics: SpawnText("Lyrics found online", 3f); } StartCoroutine(DisplayLyrics(subtitles)); }