我试图在我的应用程序(使用C#编写的游戏,使用SteamWorks.NET并基于XNA的游戏)中包含排行榜。Steam已正确初始化。在游戏开始时,我致电:SteamAPICall_t hSteamAPICall = SteamUserStats.FindLeaderboard("Most active beta testers");leaderboard_BetaTesters_ResultFindLeaderboard = Callback<LeaderboardFindResult_t>.Create(OnLeaderboardFindResult_BetaTesters);使用static private void OnLeaderboardFindResult_BetaTesters(LeaderboardFindResult_t pCallback){// See if we encountered an error during the callif (pCallback.m_bLeaderboardFound == 0) { Warning.Happened("Leaderboard could not be found / accessed"); return; }else { Write.Text("Steam leaderboad connected"); } leaderboard_BetaTesters = pCallback.m_hSteamLeaderboard;}在每个Update()中,我都调用:if (SystemLogic.SteamInitSuccessul()) SteamAPI.RunCallbacks();但是,永远不会调用OnLeaderboardFindResult_BetaTesters。我究竟做错了什么? 最佳答案 我知道这是一个老问题,但是我现在有一个相同的问题。当我尝试使用Steamworks.NET在Unity上实现Steam排行榜时,我遇到了同样的问题。最后,我从原始的Steamworks C++示例项目中获得了它的工作。 (Steamworks.NET的文档确实很差,就像原始的Steamworks c++一样,因此您必须检查Steamworks c++示例项目以查看如何使用它)您有一个错误,必须使用“CallResult ”类而不是“Callback ”类。以下代码使我可以将Unity上的乐谱上传到SteamLeaderboard:using UnityEngine;using Steamworks;using System.Collections;using System.Threading;public class SteamLeaderboards : MonoBehaviour{ private const string s_leaderboardName = "StoryMode"; private const ELeaderboardUploadScoreMethod s_leaderboardMethod = ELeaderboardUploadScoreMethod.k_ELeaderboardUploadScoreMethodKeepBest; private static SteamLeaderboard_t s_currentLeaderboard; private static bool s_initialized = false; private static CallResult<LeaderboardFindResult_t> m_findResult = new CallResult<LeaderboardFindResult_t>(); private static CallResult<LeaderboardScoreUploaded_t> m_uploadResult = new CallResult<LeaderboardScoreUploaded_t>(); public static void UpdateScore(int score) { if (!s_initialized) { UnityEngine.Debug.Log("Can't upload to the leaderboard because isn't loadded yet"); } else { UnityEngine.Debug.Log("uploading score(" + score + ") to steam leaderboard(" + s_leaderboardName + ")"); SteamAPICall_t hSteamAPICall = SteamUserStats.UploadLeaderboardScore(s_currentLeaderboard, s_leaderboardMethod, score, null, 0); m_uploadResult.Set(hSteamAPICall, OnLeaderboardUploadResult); } } public static void Init() { SteamAPICall_t hSteamAPICall = SteamUserStats.FindLeaderboard(s_leaderboardName); m_findResult.Set(hSteamAPICall, OnLeaderboardFindResult); InitTimer(); } static private void OnLeaderboardFindResult(LeaderboardFindResult_t pCallback, bool failure) { UnityEngine.Debug.Log("STEAM LEADERBOARDS: Found - " + pCallback.m_bLeaderboardFound + " leaderboardID - " + pCallback.m_hSteamLeaderboard.m_SteamLeaderboard); s_currentLeaderboard = pCallback.m_hSteamLeaderboard; s_initialized = true; } static private void OnLeaderboardUploadResult(LeaderboardScoreUploaded_t pCallback, bool failure) { UnityEngine.Debug.Log("STEAM LEADERBOARDS: failure - " + failure + " Completed - " + pCallback.m_bSuccess + " NewScore: " + pCallback.m_nGlobalRankNew + " Score " + pCallback.m_nScore + " HasChanged - " + pCallback.m_bScoreChanged); } private static Timer timer1; public static void InitTimer() { timer1 = new Timer(timer1_Tick, null,0,1000); } private static void timer1_Tick(object state) { SteamAPI.RunCallbacks(); }}*我已经对该代码进行了数次编辑而没有对其进行编译,并且可能包含任何语法错误,但是实现应该没问题**还请记住,此代码已在Unity 4上使用,但是Unity类仅用于“控制台日志”消息和最后两个方法“每隔x毫秒调用SteamAPI.RunCallbacks()方法”关于c# - 如何在Steamworks.NET中做排行榜?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/37842524/ 10-13 06:07