public void RestartGame() { UniTask.Create(async() => { try { await hubConnection.CloseAsync(); } catch (Exception e) { Debug.Log(e); } await SceneManager.LoadSceneAsync(0); }).Forget(e => throw e); }
public async Task Handler(string message, ConcurrentDictionary <string, InvocationRequestCallBack <object> > requestCallBacks, ConcurrentDictionary <string, InvocationHandlerList> invocationHandlers, HubConnection hubConnection) { _logger.LogDebug($"开始处理CloseMessage, Message:{message}"); var settings = new JsonSerializerSettings { ContractResolver = new CamelCasePropertyNamesContractResolver() }; var BasicInvocationMessage = Newtonsoft.Json.JsonConvert.DeserializeObject <CloseWithError>(message, settings); var error = "服务器关闭了连接"; if (!string.IsNullOrEmpty(BasicInvocationMessage.Error)) { error = $"服务器关闭了连接,message:{BasicInvocationMessage.Error}"; } _logger.LogError(error); await hubConnection.CloseAsync(error); }
async void OnDestroy() { await hub?.CloseAsync(); }
private async void OnDisable() { if (_connection != null) await _connection.CloseAsync(); }