/// <summary> /// Internal method triggering the SteamLeaderboardsUI.OnEntryDataSet event with exception handling. Required to ensure code execution even if your code throws exceptions. /// </summary> public void InvokeOnEntryDataSet(LeaderboardsScoreEntry p_entryData, SteamLeaderboardsScoreEntryNode p_entryUI) { InvokeEventHandlerSafely(OnEntryDataSet, new SteamLeaderboardsScoreEntryNode.EntryDataSetEventArgs() { EntryData = p_entryData, EntryUI = p_entryUI }); }
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 + "'"); } } } }
private void OnDownloadedScores(LapinerTools.Steam.Data.LeaderboardsDownloadedScoresEventArgs p_leaderboardArgs) { foreach (LeaderboardsScoreEntry scoreEntry in p_leaderboardArgs.Scores) { if (scoreEntry.IsCurrentUserScore) { // save users score entry (will be used to see additional entry data) m_userScore = scoreEntry; break; } } }
protected virtual IEnumerator LoadAvatarTexture(LeaderboardsScoreEntry p_entry) { // if the user of this score has no avatar image set, then do nothing bool isAvatarLoaded = !SteamLeaderboardsMain.Instance.IsAvatarTextureSet(p_entry); while (!isAvatarLoaded) { if (m_avatarTexture != null) { Destroy(m_avatarTexture); } // Steam will load the avatar image asynchronously -> check if it is already loaded and repeat later if it is not yet available m_avatarTexture = SteamLeaderboardsMain.Instance.GetAvatarTexture(p_entry); if (m_avatarTexture != null) { isAvatarLoaded = true; if (m_image != null) // might have been destroyed in the meantime -> check again { m_image.texture = m_avatarTexture; } } yield return(new WaitForSeconds(0.35f)); } }
/// <summary> /// If Steam has already downloaded the user's avatar, then it will be returned as Texture2D. /// Otherwise, will return null if the user has no avatar image at all or the image is still loading. /// Will start the download of the user's avatar if Steam is not yet loading it. /// </summary> /// <returns>if Steam has already downloaded the user's avatar, then it will be returned as Texture2D; otherwise, will return null if the user has no avatar image at all or the image is still loading.</returns> /// <param name="p_scoreEntry">score entry of the user to look for.</param> public Texture2D GetAvatarTexture(LeaderboardsScoreEntry p_scoreEntry) { return(GetAvatarTexture(p_scoreEntry.SteamNative.m_steamIDUser)); }
/// <summary> /// Most users who didn't set their avatar have a question mark as their avatar texture. /// However, Steam allows to check if there is no texture set at all, which will probably never happen. /// </summary> /// <returns><c>true</c> if the user of the given score entry has a custom avatar image or uses the default question mark texture as avatar; otherwise, <c>false</c>.</returns> /// <param name="p_scoreEntry">score entry of the user to look for.</param> public bool IsAvatarTextureSet(LeaderboardsScoreEntry p_scoreEntry) { return(IsAvatarTextureSet(p_scoreEntry.SteamNative.m_steamIDUser)); }