private void SceneManagerOnActiveSceneChanged(Scene oldScene, Scene newScene) { if (newScene.buildIndex == 1) { // Loaded menu scene System.Net.WebClient client = new System.Net.WebClient(); var menuSceneSetupData = Resources.FindObjectsOfTypeAll <MenuSceneSetupData>().FirstOrDefault(); if (menuSceneSetupData.sceneState == MenuSceneSetupData.SceneState.Results) { // Send result data var twitchResults = new TwitchSongResults { Action = "SongResults", Results = menuSceneSetupData.levelCompletionResults, Timestamp = (long)DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1)).TotalSeconds }; var p = new NameValueCollection(); p.Add("Action", "SongResults"); p.Add("Data", JsonConvert.SerializeObject(twitchResults)); p.Add("Timestamp", twitchResults.Timestamp.ToString()); client.UploadValuesAsync(new System.Uri("http://localhost:3000/gamedata"), "POST", p); } else { var twitchData = new TwitchSceneUpdate { Action = "Menu", Scene = menuSceneSetupData.sceneState, Timestamp = (long)DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1)).TotalSeconds }; var p = new NameValueCollection(); p.Add("Action", "SongResults"); p.Add("Data", JsonConvert.SerializeObject(twitchData)); p.Add("Timestamp", twitchData.Timestamp.ToString()); client.UploadValuesAsync(new System.Uri("http://localhost:3000/gamedata"), "POST", p); } } else if (newScene.buildIndex == 4) { // Loaded game playing scene _mainSetupData = Resources.FindObjectsOfTypeAll <MainGameSceneSetupData>().FirstOrDefault(); _gameStaticData = Resources.FindObjectsOfTypeAll <GameStaticData>().FirstOrDefault(); _scoreController = Resources.FindObjectsOfTypeAll <ScoreController>().FirstOrDefault(); if (_mainSetupData == null || _gameStaticData == null || _scoreController == null) { Console.WriteLine("Twitch Overlay: Cannot load game data."); return; } // Attach note event handlers _scoreController.noteWasCutEvent += HandleNoteWasCutEvent; _scoreController.noteWasMissedEvent += HandleNoteWasMissedEvent; var song = _gameStaticData.GetLevelData(_mainSetupData.levelId); var songData = song.GetDifficultyLevel(_mainSetupData.difficulty).songLevelData.songData; var twitchSongUpdate = new TwitchSongUpdate { Action = "PlayingSong", SongId = song.levelId, SongName = song.songName, SongSubName = song.songSubName, AuthorName = song.authorName, Difficulty = LevelStaticData.GetDifficultyName(_mainSetupData.difficulty), SongLength = song.GetDifficultyLevel(_mainSetupData.difficulty).audioClip.length, GameMode = GetGameplayModeName(_mainSetupData.gameplayMode), IsCustomSong = song.levelId.Contains('∎'), IsNoFail = _mainSetupData.gameplayOptions.noEnergy, IsMirror = _mainSetupData.gameplayOptions.mirror, NotesCount = songData.notesCount, ObstaclesCount = songData.obstaclesCount, BPM = songData.BeatsPerMinute, SongData = songData.SongLinesData, Timestamp = (long)DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1)).TotalSeconds }; try { var p = new NameValueCollection(); p.Add("Action", "PlayingSong"); p.Add("Data", JsonConvert.SerializeObject(twitchSongUpdate)); p.Add("Timestamp", twitchSongUpdate.Timestamp.ToString()); System.Net.WebClient client = new System.Net.WebClient(); client.UploadValuesAsync(new System.Uri("http://localhost:3000/gamedata"), "POST", p); } catch (Exception e) { var p = new NameValueCollection(); p.Add("state", "Error"); p.Add("Exception", e.ToString()); System.Net.WebClient client = new System.Net.WebClient(); client.UploadValuesAsync(new System.Uri("http://localhost:3000/gamedata"), "POST", p); } } }