Ejemplo n.º 1
0
        public static Task <SteamUGCDetails[]> QueryAllUGCAsync(UGCQuery eQueryType, MatchingUGCType eMatchingeMatchingUGCTypeFileType, AppId creatorAppId, AppId consumerAppId, uint unPage)
        {
            var tcs         = new TaskCompletionSource <SteamUGCDetails[]>();
            var queryHandle = SteamUGC.CreateQueryAllUGCRequest(eQueryType, eMatchingeMatchingUGCTypeFileType, creatorAppId, consumerAppId, unPage);

            var call = SteamUGC.SendQueryUGCRequest(queryHandle);

            var callback = new CallResult <SteamUGCQueryCompleted>();

            callback.Set(call, (a, b) =>
            {
                var results = new SteamUGCDetails[a.ResultsCount];
                for (uint i = 0; i < a.ResultsCount; i++)
                {
                    SteamUGCDetails details;
                    GetQueryUGCResult(queryHandle, i, out details);
                    results[i] = details;
                }
                tcs.SetResult(results);
            });

            return(tcs.Task);
        }
Ejemplo n.º 2
0
    private IEnumerator UpdateLeaderboard(int timeInMilliseconds, string leaderboardName)
    {
        Debug.Log("updating leaderboard");
        if (!SteamManager.Initialized)
        {
            Debug.Log("steammanager not initialized");
            yield break;
        }

        bool findLeaderboardCallCompleted = false;
        bool error = false;
        bool uploadedScoreCallCompleted = false;

        Steamworks.SteamLeaderboard_t         speedrunLeaderboard = new Steamworks.SteamLeaderboard_t();
        Steamworks.LeaderboardScoreUploaded_t leaderboardScore    = new Steamworks.LeaderboardScoreUploaded_t();

        Steamworks.SteamAPICall_t speedrunLeaderboardSearch = Steamworks.SteamUserStats.FindLeaderboard(leaderboardName);
        Steamworks.CallResult <Steamworks.LeaderboardFindResult_t> findLeaderboardCallResult = Steamworks.CallResult <Steamworks.LeaderboardFindResult_t> .Create();

        findLeaderboardCallResult.Set(speedrunLeaderboardSearch, (leaderboardFindResult, failure) =>
        {
            if (!failure && leaderboardFindResult.m_bLeaderboardFound == 1)
            {
                speedrunLeaderboard = leaderboardFindResult.m_hSteamLeaderboard;
                Debug.Log("speedrunLeaderboard found");
            }
            else
            {
                error = true;
            }

            findLeaderboardCallCompleted = true;
        });

        while (!findLeaderboardCallCompleted)
        {
            yield return(null);
        }

        if (error)
        {
            Debug.Log("Error finding High Score leaderboard.");
            yield break;
        }

        Steamworks.SteamAPICall_t uploadedScoreCall = Steamworks.SteamUserStats.UploadLeaderboardScore(speedrunLeaderboard, Steamworks.ELeaderboardUploadScoreMethod.k_ELeaderboardUploadScoreMethodKeepBest, timeInMilliseconds, new int[0], 0);
        Steamworks.CallResult <Steamworks.LeaderboardScoreUploaded_t> leaderboardScoreUploadedCallResult = Steamworks.CallResult <Steamworks.LeaderboardScoreUploaded_t> .Create();

        leaderboardScoreUploadedCallResult.Set(uploadedScoreCall, (scoreUploadedResult, failure) =>
        {
            if (!failure && scoreUploadedResult.m_bSuccess == 1)
            {
                leaderboardScore = scoreUploadedResult;
                Debug.Log("leaderboardScore found");
            }
            else
            {
                error = true;
            }

            uploadedScoreCallCompleted = true;
        });

        while (!uploadedScoreCallCompleted)
        {
            yield return(null);
        }

        if (error)
        {
            Debug.Log("Error uploading to High Score leaderboard.");
            yield break;
        }

        if (leaderboardScore.m_bScoreChanged == 1)
        {
            Debug.Log(String.Format("New high score! Global rank #{0}.", leaderboardScore.m_nGlobalRankNew));
        }
        else
        {
            Debug.Log(String.Format("A previous score was better. Global rank #{0}.", leaderboardScore.m_nGlobalRankNew));
        }
    }