gpt4 book ai didi

c# - 使用 Steamworks.NET 包装器时不会触发回调

转载 作者:行者123 更新时间:2023-12-02 13:29:57 30 4
gpt4 key购买 nike

我正在尝试了解如何正确使用 Steamworks.NET C# 包装器,因为我想将它与我的不和谐机器人一起使用。现在,大多数功能都可以使用正常的回调方法。当我尝试使用具有相同回调接口(interface)的三个方法时,我陷入了困境,这三个方法都没有触发回调。因此,在 ISteamMatchmakinServers 接口(interface)中,我想使用 3 个方法 - PlayerDetails、PingServer、ServerRules 来获取使用这些接口(interface)所需的响应 ISteamMatchmakingPingResponse 、ISteamMatchmakingPlayersResponse、ISteamMatchmakingRulesResponse。 Steamworks 官方文档中指出:

You must inherit from the ISteamMatchmakingRulesResponse object to receive this callback.

Callback interface for receiving responses after pinging an individual server.

If you are destructing an object that implements this interface then you should
call CancelServerQuery passing in the handle to the query which is in progress.
Failure to cancel in progress queries when destructing a callback handler may
result in a crash when a callback later occurs.

现在,如果我使用 Unity 及其 Mono 脚本并将接口(interface)放入继承这些方法的 OnEnable 方法中,这些接口(interface)就会被触发。

    public void OnEnable() {
m_ServerListRequest = HServerListRequest.Invalid;
m_ServerQuery = HServerQuery.Invalid;

m_ServerListResponse = new ISteamMatchmakingServerListResponse(OnServerResponded,
OnServerFailedToRespond, OnRefreshComplete);
m_PingResponse = new ISteamMatchmakingPingResponse(OnServerResponded,
OnServerFailedToRespond);
m_PlayersResponse = new ISteamMatchmakingPlayersResponse(OnAddPlayerToList, OnPlayersFailedToRespond,
OnPlayersRefreshComplete);
m_RulesResponse = new ISteamMatchmakingRulesResponse(OnRulesResponded,
OnRulesFailedToRespond, OnRulesRefreshComplete);

}

现在,我的想法是,仅当用户使用 .server 命令时我才需要这些方法,因此我执行与上面相同的操作,只是将继承放在命令调用的开头。然后我触发该方法,获取响应,但这次未调用回调,因此我无法访问信息。我的代码:

public class Commands : ModuleBase {
CSteamID m_Lobby;
private HServerQuery m_ServerQuery;
private ISteamMatchmakingPingResponse m_PingResponse;
private ISteamMatchmakingPlayersResponse m_PlayersResponse;
private ISteamMatchmakingRulesResponse m_RulesResponse;

方法:

[Command("server")]
public async Task Server(int serverNumber)
{
m_ServerListRequest = HServerListRequest.Invalid;
m_ServerQuery = HServerQuery.Invalid;

m_ServerListResponse = new ISteamMatchmakingServerListResponse(OnServerResponded,
OnServerFailedToRespond, OnRefreshComplete);
m_PingResponse = new ISteamMatchmakingPingResponse(OnServerResponded,
OnServerFailedToRespond);
m_PlayersResponse = new ISteamMatchmakingPlayersResponse(OnAddPlayerToList, OnPlayersFailedToRespond,
OnPlayersRefreshComplete);
m_RulesResponse = new ISteamMatchmakingRulesResponse(OnRulesResponded,
OnRulesFailedToRespond, OnRulesRefreshComplete);

if (serverNumber == 422) {
m_Lobby = (CSteamID)90130468311942151;
}

回调位于命令类中

private void OnServerResponded(HServerListRequest hRequest, int iServer) {
Debug.Log("OnServerResponded: " + hRequest + " - " + iServer);
}

private void OnServerFailedToRespond(HServerListRequest hRequest, int iServer) {
Debug.Log("OnServerFailedToRespond: " + hRequest + " - " + iServer);
}

private void OnRefreshComplete(HServerListRequest hRequest, EMatchMakingServerResponse response) {
Debug.Log("OnRefreshComplete: " + hRequest + " - " + response);
}

// ISteamMatchmakingPingResponse
private void OnServerResponded(gameserveritem_t gsi) {
Debug.Log("OnServerResponded: " + gsi + "\n" + GameServerItemFormattedString(gsi));
}

private void OnServerFailedToRespond() {
Debug.Log("OnServerFailedToRespond");
}

// ISteamMatchmakingPlayersResponse
private void OnAddPlayerToList(string pchName, int nScore, float flTimePlayed) {
Debug.Log("OnAddPlayerToList: " + pchName + " - " + nScore + " - " + flTimePlayed);
}

private void OnPlayersFailedToRespond() {
Debug.Log("OnPlayersFailedToRespond");
}

private void OnPlayersRefreshComplete() {
Debug.Log("OnPlayersRefreshComplete");
}

// ISteamMatchmakingRulesResponse
private void OnRulesResponded(string pchRule, string pchValue) {
Debug.Log("OnRulesResponded: " + pchRule + " - " + pchValue);
}

private void OnRulesFailedToRespond() {
Debug.Log("OnRulesFailedToRespond");
}

private void OnRulesRefreshComplete() {
Debug.Log("OnRulesRefreshComplete");
}

最佳答案

通过创建另一个每 50 毫秒运行一次的方法来使其工作,该方法调用 SteamAPI.RunCallbacks(); 现在可以正确调用回调

关于c# - 使用 Steamworks.NET 包装器时不会触发回调,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58958419/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com