예제 #1
0
    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);
    }
예제 #2
0
    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);
        }
    }
    public bool DownloadScores(bool newPlayer = false)
    {
        if (currentLeaderboard == null)
        {
            return(false);
        }

        downloadInProgress = true;
        loadedScores       = null;

        SteamAPICall_t steamAPICall;

        if (!newPlayer)
        {
            steamAPICall = SteamUserStats.DownloadLeaderboardEntries(currentLeaderboard, ELeaderboardDataRequest.k_ELeaderboardDataRequestGlobalAroundUser, -leaderBoardEntryMax / 2, (leaderBoardEntryMax / 2) - 1);
        }
        else
        {
            steamAPICall = SteamUserStats.DownloadLeaderboardEntries(currentLeaderboard, ELeaderboardDataRequest.k_ELeaderboardDataRequestGlobal, 1, leaderBoardEntryMax);
        }

        callResultDownloadScore.Set(steamAPICall, OnDownloadScore);

        return(true);
    }
예제 #4
0
        private static void DownloadEntries()
        {
            const int InitialCacheSize = 100;

            SteamAPICall_t result;

            if (readAction.Gamers != null)
            {
                /* FIXME: We're just going to assume "Friends" here...
                 * There is DownloadLeaderboardEntriesForUsers, but holy shit,
                 * have you seen the way they expect you to get friend gamers?
                 * -flibit
                 */
                result = SteamUserStats.DownloadLeaderboardEntries(
                    readAction.Leaderboard,
                    ELeaderboardDataRequest.k_ELeaderboardDataRequestFriends,
                    0,
                    InitialCacheSize
                    );
            }
            else if (readAction.PivotGamer == null)
            {
                result = SteamUserStats.DownloadLeaderboardEntries(
                    readAction.Leaderboard,
                    ELeaderboardDataRequest.k_ELeaderboardDataRequestGlobal,
                    1,
                    InitialCacheSize
                    );
            }
            else
            {
                if (readAction.PivotGamer.steamID != SteamUser.GetSteamID())
                {
                    throw new NotSupportedException(
                              "Global score around user other than host"
                              );
                }
                result = SteamUserStats.DownloadLeaderboardEntries(
                    readAction.Leaderboard,
                    ELeaderboardDataRequest.k_ELeaderboardDataRequestGlobalAroundUser,
                    readAction.PageStart - (InitialCacheSize / 2),
                    readAction.PageStart + (InitialCacheSize / 2)
                    );
            }

            if (result.m_SteamAPICall != 0)
            {
                CallResult <LeaderboardScoresDownloaded_t> downloaded;
                downloaded = new CallResult <LeaderboardScoresDownloaded_t>();
                downloaded.Set(
                    result,
                    OnScoresDownloaded
                    );
            }
            else
            {
                readAction.IsCompleted = true;
            }
        }
예제 #5
0
    public void DownloadTop100Entries()
    {
        Debug.Log("[LeaderBoard] downloading top 100 leaderboard entries");
        downLoadingTop100Entries = true;
        SteamAPICall_t handle4 = SteamUserStats.DownloadLeaderboardEntries(hSteamLeaderboard, ELeaderboardDataRequest.k_ELeaderboardDataRequestGlobal, 0, 100);

        m_LeaderBoardTop100Downloaded.Set(handle4); // set m_LeaderBoardTop100Downloaded with the top 10 downloaded leaderboard entries
    }
예제 #6
0
        private void download(SteamLeaderboard_t leaderboard)
        {
#if STEAMWORKS
            this.globalLeaderboardDownloadCall = new CallResult <LeaderboardScoresDownloaded_t>((downloaded, downloadedFailure) =>
            {
                this.globalLeaderboardDownloadCall = null;
                if (downloadedFailure)
                {
                    this.OnLeaderboardError.Execute();
                }
                else
                {
                    if (downloaded.m_cEntryCount == 0)
                    {
                        // We're not ranked
                        // Get the top global list
                        this.globalLeaderboardDownloadCall = new CallResult <LeaderboardScoresDownloaded_t>((downloaded2, downloadedFailure2) =>
                        {
                            if (downloadedFailure2)
                            {
                                this.OnLeaderboardError.Execute();
                            }
                            else
                            {
                                this.globalScoresDownloaded = true;
                                this.globalScores           = downloaded2;
                                this.checkLeaderboardsDownloaded();
                            }
                        });
                        this.globalLeaderboardDownloadCall.Set(SteamUserStats.DownloadLeaderboardEntries(leaderboard, ELeaderboardDataRequest.k_ELeaderboardDataRequestGlobal, 0, this.before + this.after));
                    }
                    else
                    {
                        this.globalScoresDownloaded = true;
                        this.globalScores           = downloaded;
                        this.checkLeaderboardsDownloaded();
                    }
                }
            });
            this.globalLeaderboardDownloadCall.Set(SteamUserStats.DownloadLeaderboardEntries(leaderboard, ELeaderboardDataRequest.k_ELeaderboardDataRequestGlobalAroundUser, -this.before, this.after));
            this.friendLeaderboardDownloadCall = new CallResult <LeaderboardScoresDownloaded_t>((downloaded, downloadedFailure) =>
            {
                this.friendLeaderboardDownloadCall = null;
                if (downloadedFailure)
                {
                    this.OnLeaderboardError.Execute();
                }
                else
                {
                    this.friendScoresDownloaded = true;
                    this.friendScores           = downloaded;
                    this.checkLeaderboardsDownloaded();
                }
            });
            this.friendLeaderboardDownloadCall.Set(SteamUserStats.DownloadLeaderboardEntries(leaderboard, ELeaderboardDataRequest.k_ELeaderboardDataRequestFriends, -this.friendsBefore, this.friendsAfter));
#endif
        }
예제 #7
0
 public void DownloadLeaderboardEntries()
 {
     if (m_steamLeaderboard.m_SteamLeaderboard != 0)
     {
         Debug.LogError("请求排行榜数据");
         var handle = SteamUserStats.DownloadLeaderboardEntries(m_steamLeaderboard, ELeaderboardDataRequest.k_ELeaderboardDataRequestGlobal, 1, 8);
         m_LeaderboardScoresDownloaded.Set(handle);
     }
 }
예제 #8
0
    private void OnDownload()
    {
        if (leaderboard_T == new SteamLeaderboard_t(0))
        {
            return;
        }
        SteamAPICall_t steamAPICall = SteamUserStats.DownloadLeaderboardEntries(leaderboard_T, (ELeaderboardDataRequest)requestType, 1, 30);

        OnLeaderboardScoresDownloadedCallResult.Set(steamAPICall, DownloadResult);
    }
예제 #9
0
    public bool DownloadGlobalScores(int start, int end)
    {
        if (leaderboard == null)
        {
            return(false);
        }
        SteamAPICall_t steamCall = SteamUserStats.DownloadLeaderboardEntries(leaderboard, ELeaderboardDataRequest.k_ELeaderboardDataRequestGlobal, start, end);

        DownloadResult.Set(steamCall);
        return(true);
    }
예제 #10
0
        /// <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);
        }
예제 #11
0
        public void RequestEntries(LeaderboardHandle Handle, int RequestType, int Start, int End, Action <bool> OnDownload)
        {
            s_OnDownload = OnDownload;

            // Request the specified leaderboard data.
            SteamAPICall_t hSteamAPICall = (SteamAPICall_t)SteamUserStats.DownloadLeaderboardEntries(
                Handle.m_handle, (ELeaderboardDataRequest)(RequestType), Start, End);

            // Register for the async callback
            SteamMatches.g_CallResultDownloadEntries = new CallResult <LeaderboardScoresDownloaded_t>(CallbackClass.instance.OnLeaderboardDownloadedEntries);
            SteamMatches.g_CallResultDownloadEntries.Set(hSteamAPICall); //, SteamStats.g_CallbackClassInstance, CallbackClass.OnLeaderboardDownloadedEntries);
        }
예제 #12
0
 /// <summary>
 /// This method download the leaderboard entries, with the range being m_leaderboardEntriesRangeInit to m_leaderboardEntriesRangeInit
 /// </summary>
 public static void DownloadLeaderboardEntries()
 {
     if (!m_leaderboardInitiated)
     {
         Debug.Log("The leaderboard was not found!");
     }
     else
     {
         SteamAPICall_t _steamAPICall = SteamUserStats.DownloadLeaderboardEntries(m_steamLeaderBoard, m_requestType, m_leaderboardEntriesRangeInit, m_leaderboardEntriesRangeEnd);
         m_scoresDownloadedResult.Set(_steamAPICall, OnLeaderBoardScoresDownloaded);
     }
 }
예제 #13
0
        public IAsyncResult BeginPageDown(
            AsyncCallback callback,
            object asyncState
            )
        {
            readAction = new LeaderboardReaderAction(
                asyncState,
                callback,
                LeaderboardIdentity,
                PageStart,
                pageSize,
                null,
                null
                );

            if (PageStart + pageSize * 2 <= entryCache.Count)
            {
                readAction.IsCompleted = true;
            }
            else if (!CanPageDown)
            {
                readAction.IsCompleted = true;

                // Cannot increment page start, bail immediately
                return(readAction);
            }
            else if (isFriendBoard)
            {
                // Friend max is 100, no need to download ever
                readAction.IsCompleted = true;
            }
            else
            {
                SteamAPICall_t call = SteamUserStats.DownloadLeaderboardEntries(
                    Leaderboards[LeaderboardIdentity.Key],
                    ELeaderboardDataRequest.k_ELeaderboardDataRequestGlobal,
                    entryCache[entryCache.Count - 1].RankingEXT + 1,
                    entryCache[entryCache.Count - 1].RankingEXT + pageSize
                    );
                if (call.m_SteamAPICall != 0)
                {
                    CallResult <LeaderboardScoresDownloaded_t> scoresDownloaded;
                    scoresDownloaded = new CallResult <LeaderboardScoresDownloaded_t>();
                    scoresDownloaded.Set(
                        call,
                        DoPageDown
                        );
                }
            }
            readAction.PageStart += pageSize;
            return(readAction);
        }
예제 #14
0
        protected override void GetAroundMeLeaderboard(int numberOfEntries)
        {
            _getAroundMeLeaderboardRequest = CallResult <LeaderboardScoresDownloaded_t> .Create(OnGetEntriesRersponse);

            SteamAPICall_t handler = SteamUserStats.DownloadLeaderboardEntries(
                _leaderboardId
                , ELeaderboardDataRequest.k_ELeaderboardDataRequestGlobalAroundUser
                , -(int)UnityEngine.Mathf.Floor(numberOfEntries / 2)
                , (int)UnityEngine.Mathf.Ceil(numberOfEntries / 2)
                );

            _getAroundMeLeaderboardRequest.Set(handler);
        }
예제 #15
0
    /// <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);
    }
예제 #16
0
        protected override void GetFriendsLeaderboard(int numberOfEntries)
        {
            _getFriendsLeaderboardRequest = CallResult <LeaderboardScoresDownloaded_t> .Create(OnGetEntriesRersponse);

            SteamAPICall_t handler = SteamUserStats.DownloadLeaderboardEntries(
                _leaderboardId
                , ELeaderboardDataRequest.k_ELeaderboardDataRequestFriends
                , 0
                , numberOfEntries
                );

            _getFriendsLeaderboardRequest.Set(handler);
        }
예제 #17
0
        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");
                }
            }
        }
예제 #18
0
    /// <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);
    }
예제 #19
0
    private void OnLeaderboardFindResult(LeaderboardFindResult_t pCallback, bool bIOFailure)
    {
        Debug.Log("[" + LeaderboardFindResult_t.k_iCallback + " - LeaderboardFindResult] - " + pCallback.m_hSteamLeaderboard + " -- " + pCallback.m_bLeaderboardFound);

        if (pCallback.m_bLeaderboardFound != 0)
        {
            m_SteamLeaderboard = pCallback.m_hSteamLeaderboard;
        }

        if (downloadEntries)
        {
            SteamAPICall_t downloadHandle = SteamUserStats.DownloadLeaderboardEntries(m_SteamLeaderboard, ELeaderboardDataRequest.k_ELeaderboardDataRequestGlobal, (int)downloadRange.x, (int)downloadRange.y);
            LeaderboardScoresDownloaded.Set(downloadHandle, OnLeaderboardScoresDownloaded);
            downloadEntries = false;
        }
    }
예제 #20
0
    /// <summary>
    /// エントリ取得:ユーザーのグルーバルランキング位置からの指定相対数
    /// -4, 5でユーザー自身のランキングと、その位置から前4・後5の合計10個分エントリを取得する
    /// 前指定が条件を満たさない場合、その超過分は後方取得に置き換えられる
    /// </summary>
    /// <returns><c>true</c>, if scores was downloaded, <c>false</c> otherwise.</returns>
    /// <param name="_rangeStart">取得開始位置</param>
    /// <param name="_rangeEnd">取得終了位置</param>
    public bool DownloadScoreGlobalAroundUser(int _rangeStart, int _rangeEnd, CallBackDownload _callback = null)
    {
        if (steamLeaderboard == null)
        {
            return(false);
        }
        callBackDownload = _callback;

        CurrentDownloadEntryCnt = 0;

        SteamAPICall_t handle = SteamUserStats.DownloadLeaderboardEntries((SteamLeaderboard_t)steamLeaderboard, ELeaderboardDataRequest.k_ELeaderboardDataRequestGlobalAroundUser, _rangeStart, _rangeEnd);

        leaderboardScoresDownloaded.Set(handle);

        return(true);
    }
예제 #21
0
        public IAsyncResult BeginPageUp(
            AsyncCallback callback,
            object asyncState
            )
        {
            readAction = new LeaderboardReaderAction(
                asyncState,
                callback,
                LeaderboardIdentity,
                PageStart,
                pageSize,
                null,
                null
                );

            if (PageStart >= pageSize)
            {
                readAction.PageStart  -= pageSize;
                readAction.IsCompleted = true;
            }
            else if (!CanPageUp)
            {
                readAction.IsCompleted = true;
            }
            else
            {
                SteamAPICall_t call = SteamUserStats.DownloadLeaderboardEntries(
                    Leaderboards[LeaderboardIdentity.Key],
                    ELeaderboardDataRequest.k_ELeaderboardDataRequestGlobal,
                    entryCache[0].RankingEXT - pageSize,
                    entryCache[0].RankingEXT - 1
                    );
                if (call.m_SteamAPICall != 0)
                {
                    CallResult <LeaderboardScoresDownloaded_t> scoresDownloaded;
                    scoresDownloaded = new CallResult <LeaderboardScoresDownloaded_t>();
                    scoresDownloaded.Set(
                        call,
                        DoPageUp
                        );
                }
            }

            return(readAction);
        }
예제 #22
0
    /// <summary>
    /// Change if this leader board displays in high score mode or around user mode
    /// </summary>
    public void ChangeScoreBoardAroundType(bool hScore)
    {
        if (SteamManager.Initialized == true)
        {
            if (hScore == true)
            {
                SteamAPICall_t handle = SteamUserStats.DownloadLeaderboardEntries(m_SteamLeaderboard, ELeaderboardDataRequest.k_ELeaderboardDataRequestGlobal, 1, 10);

                // Set the downloaded score
                LeaderboardScoresDownloaded.Set(handle);
            }
            else
            {
                SteamAPICall_t handle = SteamUserStats.DownloadLeaderboardEntries(m_SteamLeaderboard, ELeaderboardDataRequest.k_ELeaderboardDataRequestGlobalAroundUser, -5, 5);

                // Set the downloaded score
                LeaderboardScoresDownloaded.Set(handle);
            }
        }
    }
예제 #23
0
    public void DownloadEntries()
    {
        //download entries from steam!

        if (s_initialized == false)
        {
            return;
        }

        SteamAPICall_t hSteamAPICall = SteamUserStats.DownloadLeaderboardEntries(s_currentLeaderboard, ELeaderboardDataRequest.k_ELeaderboardDataRequestGlobal, 0, 9);

        m_downloadResultTopTen.Set(hSteamAPICall, OnLeaderboardFindTopTen);

        SteamAPICall_t hSteamAPICallB = SteamUserStats.DownloadLeaderboardEntries(s_currentLeaderboard, ELeaderboardDataRequest.k_ELeaderboardDataRequestGlobalAroundUser, -5, 4);

        m_downloadResultAroundUser.Set(hSteamAPICallB, OnLeaderboardFindAroundUser);

        SteamAPICall_t hSteamAPICallC = SteamUserStats.DownloadLeaderboardEntriesForUsers(s_currentLeaderboard, new CSteamID[] { SteamUser.GetSteamID() }, 1);

        m_downloadResultUser.Set(hSteamAPICallC, OnLeaderboardFindUser);
    }
예제 #24
0
 private void OnLeaderboardFound(LeaderboardFindResult_t pCallback, bool bIOFailure)
 {
     if (bIOFailure)
     {
         Console.WriteLine("Something went wrong finding the leaderboard");
     }
     else
     {
         if (pCallback.m_bLeaderboardFound == 1)
         {
             Console.WriteLine("Leaderboard Found!");
             SteamAPICall_t handle = SteamUserStats.DownloadLeaderboardEntries(pCallback.m_hSteamLeaderboard, 0, 0, int.MaxValue);
             m_DownloadedLeaderboard.Set(handle);
             Console.WriteLine("Downloading leaderboard " + this.name + ", one sec");
         }
         else
         {
             Console.WriteLine("No leaderboard found");
             done = true;
         }
     }
 }
예제 #25
0
    //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)
    }
예제 #26
0
        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);
        }
예제 #27
0
    private void Update()
    {
        timeout -= Time.deltaTime;
        if (timeout < 0)
        {
            timeout = 0;
        }

        if (timeout <= 0)
        {
            timeout = 1;
            if (!getterLeaderboard)
            {
                SteamAPICall_t handle = SteamUserStats.FindOrCreateLeaderboard(leaderboardName, ELeaderboardSortMethod.k_ELeaderboardSortMethodDescending, ELeaderboardDisplayType.k_ELeaderboardDisplayTypeNumeric);
                m_SteamLeaderboard_t.Set(handle);
            }
            //Получение топовых игроков
            else if (getterLeaderboard && !getterLeaderboardDownloadTOP)
            {
                Debug.Log("getterLeaderboardDownload_TOP test");
                SteamLeaderboard_t steamLeaderboard_T;
                steamLeaderboard_T.m_SteamLeaderboard = SteamLeaderboard.m_hSteamLeaderboard.m_SteamLeaderboard;
                SteamAPICall_t handle = SteamUserStats.DownloadLeaderboardEntries(steamLeaderboard_T, ELeaderboardDataRequest.k_ELeaderboardDataRequestGlobal, 1, 3);
                m_LeaderboardScoresDownloaded_TOP.Set(handle);
            }
            //Получение участка списка лидеров
            else if (getterLeaderboard && !getterLeaderboardDownload)
            {
                Debug.Log("getterLeaderboardDownload test");
                SteamLeaderboard_t steamLeaderboard_T;
                steamLeaderboard_T.m_SteamLeaderboard = SteamLeaderboard.m_hSteamLeaderboard.m_SteamLeaderboard;
                int            min    = -5 + LeaderboardSmeshenie * 10;
                int            max    = 4 + LeaderboardSmeshenie * 10;
                SteamAPICall_t handle = SteamUserStats.DownloadLeaderboardEntries(steamLeaderboard_T, ELeaderboardDataRequest.k_ELeaderboardDataRequestGlobalAroundUser, min, max);
                m_LeaderboardScoresDownloaded_t.Set(handle);
            }
            else if (getterLeaderboard && !getterLeaderboardDownloadFriends)
            {
                Debug.Log("getterLeaderboardDownload_Friends test");
                SteamLeaderboard_t steamLeaderboard_T;
                steamLeaderboard_T.m_SteamLeaderboard = SteamLeaderboard.m_hSteamLeaderboard.m_SteamLeaderboard;
                SteamAPICall_t handle = SteamUserStats.DownloadLeaderboardEntries(steamLeaderboard_T, ELeaderboardDataRequest.k_ELeaderboardDataRequestFriends, 1, 3);
                m_LeaderboardScoresDownloaded_Friends.Set(handle);
            }
            else if (!TestFirst && getterLeaderboard && getterLeaderboardDownloadFriends)
            {
                TestFirst = true;
                LeaderboardEntry_t leaderboardEntry;
                int[] details = new int[5];
                bool  ok_load = SteamUserStats.GetDownloadedLeaderboardEntry(SteamleaderboardScoresDownloaded_Friends.m_hSteamLeaderboardEntries, 0, out leaderboardEntry, details, 5);
                if (ok_load)
                {
                    if (leaderboardEntry.m_steamIDUser == SteamUser.GetSteamID())
                    {
                        gameObject.GetComponent <steam_achievement>().the_first();
                    }
                }
            }
            //Загрузка очков в таблицу
            else if (getterLeaderboard && !uploadScore)
            {
                SteamLeaderboard_t steamLeaderboard_T;
                steamLeaderboard_T.m_SteamLeaderboard = SteamLeaderboard.m_hSteamLeaderboard.m_SteamLeaderboard;
                int[]          testArray = new int[5];
                SteamAPICall_t handle;
                if (!reWriteTop)
                {
                    handle = SteamUserStats.UploadLeaderboardScore(steamLeaderboard_T, ELeaderboardUploadScoreMethod.k_ELeaderboardUploadScoreMethodKeepBest, countScore, testArray, 5);
                }
                else
                {
                    handle = SteamUserStats.UploadLeaderboardScore(steamLeaderboard_T, ELeaderboardUploadScoreMethod.k_ELeaderboardUploadScoreMethodForceUpdate, countScore, testArray, 5);
                }
                m_LeaderboardScoreUploaded_t.Set(handle);
            }
        }
    }
    private void RenderPageTwo()
    {
        if (GUILayout.Button("FindOrCreateLeaderboard(\"Feet Traveled\", k_ELeaderboardSortMethodAscending, k_ELeaderboardDisplayTypeNumeric)"))
        {
            SteamAPICall_t handle = SteamUserStats.FindOrCreateLeaderboard("Feet Traveled", ELeaderboardSortMethod.k_ELeaderboardSortMethodAscending, ELeaderboardDisplayType.k_ELeaderboardDisplayTypeNumeric);
            LeaderboardFindResult.Set(handle);
            print("FindOrCreateLeaderboard(\"Feet Traveled\", ELeaderboardSortMethod.k_ELeaderboardSortMethodAscending, ELeaderboardDisplayType.k_ELeaderboardDisplayTypeNumeric) - " + handle);
        }

        if (GUILayout.Button("FindLeaderboard(\"Feet Traveled\")"))
        {
            SteamAPICall_t handle = SteamUserStats.FindLeaderboard("Feet Traveled");
            LeaderboardFindResult.Set(handle);
            print("FindLeaderboard(\"Feet Traveled\") - " + handle);
        }

        // Spams SteamAPI Warnings that the SteamLeaderboard does not exist.
        if (m_SteamLeaderboard != new SteamLeaderboard_t(0))
        {
            GUILayout.Label("GetLeaderboardName(m_SteamLeaderboard) : " + SteamUserStats.GetLeaderboardName(m_SteamLeaderboard));
            GUILayout.Label("GetLeaderboardEntryCount(m_SteamLeaderboard) : " + SteamUserStats.GetLeaderboardEntryCount(m_SteamLeaderboard));
            GUILayout.Label("GetLeaderboardSortMethod(m_SteamLeaderboard) : " + SteamUserStats.GetLeaderboardSortMethod(m_SteamLeaderboard));
            GUILayout.Label("GetLeaderboardDisplayType(m_SteamLeaderboard) : " + SteamUserStats.GetLeaderboardDisplayType(m_SteamLeaderboard));
        }
        else
        {
            GUILayout.Label("GetLeaderboardName(m_SteamLeaderboard) : ");
            GUILayout.Label("GetLeaderboardEntryCount(m_SteamLeaderboard) : ");
            GUILayout.Label("GetLeaderboardSortMethod(m_SteamLeaderboard) : ");
            GUILayout.Label("GetLeaderboardDisplayType(m_SteamLeaderboard) : ");
        }

        if (GUILayout.Button("DownloadLeaderboardEntries(m_SteamLeaderboard, ELeaderboardDataRequest.k_ELeaderboardDataRequestGlobal, 1, 5)"))
        {
            SteamAPICall_t handle = SteamUserStats.DownloadLeaderboardEntries(m_SteamLeaderboard, ELeaderboardDataRequest.k_ELeaderboardDataRequestGlobal, 1, 5);
            LeaderboardScoresDownloaded.Set(handle);
            print("DownloadLeaderboardEntries(" + m_SteamLeaderboard + ", ELeaderboardDataRequest.k_ELeaderboardDataRequestGlobal, 1, 5) - " + handle);
        }

        if (GUILayout.Button("DownloadLeaderboardEntriesForUsers(m_SteamLeaderboard, Users, Users.Length)"))
        {
            CSteamID[]     Users  = { SteamUser.GetSteamID() };
            SteamAPICall_t handle = SteamUserStats.DownloadLeaderboardEntriesForUsers(m_SteamLeaderboard, Users, Users.Length);
            LeaderboardScoresDownloaded.Set(handle);
            print("DownloadLeaderboardEntriesForUsers(" + m_SteamLeaderboard + ", " + Users + ", " + Users.Length + ") - " + handle);
        }

        if (GUILayout.Button("GetDownloadedLeaderboardEntry(m_SteamLeaderboardEntries, 0, out LeaderboardEntry, null, 0)"))
        {
            LeaderboardEntry_t LeaderboardEntry;
            bool ret = SteamUserStats.GetDownloadedLeaderboardEntry(m_SteamLeaderboardEntries, 0, out LeaderboardEntry, null, 0);
            print("GetDownloadedLeaderboardEntry(" + m_SteamLeaderboardEntries + ", 0, out LeaderboardEntry, null, 0) - " + ret + " -- " + LeaderboardEntry.m_steamIDUser + " -- " + LeaderboardEntry.m_nGlobalRank + " -- " + LeaderboardEntry.m_nScore + " -- " + LeaderboardEntry.m_cDetails + " -- " + LeaderboardEntry.m_hUGC);
        }

        if (GUILayout.Button("UploadLeaderboardScore(m_SteamLeaderboard, k_ELeaderboardUploadScoreMethodForceUpdate, (int)m_FeetTraveledStat, ScoreDetails, 0)"))
        {
            SteamAPICall_t handle = SteamUserStats.UploadLeaderboardScore(m_SteamLeaderboard, ELeaderboardUploadScoreMethod.k_ELeaderboardUploadScoreMethodForceUpdate, (int)m_FeetTraveledStat, null, 0);
            LeaderboardScoreUploaded.Set(handle);
            print("UploadLeaderboardScore(" + m_SteamLeaderboard + ", ELeaderboardUploadScoreMethod.k_ELeaderboardUploadScoreMethodForceUpdate, " + (int)m_FeetTraveledStat + ", null, 0) - " + handle);
        }

        if (GUILayout.Button("SteamUserStats.AttachLeaderboardUGC(m_SteamLeaderboard, RemoteStorageTest.m_UGCHandle)"))
        {
            SteamAPICall_t handle = SteamUserStats.AttachLeaderboardUGC(m_SteamLeaderboard, UGCHandle_t.Invalid);
            LeaderboardUGCSet.Set(handle);
            print("SteamUserStats.AttachLeaderboardUGC(" + m_SteamLeaderboard + ", " + UGCHandle_t.Invalid + ") - " + handle);
        }

        if (GUILayout.Button("GetNumberOfCurrentPlayers()"))
        {
            SteamAPICall_t handle = SteamUserStats.GetNumberOfCurrentPlayers();
            NumberOfCurrentPlayers.Set(handle);
            print("GetNumberOfCurrentPlayers() - " + handle);
        }

        if (GUILayout.Button("RequestGlobalAchievementPercentages()"))
        {
            SteamAPICall_t handle = SteamUserStats.RequestGlobalAchievementPercentages();
            GlobalAchievementPercentagesReady.Set(handle);
            print("RequestGlobalAchievementPercentages() - " + handle);
        }

        {
            int Iterator;

            {
                string Name;
                float  Percent;
                bool   Achieved;
                Iterator = SteamUserStats.GetMostAchievedAchievementInfo(out Name, 120, out Percent, out Achieved);
                if (Iterator != -1)
                {
                    GUILayout.Label("GetMostAchievedAchievementInfo(out Name, 120, out Percent, out Achieved) : " + Iterator + " -- " + Name + " -- " + Percent + " -- " + Achieved);
                }
                else
                {
                    GUILayout.Label("GetMostAchievedAchievementInfo(out Name, 120, out Percent, out Achieved) : " + Iterator);
                }
            }

            if (Iterator != -1)
            {
                string Name;
                float  Percent;
                bool   Achieved;
                Iterator = SteamUserStats.GetNextMostAchievedAchievementInfo(Iterator, out Name, 120, out Percent, out Achieved);
                GUILayout.Label("GetNextMostAchievedAchievementInfo(out Name, 120, out Percent, out Achieved) : " + Iterator + " -- " + Name + " -- " + Percent + " -- " + Achieved);
            }
        }

        {
            float Percent;
            bool  ret = SteamUserStats.GetAchievementAchievedPercent("ACH_WIN_100_GAMES", out Percent);
            GUILayout.Label("GetAchievementAchievedPercent(\"ACH_WIN_100_GAMES\", out Percent) : " + ret + " -- " + Percent);
        }

        if (GUILayout.Button("SteamUserStats.RequestGlobalStats(3)"))
        {
            SteamAPICall_t handle = SteamUserStats.RequestGlobalStats(3);
            GlobalStatsReceived.Set(handle);
            print("SteamUserStats.RequestGlobalStats(3) - " + handle);
        }

        /* TODO - Spams SteamAPI warnings
         * Does SpaceWar have a stat marked as "aggregated" to try out these functions?
         * {
         *      long Data;
         *      bool ret = SteamUserStats.GetGlobalStat("", out Data);
         *      GUILayout.Label("GetGlobalStat(\"\", out Data) : " + ret + " -- " + Data);
         * }
         *
         * {
         *      double Data;
         *      bool ret = SteamUserStats.GetGlobalStat("", out Data);
         *      GUILayout.Label("GetGlobalStat(\"\", out Data) : " + ret + " -- " + Data);
         * }
         *
         * {
         *      long[] Data = new long[1];
         *      int ret = SteamUserStats.GetGlobalStatHistory("", Data, (uint)Data.Length);
         *      if (ret != 0) {
         *              GUILayout.Label("GetGlobalStatHistory(\"\", Data, " + (uint)Data.Length + ") : " + ret + " -- " + Data[0]);
         *      }
         *      else {
         *              GUILayout.Label("GetGlobalStatHistory(\"\", Data, " + (uint)Data.Length + ") : " + ret + " -- ");
         *      }
         * }
         *
         * {
         *      double[] Data = new double[1];
         *      int ret = SteamUserStats.GetGlobalStatHistory("", Data, (uint)Data.Length);
         *      if (ret != 0) {
         *              GUILayout.Label("GetGlobalStatHistory(\"\", Data, " + (uint)Data.Length + ") : " + ret + " -- " + Data[0]);
         *      }
         *      else {
         *              GUILayout.Label("GetGlobalStatHistory(\"\", Data, " + (uint)Data.Length + ") : " + ret + " -- ");
         *      }
         * }
         */
#if _PS3
        if (GUILayout.Button("InstallPS3Trophies()"))
        {
            bool ret = SteamUserStats.InstallPS3Trophies();
            print("InstallPS3Trophies() - " + ret);
        }

        if (GUILayout.Button("GetTrophySpaceRequiredBeforeInstall()"))
        {
            ulong ret = SteamUserStats.GetTrophySpaceRequiredBeforeInstall();
            print("GetTrophySpaceRequiredBeforeInstall() - " + ret);
        }

        if (GUILayout.Button("SetUserStatsData(System.IntPtr.Zero, 0)"))
        {
            bool ret = SteamUserStats.SetUserStatsData(System.IntPtr.Zero, 0);
            print(" - " + ret);
        }

        if (GUILayout.Button(""))
        {
            uint Written;
            bool ret = SteamUserStats.GetUserStatsData(System.IntPtr.Zero, 0, out Written);
            print("GetUserStatsData(System.IntPtr.Zero, 0, out Written) - " + ret + " -- " + Written);
        }
#endif
    }
예제 #29
0
    void GetThisScore()
    {
        SteamAPICall_t newApiCall = SteamUserStats.DownloadLeaderboardEntries(leaderboard_t, ELeaderboardDataRequest.k_ELeaderboardDataRequestGlobalAroundUser, 0, 1);

        downloadResultPersonal.Set(newApiCall);
    }
예제 #30
0
        private void syncLeaderboard()
        {
            this.cancelCallbacks();

            if (!SteamWorker.SteamInitialized)
            {
                this.OnLeaderboardError.Execute();
                return;
            }

            string uuid  = WorldFactory.Instance.Get <World>().UUID;
            int    score = (int)(this.BestTime.Value * 1000.0f);

            this.leaderboardFindCall = new CallResult <LeaderboardFindResult_t>((found, foundFailure) =>
            {
                this.leaderboardFindCall = null;
                if (foundFailure)
                {
                    this.OnLeaderboardError.Execute();
                }
                else
                {
                    this.leaderboardUploadCall = new CallResult <LeaderboardScoreUploaded_t>(delegate(LeaderboardScoreUploaded_t uploaded, bool uploadedFailure)
                    {
                        this.leaderboardUploadCall = null;
                        if (uploadedFailure)
                        {
                            this.OnLeaderboardError.Execute();
                        }
                        else
                        {
                            this.globalLeaderboardDownloadCall = new CallResult <LeaderboardScoresDownloaded_t>((downloaded, downloadedFailure) =>
                            {
                                this.globalLeaderboardDownloadCall = null;
                                if (downloadedFailure)
                                {
                                    this.OnLeaderboardError.Execute();
                                }
                                else
                                {
                                    this.globalScoresDownloaded = true;
                                    this.globalScores           = downloaded;
                                    this.checkLeaderboardsDownloaded();
                                }
                            });
                            this.globalLeaderboardDownloadCall.Set(SteamUserStats.DownloadLeaderboardEntries(found.m_hSteamLeaderboard, ELeaderboardDataRequest.k_ELeaderboardDataRequestGlobalAroundUser, -5, 5));
                            this.friendLeaderboardDownloadCall = new CallResult <LeaderboardScoresDownloaded_t>((downloaded, downloadedFailure) =>
                            {
                                this.friendLeaderboardDownloadCall = null;
                                if (downloadedFailure)
                                {
                                    this.OnLeaderboardError.Execute();
                                }
                                else
                                {
                                    this.friendScoresDownloaded = true;
                                    this.friendScores           = downloaded;
                                    this.checkLeaderboardsDownloaded();
                                }
                            });
                            this.friendLeaderboardDownloadCall.Set(SteamUserStats.DownloadLeaderboardEntries(found.m_hSteamLeaderboard, ELeaderboardDataRequest.k_ELeaderboardDataRequestFriends, -5, 5));
                        }
                    });
                    this.leaderboardUploadCall.Set(SteamUserStats.UploadLeaderboardScore(found.m_hSteamLeaderboard, ELeaderboardUploadScoreMethod.k_ELeaderboardUploadScoreMethodKeepBest, score, new int[] {}, 0));
                }
            });
            this.leaderboardFindCall.Set(SteamUserStats.FindOrCreateLeaderboard(uuid, ELeaderboardSortMethod.k_ELeaderboardSortMethodAscending, ELeaderboardDisplayType.k_ELeaderboardDisplayTypeTimeMilliSeconds));
        }