internal static async Task <List <Tuple <LeaderboardEntry_t, int[]> > > GetLeaderboardEntriesForUsers(string leaderboardName, CSteamID[] steamIds, int timeout = 10000, Func <List <Tuple <LeaderboardEntry_t, int[]> >, bool> resultHandler = null, Func <bool> repeatHandler = null) { var resultLeaderboard = await GetLeaderboard(leaderboardName); return(await TaskHelper.RepeatTaskForeverIfFailed(() => SteamApiHelper.HandleApiCall <List <Tuple <LeaderboardEntry_t, int[]> >, LeaderboardScoresDownloaded_t>(SteamUserStats.DownloadLeaderboardEntriesForUsers(resultLeaderboard.m_hSteamLeaderboard, steamIds, steamIds.Length), CancellationToken.None, (tcs, result, bIOFailure) => { if (result.m_hSteamLeaderboard.m_SteamLeaderboard == 0 || bIOFailure) { tcs.SetException(new Exception("Ошибка GetLeaderboardEntriesForUsers")); return; } var entriesList = new List <Tuple <LeaderboardEntry_t, int[]> >(); LeaderboardEntry_t entry; for (int index = 0; index < result.m_cEntryCount; index++) { int[] pData = new int[64]; if (SteamUserStats.GetDownloadedLeaderboardEntry(result.m_hSteamLeaderboardEntries, index, out entry, pData, 64)) { entriesList.Add(Tuple.Create(entry, pData)); } } tcs.SetResult(entriesList); }), timeout, CancellationToken.None, resultHandler : resultHandler, repeatHandler : repeatHandler)); }
internal static async Task <Tuple <LeaderboardEntry_t, int[]> > GetLeaderboardEntryWithDetails(string leaderboardName, int timeout = 10000, Func <Tuple <LeaderboardEntry_t, int[]>, bool> resultHandler = null, Func <bool> repeatHandler = null) { var resultLeaderboard = await GetLeaderboard(leaderboardName); return(await TaskHelper.RepeatTaskForeverIfFailed(() => SteamApiHelper.HandleApiCall <Tuple <LeaderboardEntry_t, int[]>, LeaderboardScoresDownloaded_t>(SteamUserStats.DownloadLeaderboardEntriesForUsers(resultLeaderboard.m_hSteamLeaderboard, new CSteamID[] { SteamUser.GetSteamID() }, 1), CancellationToken.None, (tcs, result, bIOFailure) => { if (result.m_hSteamLeaderboard.m_SteamLeaderboard == 0 || bIOFailure) { tcs.SetException(new Exception("Ошибка GetLeaderboardEntryWithDetails")); return; } int[] pData = null; if (result.m_cEntryCount > 0) { pData = new int[64]; } var entry = new LeaderboardEntry_t(); for (int index = 0; index < result.m_cEntryCount; index++) { SteamUserStats.GetDownloadedLeaderboardEntry(result.m_hSteamLeaderboardEntries, index, out entry, pData, 64); } tcs.SetResult(Tuple.Create(entry, pData)); }), timeout, CancellationToken.None, resultHandler : resultHandler, repeatHandler : repeatHandler)); }
private static void OnScoresDownloaded( LeaderboardScoresDownloaded_t scores, bool bIOFailure ) { if (!bIOFailure && scores.m_hSteamLeaderboardEntries.m_SteamLeaderboardEntries != 0) { readAction.Entries = new List <LeaderboardEntry>(scores.m_cEntryCount); LeaderboardEntry_t entry; for (int i = 0; i < scores.m_cEntryCount; i += 1) { SteamUserStats.GetDownloadedLeaderboardEntry( scores.m_hSteamLeaderboardEntries, i, out entry, null, 0 ); readAction.Entries.Add( new LeaderboardEntry( new LeaderboardGamer(entry.m_steamIDUser), entry.m_nScore, entry.m_nGlobalRank, readAction.Leaderboard ) ); } } readAction.IsCompleted = true; }
private void ParseLeaderboardData(LeaderboardScoresDownloaded_t steamData) { UnityEngine.Debug.Log("Steam ParseLeaderboardData"); List <OutrunLeaderboard.Entry> result = new List <OutrunLeaderboard.Entry> (); for (var i = 0; i < steamData.m_cEntryCount; i++) { LeaderboardEntry_t steamEntry; SteamUserStats.GetDownloadedLeaderboardEntry(steamData.m_hSteamLeaderboardEntries, i, out steamEntry, null, 0); OutrunLeaderboard.Entry resulEntry = new OutrunLeaderboard.Entry() { userId = steamEntry.m_steamIDUser.ToString() , userName = SteamFriends.GetFriendPersonaName(steamEntry.m_steamIDUser) , distance = steamEntry.m_nScore , rank = steamEntry.m_nGlobalRank , isMe = (steamEntry.m_steamIDUser == _playerId) }; result.Add(resulEntry); } if (OnLeaderboardData != null) { OnLeaderboardData(result); } }
private void DoPageDown( LeaderboardScoresDownloaded_t scores, bool bioFailure ) { if (scores.m_hSteamLeaderboardEntries.m_SteamLeaderboardEntries != 0) { LeaderboardEntry_t entry; for (int i = 0; i < scores.m_cEntryCount; i += 1) { SteamUserStats.GetDownloadedLeaderboardEntry( scores.m_hSteamLeaderboardEntries, i, out entry, null, 0 ); entryCache.Add( new LeaderboardEntry( new LeaderboardGamer(entry.m_steamIDUser), entry.m_nScore, entry.m_nGlobalRank, readAction.Leaderboard ) ); } } readAction.IsCompleted = true; }
void OnDownloadScore(LeaderboardScoresDownloaded_t callback, bool ioFailure) { if (!ioFailure) { int leaderBoardEntryAmount = Mathf.Min(callback.m_cEntryCount, leaderBoardEntryMax); Debug.Log("Downloaded " + leaderBoardEntryAmount + " Scores:"); if (leaderBoardEntryAmount <= 0) { Debug.Log("Retrying Download as user without score..."); DownloadScores(true); return; } loadedScores = new SteamScoreEntry[leaderBoardEntryAmount]; LeaderboardEntry_t currentEntry; for (int i = 0; i < leaderBoardEntryAmount; i++) { SteamUserStats.GetDownloadedLeaderboardEntry(callback.m_hSteamLeaderboardEntries, i, out currentEntry, null, 0); loadedScores[i] = new SteamScoreEntry(currentEntry.m_steamIDUser, currentEntry.m_nGlobalRank, 1 / ((float)currentEntry.m_nScore / scoreMultiplier)); } } else { Debug.LogWarning("Failure to download scores"); } downloadInProgress = false; }
/// <summary> /// This method makes use of the entries that the method "DownloadLeaderboardEntries" got /// </summary> public static void UseDownloadedEntries() { leaderboardPlayersList.Clear(); for (int i = 0; i < m_leaderboardCount; i++) { LeaderboardEntry_t _LeaderboardEntry; Sprite _playerImage; //Returns the entry from "m_leaderboardEntries" using the method GetDownloadedLeaderboardEntry, modifying the variable _leaderboardEntry using the modifier out bool ret = SteamUserStats.GetDownloadedLeaderboardEntry(m_leaderboardEntries, i, out _LeaderboardEntry, null, 0); Debug.Log("Score: " + _LeaderboardEntry.m_nScore + " User ID: " + SteamFriends.GetFriendPersonaName(_LeaderboardEntry.m_steamIDUser)); //The sprite image is generated on the FetchAvatar method, we pass the user that is on the current leaderboard entry _playerImage = FetchAvatar(_LeaderboardEntry.m_steamIDUser); if (!_playerImage) { _playerImage = FetchAvatar(_LeaderboardEntry.m_steamIDUser); } /*--------------------------------------------------------------------------------------- * We insert into the LeaderboardPlayers list a new leaderboardCell that is composed by: * public Sprite playerImage; * public string playerName * public int playerScore * This list will be used in conjuction with the list of The cells prefab list, using this list as a reference * ---------------------------------------------------------------------------------------*/ leaderboardPlayersList.Insert(i, new LeaderboardCell(_playerImage, SteamFriends.GetFriendPersonaName(_LeaderboardEntry.m_steamIDUser), _LeaderboardEntry.m_nScore)); } }
private void DoPageUp( LeaderboardScoresDownloaded_t scores, bool bioFailure ) { if (scores.m_hSteamLeaderboardEntries.m_SteamLeaderboardEntries != 0) { LeaderboardEntry_t entry; for (int i = scores.m_cEntryCount - 1; i >= 0; i -= 1) { SteamUserStats.GetDownloadedLeaderboardEntry( scores.m_hSteamLeaderboardEntries, i, out entry, null, 0 ); entryCache.Insert( 0, new LeaderboardEntry( new LeaderboardGamer(entry.m_steamIDUser), entry.m_nScore, entry.m_nGlobalRank, readAction.Leaderboard ) ); } PageStart = PageStart + scores.m_cEntryCount - pageSize; } readAction.IsCompleted = true; }
private void OnLeaderBoardScoresDownloaded(LeaderboardScoresDownloaded_t param, bool bIOFailure) { List <LeaderBoardVars> results = new List <LeaderBoardVars>(); if (bIOFailure) { Debug.LogError("Error getting leader board entries"); } else { int count = param.m_cEntryCount; SteamLeaderboardEntries_t entries = param.m_hSteamLeaderboardEntries; for (int i = 0; i < count; i++) { LeaderboardEntry_t entry; int[] details = new int[MAX_DETAILS]; if (SteamUserStats.GetDownloadedLeaderboardEntry(entries, i, out entry, details, MAX_DETAILS)) { LeaderBoardVars leaderBoardVars = ExtractLeaderBoardVars(entry, details); results.Add(leaderBoardVars); } } results = SortEntries(results); } callbackAction(results, false); }
private void OnLeaderboardScoresDownloadedForUserList(LeaderboardScoresDownloaded_t itemResult, bool bIOFailure) { if (bIOFailure) { if (mEntriesCallBack != null) { mEntriesCallBack.GetEntriesForUserListFail(SteamLeaderboardFailEnum.GETLIST_FAIL); } return; } SteamLeaderboardEntries_t entriesData = itemResult.m_hSteamLeaderboardEntries; List <SteamLeaderboardEntryBean> listData = new List <SteamLeaderboardEntryBean>(); for (int i = 0; i < itemResult.m_cEntryCount; i++) { LeaderboardEntry_t entry_T; int[] detailsInt = new int[64]; SteamUserStats.GetDownloadedLeaderboardEntry(entriesData, i, out entry_T, detailsInt, 64); SteamLeaderboardEntryBean itemData = new SteamLeaderboardEntryBean { score = entry_T.m_nScore, rank = entry_T.m_nGlobalRank, steamID = entry_T.m_steamIDUser, details = detailsInt }; listData.Add(itemData); } if (mEntriesCallBack != null) { mEntriesCallBack.GetEntriesForUserListSuccess(itemResult.m_hSteamLeaderboard.m_SteamLeaderboard, listData); } }
/// <summary> /// 查询排行榜数据回调 /// </summary> /// <param name="pCallback"></param> /// <param name="bIOFailure"></param> void OnLeaderboardScoresDownloaded(LeaderboardScoresDownloaded_t pCallback, bool bIOFailure) { m_SteamLeaderboardEntries = pCallback.m_hSteamLeaderboardEntries; List <GetLeaderboardEntriesResult.LeaderboardEntries> listData = new List <GetLeaderboardEntriesResult.LeaderboardEntries>(); for (int i = 0; i < pCallback.m_cEntryCount; i++) { LeaderboardEntry_t entry_T; bool ret = SteamUserStats.GetDownloadedLeaderboardEntry(m_SteamLeaderboardEntries, i, out entry_T, null, 0); GetLeaderboardEntriesResult.LeaderboardEntries itemData = new GetLeaderboardEntriesResult.LeaderboardEntries(); itemData.score = entry_T.m_nScore; itemData.rank = entry_T.m_nGlobalRank; itemData.steamID = entry_T.m_steamIDUser.ToString(); listData.Add(itemData); } if (mFindDataType == 0) { OnLeaderboardEntriesFindResultCallBack.leaderboradEntriesFindResultForSelf(listData); } else if (mFindDataType == 1) { OnLeaderboardEntriesFindResultCallBack.leaderboradEntriesFindResultForAll(listData); } }
public int ReadDownloadedUserLeaderboardEntry() { Debug.Log("[LeaderBoard] reading your leaderboard entry"); LeaderboardEntry_t entry_T; SteamUserStats.GetDownloadedLeaderboardEntry(hSteamLeaderboardEntry, 0, out entry_T, pScoreDetails, cScoreDetailsCount); return(entry_T.m_nScore); }
void TestReDrawLeader() { //Нужно ли отрисовать? и получена ли таблица? if (NeedReDrawFriends && asuncSteam != null && asuncSteam.getterLeaderboardDownloadFriends) { NeedReDrawFriends = false; //Запрос начинает выполнение //Сперва очищаем табицу от предыдущего результата SumUserLoaded = 0; ScoreTabSteamID[] oldList = gameObject.GetComponentsInChildren <ScoreTabSteamID>(); if (oldList != null && oldList.Length > 0) { for (int num_now = 0; num_now < oldList.Length; num_now++) { if (oldList[num_now] != null) { Destroy(oldList[num_now].gameObject); } } } //Таблица очищена грузим новую if (PrefabScoreTabWorld != null) { //Перебираем все результаты for (int num_now = 0; num_now < asuncSteam.SteamleaderboardScoresDownloaded_Friends.m_cEntryCount; num_now++) { //Вытаскиваем позицию игрока LeaderboardEntry_t leaderboardEntry; int[] details = new int[5]; bool ok_load = SteamUserStats.GetDownloadedLeaderboardEntry(asuncSteam.SteamleaderboardScoresDownloaded_Friends.m_hSteamLeaderboardEntries, num_now, out leaderboardEntry, details, 5); if (ok_load) { SumUserLoaded++; //Создаем ячейку GameObject playerResultObj = Instantiate(PrefabScoreTabWorld, gameObject.transform); RectTransform rectTransform = playerResultObj.GetComponent <RectTransform>(); //Меняем позицию этого результата Vector3 positionNew = rectTransform.position; Vector2 pivotNew = rectTransform.pivot; pivotNew.y = SumUserLoaded; rectTransform.pivot = pivotNew; rectTransform.position = positionNew; ScoreTabSteamID scoreTabWorldSteamID = playerResultObj.GetComponent <ScoreTabSteamID>(); scoreTabWorldSteamID.inicializationSteamID(leaderboardEntry.m_steamIDUser); scoreTabWorldSteamID.setScore(leaderboardEntry.m_nScore); scoreTabWorldSteamID.setNum(SumUserLoaded); } } } } }
private void OnDownloadLeaderboardEntriesCallCompleted(string p_leaderboardName, LeaderboardScoresDownloaded_t p_callback, bool p_bIOFailure) { if (CheckAndLogResult <LeaderboardScoresDownloaded_t, LeaderboardsDownloadedScoresEventArgs>("OnDownloadLeaderboardEntriesCallCompleted", EResult.k_EResultOK, p_bIOFailure, "OnDownloadedScores", ref OnDownloadedScores)) { if (OnDownloadedScores != null) { lock (m_lock) { // get score list m_scores.Clear(); m_scoresMissingUserNames.Clear(); m_scoresLeaderboardName = p_leaderboardName; for (int i = 0; i < p_callback.m_cEntryCount; i++) { LeaderboardEntry_t entry; int[] details = new int[Mathf.Max(0, m_scoreDownloadDetailsLength)]; if (SteamUserStats.GetDownloadedLeaderboardEntry(p_callback.m_hSteamLeaderboardEntries, i, out entry, details, details.Length)) { if (SteamFriends.RequestUserInformation(entry.m_steamIDUser, true)) // request name only, avatars will be requested if needed with GetAvatarTexture { m_scoresMissingUserNames.Add(entry.m_steamIDUser); } int[] detailsDownloaded = new int[Mathf.Min(details.Length, entry.m_cDetails)]; System.Array.Copy(details, detailsDownloaded, detailsDownloaded.Length); string userName = SteamFriends.GetFriendPersonaName(entry.m_steamIDUser); ELeaderboardDisplayType scoreType = SteamUserStats.GetLeaderboardDisplayType(p_callback.m_hSteamLeaderboard); LeaderboardsScoreEntry parsedEntry = new LeaderboardsScoreEntry() { LeaderboardName = p_leaderboardName, UserName = userName, GlobalRank = entry.m_nGlobalRank, Score = entry.m_nScore, ScoreString = FormatScore(entry.m_nScore, scoreType), ScoreType = scoreType, DetailsAvailableLength = entry.m_cDetails, DetailsDownloaded = detailsDownloaded, IsCurrentUserScore = entry.m_steamIDUser == SteamUser.GetSteamID(), SteamNative = new LeaderboardsScoreEntry.SteamNativeData(p_callback.m_hSteamLeaderboard, entry.m_hUGC, entry.m_steamIDUser) }; m_scores.Add(parsedEntry); } } } // inform listeners if (m_scoresMissingUserNames.Count == 0) { InvokeEventHandlerSafely(OnDownloadedScores, new LeaderboardsDownloadedScoresEventArgs(p_leaderboardName, new List <LeaderboardsScoreEntry>(m_scores))); ClearSingleShotEventHandlers("OnDownloadedScores", ref OnDownloadedScores); } else if (IsDebugLogEnabled) { Debug.Log("OnDownloadLeaderboardEntriesCallCompleted: missing user names count: '" + m_scoresMissingUserNames.Count + "'"); } } } }
void OnLeaderboardScoresDownloaded(LeaderboardScoresDownloaded_t param, bool ioError) { // IF the score board has been destroyed if (bodyText == null) { return; } if (ioError) { // Handle score download failure Debug.Log("Fail"); return; } // If arcade mode make it so it says "points" instead of walls string wallsOrPoints = "Walls"; if (titleText.text.Contains("ARCADE MODE")) { wallsOrPoints = "Points"; } // You should probably check whether param.m_hSteamLeaderboard is // the one you want to handle. bool entryAdded = false; bodyText.text = ""; List <string> entries = new List <string>(); for (int i = 0; i < param.m_cEntryCount; ++i) { LeaderboardEntry_t entry; // I assume you don't store any details // Not sure if the array is required to be non-null if (SteamUserStats.GetDownloadedLeaderboardEntry(param.m_hSteamLeaderboardEntries, i, out entry, null, 0)) { entryAdded = true; string playerName = SteamFriends.GetFriendPersonaName(entry.m_steamIDUser); if (playerName.Length > 20) // Truncate Long names { string f = playerName.Substring(0, 15); playerName = f + "..." + playerName.Substring(playerName.Length - 3); } entries.Add(string.Format("Position {0} | {1} With {2} " + wallsOrPoints, entry.m_nGlobalRank, playerName, entry.m_nScore)); //entries.Add(string.Format("{0}: rank {1}, score {2}", playerName, entry.m_nGlobalRank, entry.m_nScore)); bodyText.text = bodyText.text + " " + entries[i] + "\n"; } } if (entryAdded == false) { bodyText.text = "Exercise to see where you land..."; } }
void TestReDrawTop() { if (NeewReDrawTop && asuncSteam != null && asuncSteam.getterLeaderboardDownloadTOP) { NeewReDrawTop = false; bool pl1_ok = false; bool pl2_ok = false; bool pl3_ok = false; for (int num_now = 0; num_now < asuncSteam.SteamleaderboardScoresDownloaded_TOP.m_cEntryCount; num_now++) { //Вытаскиваем позицию игрока LeaderboardEntry_t leaderboardEntry; int[] details = new int[5]; bool ok_load = SteamUserStats.GetDownloadedLeaderboardEntry(asuncSteam.SteamleaderboardScoresDownloaded_TOP.m_hSteamLeaderboardEntries, num_now, out leaderboardEntry, details, 5); if (ok_load) { if (leaderboardEntry.m_nGlobalRank == 1 && Pos1 != null) { Pos1.gameObject.SetActive(true); Pos1.SetPlayer(leaderboardEntry); pl1_ok = true; } if (leaderboardEntry.m_nGlobalRank == 2 && Pos2 != null) { Pos2.gameObject.SetActive(true); Pos2.SetPlayer(leaderboardEntry); pl2_ok = true; } if (leaderboardEntry.m_nGlobalRank == 3 && Pos3 != null) { Pos3.gameObject.SetActive(true); Pos3.SetPlayer(leaderboardEntry); pl3_ok = true; } } } if (!pl1_ok && Pos1 != null) { Pos1.gameObject.SetActive(false); } if (!pl2_ok && Pos2 != null) { Pos2.gameObject.SetActive(false); } if (!pl3_ok && Pos3 != null) { Pos3.gameObject.SetActive(false); } } }
LeaderboardEntry_t[] GetDownloadedEntries(SteamLeaderboardEntries_t entries, int count) { LeaderboardEntry_t[] e = new LeaderboardEntry_t[count]; for (int i = 0; i < count; i++) { LeaderboardEntry_t entry; SteamUserStats.GetDownloadedLeaderboardEntry(entries, i, out entry, new int[] { }, 0); e[i] = entry; } return(e); }
void DownloadResult(LeaderboardScoresDownloaded_t downResult, bool failure) { //Debug.Log("STEAM LEADERBOARDS: isfailure = " + failure + ") Num Entries = " + downResult.m_cEntryCount); List <LeaderboardElement> newList = new List <LeaderboardElement>(); LeaderboardEntry_t returnEntry; int[] details = new int[1]; int maxDetailElems = 1; //getting full leaderboard //downResult.m_cEntryCount for (int i = 0; i < 10; i++) { if (i < downResult.m_cEntryCount) { SteamUserStats.GetDownloadedLeaderboardEntry(downResult.m_hSteamLeaderboardEntries, i, out returnEntry, details, maxDetailElems); LeaderboardElement newElem; newElem.rank = returnEntry.m_nGlobalRank.ToString(); newElem.name = SteamFriends.GetFriendPersonaName(returnEntry.m_steamIDUser); newElem.score = returnEntry.m_nScore.ToString(); newList.Add(newElem); } else { LeaderboardElement newElm; newElm.rank = "NULL"; newElm.name = "NULL"; newElm.score = "NULL"; newList.Add(newElm); } } //store in the list we want switch (wantedType) { case (0): leaderboardElementsFriends = new List <LeaderboardElement>(newList); break; case (1): leaderboardElementsGlobalClose = new List <LeaderboardElement>(newList); break; case (2): leaderboardElementsGlobal = new List <LeaderboardElement>(newList); break; } //Debug.Log("Updated " + wantedType + " leaderboard"); }
public LeaderEntry[] ReadDownloadedTop100Entries() { Debug.Log("[LeaderBoard] reading top 100 entries"); LeaderEntry[] vals = new LeaderEntry[topEntriesCount]; for (int i = 0; i < topEntriesCount; i++) { LeaderboardEntry_t entry_T; SteamUserStats.GetDownloadedLeaderboardEntry(hSteamTop100Entries, i, out entry_T, pScoreDetails, cScoreDetailsCount); vals[i] = new LeaderEntry(entry_T.m_steamIDUser, entry_T.m_nGlobalRank, entry_T.m_nScore); } return(vals); }
void DownloadPersonalResult(LeaderboardScoresDownloaded_t downResult, bool failure) { LeaderboardEntry_t returnEntry; int[] details = new int[1]; int maxDetailElems = 1; //getting own score/rank/name SteamUserStats.GetDownloadedLeaderboardEntry(downResult.m_hSteamLeaderboardEntries, 0, out returnEntry, details, maxDetailElems); thisRank.text = returnEntry.m_nGlobalRank.ToString(); thisName.text = "YOU"; thisScore.text = returnEntry.m_nScore.ToString(); //Debug.Log("Updated personal leaderboard"); }
public void OnLeaderboardDownloadedEntries(LeaderboardScoresDownloaded_t pLeaderboardScoresDownloaded, bool bIOFailure) { if (!bIOFailure) { SteamStats.s_nLeaderboardEntriesFound = Math.Min(pLeaderboardScoresDownloaded.m_cEntryCount, 1000); for (int index = 0; index < SteamStats.s_nLeaderboardEntriesFound; index++) { SteamUserStats.GetDownloadedLeaderboardEntry( pLeaderboardScoresDownloaded.m_hSteamLeaderboardEntries, index, out SteamStats.m_leaderboardEntries[index], null, 0); } } SteamStats.s_OnDownload.Invoke(bIOFailure); }
IEnumerator _DownloadEntry(int _gameNo, int _diff, GetRankingType _type, Action <Ranking.Data[]> _success, Action _failure) { bool retFind = false; string leaderboard_name = LEADERBOARD_NANE[_gameNo]; // リーダーボード取得 SteamManager.Instance.Leaderboard.FindLeaderboard(leaderboard_name, (_find) => { switch (_type) { // ユーザー自身順位 case GetRankingType.USER_CURRENT: { CSteamID[] ids = { SteamUser.GetSteamID() }; SteamManager.Instance.Leaderboard.DownloadScoreUsers(ids, (_data) => { retFind = true; }); } break; // グローバル順位 case GetRankingType.GLOBAL: SteamManager.Instance.Leaderboard.DownloadScoreGlobal(GLOBAL_RANKING_START_NUM, GLOBAL_RANKING_GET_NUM, (_data) => { retFind = true; }); break; } }); while (!retFind) { // 取得待ち yield return(new WaitForEndOfFrame()); } ; Ranking.Data[] arrayRankingData = new Ranking.Data[SteamManager.Instance.Leaderboard.CurrentDownloadEntryCnt]; for (int i = 0; i < arrayRankingData.Length; ++i) { LeaderboardEntry_t leaderboardEntry; bool ret = SteamUserStats.GetDownloadedLeaderboardEntry(SteamManager.Instance.Leaderboard.SteamLeaderboardEntries, i, out leaderboardEntry, null, 0); if (ret) { arrayRankingData[i] = new Ranking.Data(leaderboardEntry.m_nGlobalRank, SteamFriends.GetFriendPersonaName(leaderboardEntry.m_steamIDUser), leaderboardEntry.m_nScore); } } if (_success != null) { _success(arrayRankingData); } }
private void OnLeaderboardDownloaded(LeaderboardScoresDownloaded_t param, bool bIOFailure) { if (bIOFailure) { Console.WriteLine("Something broke while downloading the leaderboard"); } else { done = true; Console.WriteLine("Leaderboard Downloaded!"); for (int i = 0; i < param.m_cEntryCount; i++) { LeaderboardEntry_t leaderboardEntry; int[] details = new int[10]; SteamUserStats.GetDownloadedLeaderboardEntry(param.m_hSteamLeaderboardEntries, i, out leaderboardEntry, details, 10); this.leaderboard.Add(new LeaderboardEntry(leaderboardEntry)); } } }
private void OnLeaderboardDownloadResult(LeaderboardScoresDownloaded_t pCallback, bool failure) { Debug.Log($"Steam Leaderboard Download: Did it fail? {failure}, Result - {pCallback.m_hSteamLeaderboardEntries}"); LeaderboardDataset = new List <LeaderboardData>(); //Iterates through each entry gathered in leaderboard for (int i = 0; i < pCallback.m_cEntryCount; i++) { LeaderboardEntry_t leaderboardEntry; SteamUserStats.GetDownloadedLeaderboardEntry(pCallback.m_hSteamLeaderboardEntries, i, out leaderboardEntry, null, 0); //Example of how leaderboardEntry might be held/used LeaderboardData lD; lD.username = SteamFriends.GetFriendPersonaName(leaderboardEntry.m_steamIDUser); lD.rank = leaderboardEntry.m_nGlobalRank; lD.score = leaderboardEntry.m_nScore; LeaderboardDataset.Add(lD); Debug.Log($"User: {lD.username} - Score: {lD.score} - Rank: {lD.rank}"); } //This is the callback for my own project - function is asynchronous so it must return from here rather than from GetLeaderBoardData FindObjectOfType <HighscoreUIMan>().FillLeaderboard(LeaderboardDataset); }
void OnLeaderboardDownloadResult(LeaderboardScoresDownloaded_t cb, bool IOFailure) { if (IOFailure) { print("<Steamworks> Error Downloading leaderboard scores"); } else { print("<Steamworks> Downloaded " + cb.m_cEntryCount + " scores"); for (int i = 0; i < cb.m_cEntryCount; i++) { LeaderboardEntry_t entry; bool ret = SteamUserStats.GetDownloadedLeaderboardEntry(cb.m_hSteamLeaderboardEntries, i, out entry, null, 0); leaderboardEntries.Add(new LeaderboardEntry { SteamId = entry.m_steamIDUser.m_SteamID, GlobalRank = entry.m_nGlobalRank, Score = entry.m_nScore }); } } }
private void OnLeaderboardScoresDownloaded(LeaderboardScoresDownloaded_t pCallback, bool bIOFailure) { LeaderboardScoreEntryArg arg = new LeaderboardScoreEntryArg("", -1, 0); if (pCallback.m_hSteamLeaderboard != null) { KeyValuePair <string, SteamLeaderboard_t?>?entry = leaderbordsStatus.Where(y => y.Value == pCallback.m_hSteamLeaderboard).FirstOrDefault(); if (entry != null) { arg.LeaderboardId = entry.Value.Key; } } if (!bIOFailure) { SteamLeaderboardEntries_t m_SteamLeaderboardEntries = pCallback.m_hSteamLeaderboardEntries; LeaderboardEntry_t LeaderboardEntry; bool ret = SteamUserStats.GetDownloadedLeaderboardEntry(m_SteamLeaderboardEntries, 0, out LeaderboardEntry, null, 0); if (ret) { arg.Rank = LeaderboardEntry.m_nGlobalRank; arg.Score = LeaderboardEntry.m_nScore; } else { arg.Rank = -1; } } else { arg.Rank = -1; } if (!string.IsNullOrEmpty(arg.LeaderboardId)) { RaiseGameServiceEvent(new GameServiceEvent(GameServiceEventType.LeaderboardScoreReady, arg)); } }
private void OnLeaderboardScoresDownloaded(LeaderboardScoresDownloaded_t pCallback, bool bIOFailure) { if (pCallback.m_hSteamLeaderboard == m_steamLeaderboard) { if (pCallback.m_cEntryCount > 0) { Debug.LogError("排行榜数据量:" + pCallback.m_cEntryCount); for (int i = 0; i < pCallback.m_cEntryCount; i++) { LeaderboardEntry_t leaderboardEntry; int[] details = new int[pCallback.m_cEntryCount]; SteamUserStats.GetDownloadedLeaderboardEntry(pCallback.m_hSteamLeaderboardEntries, i, out leaderboardEntry, details, pCallback.m_cEntryCount); Debug.LogError("用户ID:" + leaderboardEntry.m_steamIDUser + "用户分数" + leaderboardEntry.m_nScore + "用户排名" + leaderboardEntry.m_nGlobalRank + "Details" + leaderboardEntry.m_cDetails + " " + SteamFriends.GetFriendPersonaName(leaderboardEntry.m_steamIDUser)); gos[i].transform.FindChild("name").GetComponent <UILabel>().text = leaderboardEntry.m_nGlobalRank + " " + SteamFriends.GetFriendPersonaName(leaderboardEntry.m_steamIDUser); gos[i].transform.FindChild("score").GetComponent <UILabel>().text = leaderboardEntry.m_nScore + ""; } } else { Debug.LogError("排行榜数据为空!"); } } }
private void OnLeaderboardScoresDownloaded(LeaderboardScoresDownloaded_t pCallback, bool bIOFailure) { Debug.Log("[" + LeaderboardScoresDownloaded_t.k_iCallback + " - LeaderboardScoresDownloaded] - " + pCallback.m_hSteamLeaderboard + " -- " + pCallback.m_hSteamLeaderboardEntries + " -- " + pCallback.m_cEntryCount); for (int i = 0; i < pCallback.m_cEntryCount; i++) { LeaderboardEntry_t e; int[] additionalInfo = new int[4]; SteamUserStats.GetDownloadedLeaderboardEntry(pCallback.m_hSteamLeaderboardEntries, i, out e, additionalInfo, 4); SteamFriends.RequestUserInformation(e.m_steamIDUser, true); currDownloadedEntries[e.m_nGlobalRank - 1] = (new LeaderboardEntry("not loaded", e.m_steamIDUser, e.m_nGlobalRank, e.m_nScore, additionalInfo[0], additionalInfo[1], additionalInfo[2], additionalInfo[3])); } for (int i = 0; i < pCallback.m_cEntryCount; i++) { currDownloadedEntries[i].steamName = SteamFriends.GetFriendPersonaName(currDownloadedEntries[i].steamID); Debug.Log("entry " + i + " with name " + currDownloadedEntries[i].steamName + " and rank " + currDownloadedEntries[i].rank + " and score " + currDownloadedEntries[i].score + " retrieved"); } //SteamAPICall_t downloadHandle = SteamUserStats.DownloadLeaderboardEntriesForUsers(m_SteamLeaderboard, new CSteamID[] {steamID}, 1); //LeaderboardScoresDownloaded.Set(downloadHandle, OnOwnLeaderboardScoreDownloaded); currAction(currDownloadedEntries); }
private void DownloadResult(LeaderboardScoresDownloaded_t pCallback, bool bIOFailure) { if (!bIOFailure) { int n = Mathf.Min(pCallback.m_cEntryCount, maxEntries); LeaderboardEntry_t[] m_leaderboardEntries = new LeaderboardEntry_t[n]; entries = new LeaderboardEntrie[n]; for (int i = 0; i < n; i++) { SteamUserStats.GetDownloadedLeaderboardEntry(pCallback.m_hSteamLeaderboardEntries, i, out m_leaderboardEntries[i], null, 0); LeaderboardEntrie entrie = new LeaderboardEntrie(); entrie.name = SteamFriends.GetFriendPersonaName(m_leaderboardEntries[i].m_steamIDUser); entrie.score = m_leaderboardEntries[i].m_nScore; entrie.user = (SteamUser.GetSteamID().m_SteamID.Equals(m_leaderboardEntries[i].m_steamIDUser.m_SteamID)); entrie.pos = i; entries[i] = entrie; } onDownloaded.Invoke(entries); if (releaseMemory) { entries = null; } } }
public Promise <Leaderboard> DownloadLeaderboard(ulong id, LeaderboardType type, int maxEntries) { var result = new SimplePromise <Leaderboard>(); if (maxEntries > 0) { ELeaderboardDataRequest requestType; int rangeStart, rangeEnd; switch (type) { case LeaderboardType.Global: default: { requestType = ELeaderboardDataRequest.k_ELeaderboardDataRequestGlobal; rangeStart = 1; rangeEnd = maxEntries; break; } case LeaderboardType.Local: { requestType = ELeaderboardDataRequest.k_ELeaderboardDataRequestGlobalAroundUser; rangeStart = -(maxEntries / 2); rangeEnd = rangeStart + maxEntries - 1; break; } case LeaderboardType.Friends: { requestType = ELeaderboardDataRequest.k_ELeaderboardDataRequestFriends; rangeStart = 1; rangeEnd = maxEntries; break; } } MakeCall( SteamUserStats.DownloadLeaderboardEntries(new SteamLeaderboard_t(id), requestType, rangeStart, rangeEnd), delegate(LeaderboardScoresDownloaded_t args2, bool ioFailure2) { if (ioFailure2) { result.Fail("Failed to download leaderboard"); } else { var leaderboard = new Leaderboard(id, type); for (int i = 0; i < Math.Min(args2.m_cEntryCount, maxEntries); ++i) { LeaderboardEntry_t entry; if (SteamUserStats.GetDownloadedLeaderboardEntry(args2.m_hSteamLeaderboardEntries, i, out entry, null, 0)) { var rank = entry.m_nGlobalRank; var username = SteamFriends.GetFriendPersonaName(entry.m_steamIDUser); var score = entry.m_nScore; leaderboard.Entries.Add(new LeaderboardEntry(rank, username, score)); } } result.Succeed(leaderboard); } } ); } else { result.Succeed(new Leaderboard(id, type)); } return(result); }