У меня есть метод, который использует Gamespark Api для получения данных списка лидеров.
Я хочу вернуть эти данные в другой класс для просмотра и обновления префаба Unity.
Из моего класса лидеровЯ могу зациклить данные, но я запутался, какой тип возврата мне нужно использовать тот же код цикла из другого класса
public class LeaderboardManager : MonoBehaviour
{
public GSEnumerable<LeaderboardDataResponse._LeaderboardData> LeaderboardRequest (string leaderboard, int entryCount = 50, bool social = false)
{
GSEnumerable<LeaderboardDataResponse._LeaderboardData> data = null;
new LeaderboardDataRequest()
.SetLeaderboardShortCode(leaderboard)
.SetEntryCount(entryCount)
.SetSocial(social)
.Send((response) => {
if (!response.HasErrors)
{
Debug.Log("Found Leaderboard Data...");
foreach (LeaderboardDataResponse._LeaderboardData entry in response.Data)
{
int rank = (int)entry.Rank;
string playerName = entry.UserName;
string score = entry.JSONData["SCORE"].ToString();
Debug.Log("Rank:" + rank + " Name:" + playerName + " \n Score:" + score);
}
return response;
}
else
{
Debug.Log("Error Retrieving Leaderboard Data...");
return;
}
});
return data;
}
}
public class StartController : MonoBehaviour {
#region Variables
public string leaderboardName;
private GSEnumerable<LeaderboardDataResponse._LeaderboardData> leaderboardResults;
void Start () {
leaderboardResults = NetworkManager.Instance.leaderboard.LeaderboardRequest(leaderboardName, 10, true);
foreach (LeaderboardDataResponse._LeaderboardData entry in leaderboardResults.Data)
{
int rank = (int)entry.Rank;
string playerName = entry.UserName;
string score = entry.JSONData["SCORE"].ToString();
Debug.Log("Rank:" + rank + " Name:" + playerName + " \n Score:" + score);
}
}
Я получаю ошибку, что leaderboardResults.Data
в foreach в StartController
Класс `GSEnumerable не содержит определения данных и не имеет доступного расширения.
foreach
в LeaderboardManager
печатает нормально
Я пытался вернуть response.Data
как ArrayList
и я получаю сообщение об ошибке return data;
Anonymous function converted to void returning delegate cannot return value
public ArrayList LeaderboardRequest (string leaderboard, int entryCount = 50, bool social = false)
{
//GSEnumerable<LeaderboardDataResponse._LeaderboardData> data = null;
new LeaderboardDataRequest()
.SetLeaderboardShortCode(leaderboard)
.SetEntryCount(entryCount)
.SetSocial(social)
.Send((response) => {
if (!response.HasErrors)
{
Debug.Log("Found Leaderboard Data...");
foreach (LeaderboardDataResponse._LeaderboardData entry in response.Data)
{
int rank = (int)entry.Rank;
string playerName = entry.UserName;
string score = entry.JSONData["SCORE"].ToString();
Debug.Log("Rank:" + rank + " Name:" + playerName + " \n Score:" + score);
}
GSEnumerable<LeaderboardDataResponse._LeaderboardData> data = response.Data;
return data;
}
else
{
Debug.Log("Error Retrieving Leaderboard Data...");
return;
}
});
return null;
}