【发布时间】:2020-04-08 08:26:27
【问题描述】:
我正在 Unity 上开发 VR 游戏,SignalR 正在使用我的 Hub 中的所有方法。
问题是一种方法没有按预期工作。该方法应在游戏结束时返回有关游戏的一些信息,但我收到此错误:
Failed to invoke 'SessionReport' due to an error on the server.
但如果我尝试在游戏开始时调用该方法,它会按预期工作。
这是 Unity 中用于调用我的方法“SessionReport”的代码。
public async static void SendReportInfo()
{
HubConnection hubConnection = SignalRInitConnection.hubConnection;
if (hubConnection != null && hubConnection.State == HubConnectionState.Connected)
{
Debug.Log("SignalR: Method SendReportInfo invoked");
try
{
await hubConnection.InvokeAsync("SessionReport", MapStats.riskHistory, MapStats.scoreHistory, MapStats.envHistory, MapStats.difficultyLvlByEnv, MapStats.mapNameByEnv);
}
catch(Exception e)
{
Debug.Log("EXCEPTION SESSION REPORT:" + e.Message);
}
}
else
{
Debug.Log("SignalR: hubCon is ko for SendReportInfo");
}
}
这是我的 SignalR Hub 中的方法:
public void SessionReport(List<List<Risk>> riskHistory, List<int> scoreHistory, List<int> envHistory, List<int> difficultyLvlByEnv, List<string> mapNameByEnv)
{
//Insert into DB
Console.WriteLine("Nice session report there.");
}
当我在游戏结束时调用 'SessionReport' 方法时,与 Hub 的连接仍然建立。
为什么“SessionReport”方法在游戏开始时有效,但在结束时无效?
【问题讨论】:
标签: unity3d signalr signalr-hub signalr.client