public IEnumerator GetSongs(int page, string sortBy) { _songs.Clear(); _songListViewController.RefreshScreen(); UnityWebRequest www = UnityWebRequest.Get(String.Format("https://beatsaver.com/api.php?mode={0}&off={1}", sortBy, (page * _songListViewController._songsPerPage))); yield return(www.SendWebRequest()); if (www.isNetworkError || www.isHttpError) { log.Error(www.error); } else { try { string parse = "{\"songs\": " + www.downloadHandler.text.Replace("][", ",") + "}"; JSONNode node = JSON.Parse(parse); for (int i = 0; i < node["songs"].Count; i++) { _songs.Add(new Song(node["songs"][i])); } _loading = false; _songListViewController.RefreshScreen(); if (_selectedRow != -1 && _songs.Count > 0) { _songListViewController._songsTableView.SelectRow(Math.Min(_selectedRow, _songs.Count - 1)); ShowDetails(Math.Min(_selectedRow, _songs.Count - 1)); } _songListViewController._pageUpButton.interactable = (page == 0) ? false : true; _songListViewController._pageDownButton.interactable = (_songs.Count < _songListViewController._songsPerPage) ? false : true; } catch (Exception e) { log.Exception("EXCEPTION IN GET SONGS: " + e.Message + " | " + e.StackTrace); } } }
public IEnumerator GetSongs(int page, string sortBy) { _songs.Clear(); _songListViewController.RefreshScreen(); _loading = true; UnityWebRequest www = UnityWebRequest.Get(String.Format("https://beatsaver.com/api.php?mode={0}&off={1}", sortBy, (page * _songListViewController._songsPerPage))); www.timeout = 10; yield return(www.SendWebRequest()); if (www.isNetworkError || www.isHttpError) { log.Error(www.error); TextMeshProUGUI _errorText = ui.CreateText(rectTransform, String.Format("Request timed out"), new Vector2(0f, -48f)); _errorText.alignment = TextAlignmentOptions.Center; Destroy(_errorText.gameObject, 2f); } else { try { string parse = "{\"songs\": " + www.downloadHandler.text + "}"; JSONNode node = JSON.Parse(parse); for (int i = 0; i < node["songs"].Count; i++) { _songs.Add(new Song(node["songs"][i])); } _songListViewController.RefreshScreen(); if (_selectedRow != -1 && _songs.Count > 0) { _songListViewController._songsTableView.SelectRow(Math.Min(_selectedRow, _songs.Count - 1)); ShowDetails(Math.Min(_selectedRow, _songs.Count - 1)); } _songListViewController._pageUpButton.interactable = (page == 0) ? false : true; _songListViewController._pageDownButton.interactable = (_songs.Count < _songListViewController._songsPerPage) ? false : true; } catch (Exception e) { log.Exception("EXCEPTION(GET SONGS): " + e); } } _loading = false; }