コード例 #1
0
ファイル: Controller.cs プロジェクト: xAdamQ/Basra
    public void RestartGame()
    {
        UniTask.Create(async() =>
        {
            try
            {
                await hubConnection.CloseAsync();
            }
            catch (Exception e)
            {
                Debug.Log(e);
            }

            await SceneManager.LoadSceneAsync(0);
        }).Forget(e => throw e);
    }
コード例 #2
0
        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);
        }
コード例 #3
0
 async void OnDestroy()
 {
     await hub?.CloseAsync();
 }
コード例 #4
0
 private async void OnDisable()
 {
     if (_connection != null) await _connection.CloseAsync();
 }