Exemplo n.º 1
0
    private void OnKcpError(KChannel channel, ErrorCode error)
    {
        Log.Error($"error code:{error}");

        //兼容旧版本时,不考虑是否可链接成功
        //if (error == ErrorCode.ERR_KcpCantConnect)
        //{
        //    if (tcs.Task.IsCompleted)
        //    {
        //        Log.Error("OnKcpError task is completed.");
        //        return;
        //    }

        //    tcs.SetResult(error);

        //    Shutdown();
        //    OnErrorEventHandler?.Invoke(error);
        //}
        if (error == ErrorCode.ERR_SocketError)
        {
            if (!tcs.Task.IsCompleted)
            {
                tcs.SetResult(error);
            }

            Shutdown();
            OnErrorEventHandler?.Invoke(error);
        }
        else
        {
            //非指定错误,执行重连
            Shutdown();
            Reconnect();
        }
    }
Exemplo n.º 2
0
        /// <summary>
        /// 设置支付结果
        /// </summary>
        /// <param name="buf"></param>
        public void SetPaymentResult(string buf)
        {
            m_Log.Debug($"OnPaymentResult: {buf}.");

            PaymentResult result = JsonUtility.FromJson <PaymentResult>(buf);

            m_PaymentTcs.SetResult(result);
        }
Exemplo n.º 3
0
        /// <summary>
        /// 加载手柄二维码
        /// </summary>
        /// <param name="tcs">任务</param>
        /// <param name="url">二维码地址</param>
        /// <returns></returns>
        private IEnumerator InnerLoadGamepadQRCode(LTTaskCompletionSource <Sprite> tcs, string url)
        {
            UnityWebRequest request = UnityWebRequest.Get($"file://{url}");

            request.downloadHandler = new DownloadHandlerTexture(true);
            yield return(request.SendWebRequest());

            if (request.downloadHandler.isDone)
            {
                Texture2D texture = (request.downloadHandler as DownloadHandlerTexture).texture;
                tcs.SetResult(Sprite.Create(texture, new Rect(0, 0, texture.width, texture.height), new Vector2(0.5f, 0.5f)));
            }
            else if (request.isNetworkError || request.isHttpError)
            {
                m_Log.Error("General RQCode Error:" + request.error);
                tcs.SetResult(null);
            }
        }
Exemplo n.º 4
0
        /// <inheritdoc />
        public LTTask <PaymentResult> PaymentAsync(string payid)
        {
            m_PaymentTcs = LTTaskCompletionSource.New <PaymentResult>();

            if (m_BridgeClass == null)
            {
                //如果未接sdk,则模拟一个支付成功的结果
                PaymentResult result = new PaymentResult();
                result.code  = "100";
                result.payid = payid;
                result.text  = "订购成功.";

                m_PaymentTcs.SetResult(result);
            }
            else
            {
                m_BridgeClass.CallStatic("payment", payid, "");
            }

            return(m_PaymentTcs.Task);
        }