void GetScores(ELeaderboardDataRequest requestType) { //set to which type we want switch (requestType) { case ELeaderboardDataRequest.k_ELeaderboardDataRequestGlobal: wantedType = 2; break; case ELeaderboardDataRequest.k_ELeaderboardDataRequestGlobalAroundUser: wantedType = 1; break; case ELeaderboardDataRequest.k_ELeaderboardDataRequestFriends: wantedType = 0; break; default: break; } if (wantedType == 2 || wantedType == 0) { SteamAPICall_t newApiCall = SteamUserStats.DownloadLeaderboardEntries(leaderboard_t, requestType, 1, 10); downloadResultLeaderboard.Set(newApiCall); } else { SteamAPICall_t newApiCall = SteamUserStats.DownloadLeaderboardEntries(leaderboard_t, requestType, -4, 5); downloadResultLeaderboard.Set(newApiCall); } }
private void Awake() { m_leaderboardName = leaderboardName; m_leaderboardEntriesRangeInit = leaderboardEntriesRangeinit; m_leaderboardEntriesRangeEnd = leaderboardEntriesRangeEnd; m_leaderboardPrefab = leaderboardPrefab; m_distanceBetweenCells = distanceBetweenCells; m_uploadScoreMethod = uploadScoreMethod; m_requestType = requestType; m_usingentriesFinished = false; }
/// <summary> /// Query for entries from this baord /// </summary> /// <param name="requestType"></param> /// <param name="rangeStart"></param> /// <param name="rangeEnd"></param> public void QueryEntries(ELeaderboardDataRequest requestType, int rangeStart, int rangeEnd) { if (!LeaderboardId.HasValue) { Debug.LogError(name + " Leaderboard Data Object, cannot download scores, the leaderboard has not been initalized and cannot download scores."); return; } var handle = SteamUserStats.DownloadLeaderboardEntries(LeaderboardId.Value, requestType, rangeStart, rangeEnd); OnLeaderboardScoresDownloadedCallResult.Set(handle, OnLeaderboardScoresDownloaded); }
/// <summary> /// Downloads the leaderboard for the filter criteria. The p_onDownloadedScores callback is invoked when done. /// First all score entries are fetched, then all user names are loaded if they are not yet cached by Steam. /// Avatars are loaded as soon as they are requested with SteamLeaderboardsMain.GetAvatarTexture. /// See also SteamLeaderboardsMain.OnDownloadedScores. /// </summary> /// <returns><c>true</c>, if a request was started, <c>false</c> when the request could not have been started due to an error.</returns> /// <param name="p_leaderboardName">name of the leaderboard to load.</param> /// <param name="p_scoreSource">source of the leaderboard entries (Global, AroundUser, Friends).</param> /// <param name="p_rangeStart">score entries range to load. For example, [0,10] for Global, [-4,5] for AroundUser.</param> /// <param name="p_rangeEnd">score entries range to load. For example, [0,10] for Global, [-4,5] for AroundUser.</param> /// <param name="p_onDownloadedScores">invoked when the leaderboard is either fully loaded or an error has occured.</param> public bool DownloadScores(string p_leaderboardName, ELeaderboardDataRequest p_scoreSource, int p_rangeStart, int p_rangeEnd, System.Action <LeaderboardsDownloadedScoresEventArgs> p_onDownloadedScores) { if (SteamManager.Initialized) { SetSingleShotEventHandler("OnDownloadedScores", ref OnDownloadedScores, p_onDownloadedScores); Execute <LeaderboardFindResult_t>(SteamUserStats.FindLeaderboard(p_leaderboardName), (p_callback, p_bIOFailure) => OnDownloadScoresFindLeaderboardCallCompleted(p_leaderboardName, p_scoreSource, p_rangeStart, p_rangeEnd, p_callback, p_bIOFailure)); return(true); // request started } else { ErrorEventArgs errorArgs = ErrorEventArgs.CreateSteamNotInit(); InvokeEventHandlerSafely(p_onDownloadedScores, new LeaderboardsDownloadedScoresEventArgs(errorArgs)); HandleError("DownloadScores: failed! ", errorArgs); return(false); // no request, because there is no connection to steam } }
//change ELeaderboardDataRequest to get a different set (focused around player or global) public void GetLeaderBoardData(ELeaderboardDataRequest _type = ELeaderboardDataRequest.k_ELeaderboardDataRequestGlobal, int entries = 10) { SteamAPICall_t hSteamAPICall; switch (_type) { case ELeaderboardDataRequest.k_ELeaderboardDataRequestGlobal: hSteamAPICall = SteamUserStats.DownloadLeaderboardEntries(s_currentLeaderboard, _type, 1, entries); m_downloadResult.Set(hSteamAPICall, OnLeaderboardDownloadResult); break; case ELeaderboardDataRequest.k_ELeaderboardDataRequestGlobalAroundUser: hSteamAPICall = SteamUserStats.DownloadLeaderboardEntries(s_currentLeaderboard, _type, -(entries / 2), (entries / 2)); m_downloadResult.Set(hSteamAPICall, OnLeaderboardDownloadResult); break; case ELeaderboardDataRequest.k_ELeaderboardDataRequestFriends: hSteamAPICall = SteamUserStats.DownloadLeaderboardEntries(s_currentLeaderboard, _type, 1, entries); m_downloadResult.Set(hSteamAPICall, OnLeaderboardDownloadResult); break; } //Note that the LeaderboardDataset will not be updated immediatly (see callback below) }
/// <summary> /// Get entries from the leaderboard /// </summary> /// <param name="requestType">type of data request, when downloading leaderboard entries</param> /// <param name="rangeStart">the result index to start at</param> /// <param name="rangeEnd">the result index to end at</param> public void QueryEntries(ELeaderboardDataRequest requestType, int rangeStart, int rangeEnd) { Settings.QueryEntries(requestType, rangeStart, rangeEnd); }
/*internal static GameNetworkState LoadUserState(CSteamID userId) * { * var presence = SteamFriends.GetFriendRichPresence(userId, SteamRichPresences.STATUS); * GameNetworkState status; * if (Enum.TryParse(presence, out status)) * return status; * * return GameNetworkState.Idleness; * }*/ /*internal static void UpdateUserInfo(ChatPlayerInfo info, CSteamID userId) * { * var state = SteamFriends.GetFriendPersonaState(userId); * * bool inGame = false; * * FriendGameInfo_t gameInfo; * if (SteamFriends.GetFriendGamePlayed(userId, out gameInfo)) * inGame = gameInfo.m_gameID.AppID().m_AppId == SteamUtils.GetAppID().m_AppId; * * info.AvatarData = LoadAvatarsData(userId); * info.Nickname = SteamFriends.GetFriendPersonaName(userId); * info.Peer = new SteamPeer(userId); * info.Rating = SteamFriends.GetFriendRichPresence(userId, SteamRichPresences.RATING).TryParseToInt(); * info.GamesWon = SteamFriends.GetFriendRichPresence(userId, SteamRichPresences.GAMES_WON).TryParseToInt(); * info.GamesLost = SteamFriends.GetFriendRichPresence(userId, SteamRichPresences.GAMES_LOST).TryParseToInt(); * info.Winrate = SteamFriends.GetFriendRichPresence(userId, SteamRichPresences.WINRATE).TryParseToInt(); * info.Online = state != EPersonaState.k_EPersonaStateOffline; * info.InGame = inGame; * info.IsUser = userId == SteamUser.GetSteamID(); * info.State = LoadUserState(userId); * //info.InternalStatus = LoadUserInternalStatus(userId); * info.Type = LoadUserType(userId); * info.RatingIcon = LoadUserRatingIcon(userId); * * }*/ /* internal static ChatPlayerInfo LoadUserInfo(CSteamID userId) * { * var info = new ChatPlayerInfo(); * UpdateUserInfo(info, userId); * return info; * } * * internal static UserAvatarData LoadAvatarsData(CSteamID userId) * { * var data = new UserAvatarData(); * * data.SmallIcon = LoadIcon(SteamFriends.GetSmallFriendAvatar(userId)); * data.MediumIcon = LoadIcon(SteamFriends.GetMediumFriendAvatar(userId)); * data.LargeIcon = LoadIcon(SteamFriends.GetLargeFriendAvatar(userId)); * * return data; * } * * private static AvatarIconData LoadIcon(int avatarId) * { * AvatarIconData data = new AvatarIconData(); * data.Id = avatarId; * * uint w, h; * if (avatarId > 0 && SteamUtils.GetImageSize(avatarId, out w, out h)) * { * var bytesCount = w * h * 4; * var bytes = new byte[bytesCount]; * data.Width = (int)w; * data.Height = (int)h; * * if (SteamUtils.GetImageRGBA(avatarId, bytes, (int)bytesCount)) * { * data.Bytes = bytes; * } * } * * return data; * }*/ /* internal static ChatPlayerType LoadUserType(CSteamID userId) * { * return ChatPlayerType.Simple; * } * * internal static RatingIconType LoadUserRatingIcon(CSteamID userId) * { * return (RatingIconType)SteamFriends.GetFriendRichPresence(userId, SteamRichPresences.RATING_ICON).TryParseToInt(); * }*/ internal static async Task <List <Tuple <LeaderboardEntry_t, int[]> > > GetLeaderboardEntries(string leaderboardName, ELeaderboardDataRequest type, int start, int end, 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.DownloadLeaderboardEntries(resultLeaderboard.m_hSteamLeaderboard, type, start, end), CancellationToken.None, (tcs, result, bIOFailure) => { if (result.m_hSteamLeaderboard.m_SteamLeaderboard == 0 || bIOFailure) { tcs.SetException(new Exception("Ошибка GetLeaderboardEntries")); 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 extern int DownloadLeaderboardScores(StatusCallback downloadLeaderboardScoresCB, string pchLeaderboardName, ELeaderboardDataRequest eLeaderboardDataRequest, ELeaderboardDataTimeRange eLeaderboardDataTimeRange, int nRangeStart, int nRangeEnd);
/// <summary> /// <para> Asks the Steam back-end for a set of rows in the leaderboard.</para> /// <para> This call is asynchronous, with the result returned in LeaderboardScoresDownloaded_t</para> /// <para> LeaderboardScoresDownloaded_t will contain a handle to pull the results from GetDownloadedLeaderboardEntries() (below)</para> /// <para> You can ask for more entries than exist, and it will return as many as do exist.</para> /// <para> k_ELeaderboardDataRequestGlobal requests rows in the leaderboard from the full table, with nRangeStart & nRangeEnd in the range [1, TotalEntries]</para> /// <para> k_ELeaderboardDataRequestGlobalAroundUser requests rows around the current user, nRangeStart being negate</para> /// <para> e.g. DownloadLeaderboardEntries( hLeaderboard, k_ELeaderboardDataRequestGlobalAroundUser, -3, 3 ) will return 7 rows, 3 before the user, 3 after</para> /// <para> k_ELeaderboardDataRequestFriends requests all the rows for friends of the current user</para> /// </summary> public static SteamAPICall_t DownloadLeaderboardEntries(SteamLeaderboard_t hSteamLeaderboard, ELeaderboardDataRequest eLeaderboardDataRequest, int nRangeStart, int nRangeEnd) { InteropHelp.TestIfAvailableClient(); return((SteamAPICall_t)NativeMethods.ISteamUserStats_DownloadLeaderboardEntries(CSteamAPIContext.GetSteamUserStats(), hSteamLeaderboard, eLeaderboardDataRequest, nRangeStart, nRangeEnd)); }
public static extern ulong ISteamUserStats_DownloadLeaderboardEntries(SteamLeaderboard_t hSteamLeaderboard, ELeaderboardDataRequest eLeaderboardDataRequest, int nRangeStart, int nRangeEnd);
// Call this once when ever your GUI switches state to download the updated leaderboard entries. // If you wish to have multiple pages you could pass in the offset from your GUI. public bool GetLeaderboard(Leaderboard board, ELeaderboardDataRequest requesttype) { if (!SteamManager.Initialized) { return false; } if (m_bLoading) { // If we're still loading the Leaderboards then we'll defer this until we've finished StartCoroutine(RetryGetLeaderboard(board, requesttype)); return false; } int offset = 0; if (requesttype == ELeaderboardDataRequest.k_ELeaderboardDataRequestGlobalAroundUser) { offset = -5; } SteamAPICall_t hSteamAPICall = SteamUserStats.DownloadLeaderboardEntries(m_LeaderboardHandles[(int)board], requesttype, offset, offset + k_nMaxLeaderboardEntries); // Register for the async callback m_callResultDownloadedEntries.Set(hSteamAPICall); m_bDownloading = true; return true; }
private static bool SteamUnityAPI_SteamUserStats_RequestLeaderboardEntries(IntPtr stats, ulong leaderboard, ELeaderboardDataRequest requestType, int startIndex, int endIndex, IntPtr OnLeaderboardEntriesRetrievedCallback);
/// <summary> /// 查询排行榜数据-全球 /// </summary> /// <param name="leaderboardId"></param> /// <param name="startRange"></param> /// <param name="endRange"></param> /// <param name="type"></param> /// <param name="callBack"></param> public void FindLeaderboardEntries(ulong leaderboardId, int startRange, int endRange, ELeaderboardDataRequest type, ISteamLeaderboardEntriesCallBack callBack) { this.mEntriesCallBack = callBack; SteamLeaderboard_t tempBean = new SteamLeaderboard_t { m_SteamLeaderboard = leaderboardId }; CallResult <LeaderboardScoresDownloaded_t> callResult = CallResult <LeaderboardScoresDownloaded_t> .Create(OnLeaderboardScoresDownloaded); SteamAPICall_t handle = SteamUserStats.DownloadLeaderboardEntries(tempBean, type, startRange, endRange); //TODO 必须要延迟才能设置回调 //Thread.Sleep(1000); callResult.Set(handle); }
private static bool SteamUnityAPI_SteamUserStats_RequestLeaderboardEntries(IntPtr stats, ulong leaderboard, ELeaderboardDataRequest requestType, int startIndex, int endIndex, IntPtr OnLeaderboardEntriesRetrievedCallback);
/// <summary> /// 查询排行榜数据 /// </summary> /// <param name="leaderboardId"></param> /// <param name="startRange"></param> /// <param name="endRange"></param> /// <param name="type"></param> /// <param name="callBack"></param> private void findLeaderboardEntries(ulong leaderboardId, int startRange, int endRange, ELeaderboardDataRequest type, LeaderboardEntriesFindResultCallBack callBack) { OnLeaderboardEntriesFindResultCallBack = callBack; m_SteamLeaderboard = new SteamLeaderboard_t(); m_SteamLeaderboard.m_SteamLeaderboard = leaderboardId; OnLeaderboardScoresDownloadedCallResult = CallResult <LeaderboardScoresDownloaded_t> .Create(OnLeaderboardScoresDownloaded); SteamAPICall_t handle = SteamUserStats.DownloadLeaderboardEntries(m_SteamLeaderboard, type, startRange, endRange); //TODO 必须要延迟才能设置回调 Thread.Sleep(1000); OnLeaderboardScoresDownloadedCallResult.Set(handle); }
public UInt64 DownloadLeaderboardEntries(UInt64 hSteamLeaderboard, ELeaderboardDataRequest eLeaderboardDataRequest, Int32 nRangeStart, Int32 nRangeEnd) { UInt64 ret = 0; this.GetFunction <NativeDownloadLeaderboardEntriesUEII>(this.Functions.DownloadLeaderboardEntries24)(this.ObjectAddress, ref ret, hSteamLeaderboard, eLeaderboardDataRequest, nRangeStart, nRangeEnd); return((UInt64)ret); }
// If we're still loading the Leaderboards when GetLeaderboard() is called we'll wait until they are loaded and try calling GetLeaderboard() again. private IEnumerator RetryGetLeaderboard(Leaderboard board, ELeaderboardDataRequest requesttype) { while (m_bLoading) { yield return null; } GetLeaderboard(board, requesttype); }
public static SteamAPICall_t DownloadLeaderboardEntries(SteamLeaderboard_t hSteamLeaderboard, ELeaderboardDataRequest eLeaderboardDataRequest, int nRangeStart, int nRangeEnd) { InteropHelp.TestIfAvailableClient(); return (SteamAPICall_t)NativeMethods.ISteamUserStats_DownloadLeaderboardEntries(hSteamLeaderboard, eLeaderboardDataRequest, nRangeStart, nRangeEnd); }
// Leaderboard internal static int DownloadLeaderboardScores(StatusCallback callback, string pchLeaderboardName, ELeaderboardDataRequest nDataRequest, ELeaderboardDataTimeRange nTimeRange, int nRangeStart, int nRangeEnd) { int nRequestValue = (int)nDataRequest; int nTimeValue = (int)nTimeRange; return(Android.GetJavaUserStats().CallStatic <int>("getLeaderboard", Android.CurrentContext, new AndroidPluginCallback(callback), pchLeaderboardName, nRangeStart, nRangeEnd, nTimeValue, nRequestValue)); }
public UInt64 DownloadLeaderboardEntries(UInt64 hSteamLeaderboard, ELeaderboardDataRequest eLeaderboardDataRequest, Int32 nRangeStart, Int32 nRangeEnd) { return(this.GetFunction <NativeDownloadLeaderboardEntriesUEII>(this.Functions.DownloadLeaderboardEntries26)(this.ObjectAddress, hSteamLeaderboard, eLeaderboardDataRequest, nRangeStart, nRangeEnd)); }
private void OnDownloadScoresFindLeaderboardCallCompleted(string p_leaderboardName, ELeaderboardDataRequest p_scoreSource, int p_rangeStart, int p_rangeEnd, LeaderboardFindResult_t p_callbackFind, bool p_bIOFailureFind) { EResult callResultType = p_callbackFind.m_bLeaderboardFound == 1 ? EResult.k_EResultOK : EResult.k_EResultFileNotFound; if (CheckAndLogResult <LeaderboardFindResult_t, LeaderboardsDownloadedScoresEventArgs>("OnDownloadScoresFindLeaderboardCallCompleted", callResultType, p_bIOFailureFind, "OnDownloadedScores", ref OnDownloadedScores)) { // download scores Execute <LeaderboardScoresDownloaded_t>(SteamUserStats.DownloadLeaderboardEntries(p_callbackFind.m_hSteamLeaderboard, p_scoreSource, p_rangeStart, p_rangeEnd), (p_callbackDownload, p_bIOFailureDownload) => OnDownloadLeaderboardEntriesCallCompleted(p_leaderboardName, p_callbackDownload, p_bIOFailureDownload)); if (IsDebugLogEnabled) { Debug.Log("DownloadScores: leaderboard '" + p_leaderboardName + "' found, starting scores download"); } } }
/// <summary> /// Asks the Steam back-end for a set of rows in the leaderboard. /// Results are returned in a <see cref="LeaderboardEntriesCallback"/>. /// The returned <see cref="AsyncJob{T}"/> can also be awaited to retrieve the callback result. /// </summary> /// <param name="appId">The AppID to request leaderboard rows for.</param> /// <param name="id">ID of the leaderboard to view.</param> /// <returns>The Job ID of the request. This can be used to find the appropriate <see cref="LeaderboardEntriesCallback"/>.</returns> /// <param name="rangeStart">Range start or 0.</param> /// <param name="rangeEnd">Range end or max leaderboard entries.</param> /// <param name="dataRequest">Type of request.</param> public AsyncJob <LeaderboardEntriesCallback> GetLeaderboardEntries(uint appId, int id, int rangeStart, int rangeEnd, ELeaderboardDataRequest dataRequest) { var msg = new ClientMsgProtobuf <CMsgClientLBSGetLBEntries>(EMsg.ClientLBSGetLBEntries); msg.SourceJobID = Client.GetNextJobID(); // routing_appid has to be set correctly to receive a response msg.ProtoHeader.routing_appid = appId; msg.Body.app_id = ( int )appId; msg.Body.leaderboard_id = id; msg.Body.leaderboard_data_request = ( int )dataRequest; msg.Body.range_start = rangeStart; msg.Body.range_end = rangeEnd; Client.Send(msg); return(new AsyncJob <LeaderboardEntriesCallback>(this.Client, msg.SourceJobID)); }
public bool FetchLeaderBoardData(string leaderBoardName, ResultsCallBack callbackAction, int startRange, int endRange, ELeaderboardDataRequest requestType) { bool result = false; this.callbackAction = callbackAction; SteamLeaderboard_t leaderBoard; if (SteamManager.Initialized) { if (leaderBoards.TryGetValue(leaderBoardName, out leaderBoard)) { SteamAPICall_t apiCall = SteamUserStats.DownloadLeaderboardEntries(leaderBoard, requestType, startRange, endRange); if (leaderBoardScoresDownloaded.IsActive()) { leaderBoardScoresDownloaded.Cancel(); leaderBoardScoresDownloaded.Dispose(); } leaderBoardScoresDownloaded.Set(apiCall); result = true; } else { //Get or create the leader board actionType = 1; result = FindOrCreateLeaderboard(leaderBoardName); } } return(result); }
/// <summary> /// Asks the Steam back-end for a set of rows in the leaderboard. /// Results are returned in a <see cref="LeaderboardEntriesCallback"/>. /// </summary> /// <param name="appId">The AppID to request leaderboard rows for.</param> /// <param name="id">ID of the leaderboard to view.</param> /// <returns>The Job ID of the request. This can be used to find the appropriate <see cref="LeaderboardEntriesCallback"/>.</returns> /// <param name="rangeStart">Range start or 0.</param> /// <param name="rangeEnd">Range end or max leaderboard entries.</param> /// <param name="dataRequest">Type of request.</param> public JobID GetLeaderboardEntries( uint appId, int id, int rangeStart, int rangeEnd, ELeaderboardDataRequest dataRequest ) { var msg = new ClientMsgProtobuf<CMsgClientLBSGetLBEntries>( EMsg.ClientLBSGetLBEntries ); msg.SourceJobID = Client.GetNextJobID(); // routing_appid has to be set correctly to receive a response msg.ProtoHeader.routing_appid = appId; msg.Body.app_id = ( int )appId; msg.Body.leaderboard_id = id; msg.Body.leaderboard_data_request = ( int )dataRequest; msg.Body.range_start = rangeStart; msg.Body.range_end = rangeEnd; Client.Send( msg ); return msg.SourceJobID; }
/// Asks the Steam back-end for a set of rows in the leaderboard. /// This call is asynchronous, with the result returned in LeaderboardScoresDownloaded_t /// LeaderboardScoresDownloaded_t will contain a handle to pull the results from GetDownloadedLeaderboardEntries() (below) /// You can ask for more entries than exist, and it will return as many as do exist. /// k_ELeaderboardDataRequestGlobal requests rows in the leaderboard from the full table, with nRangeStart & nRangeEnd in the range [1, TotalEntries] /// k_ELeaderboardDataRequestGlobalAroundUser requests rows around the current user, nRangeStart being negate /// e.g. DownloadLeaderboardEntries( hLeaderboard, k_ELeaderboardDataRequestGlobalAroundUser, -3, 3 ) will return 7 rows, 3 before the user, 3 after /// k_ELeaderboardDataRequestFriends requests all the rows for friends of the current user public static SteamAPICall_t DownloadLeaderboardEntries(SteamLeaderboard_t hSteamLeaderboard, ELeaderboardDataRequest eLeaderboardDataRequest, int nRangeStart, int nRangeEnd) { return((SteamAPICall_t)0); }