Ejemplo n.º 1
0
    private async UniTaskVoid ConnectAsync()
    {
        var result = await NetP2pUnity.Instance.ConnectAsync(TimeSpan.FromSeconds(10));

        if (result == true)
        {
            LoginRpc loginRpc    = new LoginRpc(NetP2pUnity.Instance.Client);
            var      loginResult = await loginRpc.Login("AuthedId", null);

            Debug.Log($"Login Result : {loginResult}");
            if (loginResult != 0)
            {
                return;
            }

            var userInfo = await loginRpc.GetUserInfo();

            Debug.Log($"UserName : {userInfo.Name}");

            var writer = NetPool.DataWriterPool.Alloc();
            try
            {
                writer.Write("join");
                NetP2pUnity.Instance.SendAsync(writer, DeliveryMethod.Tcp);
            }
            finally
            {
                NetPool.DataWriterPool.Free(writer);
            }
        }
        else
        {
            Debug.LogError("Fail to connect server");
        }
    }
Ejemplo n.º 2
0
    private async UniTaskVoid OnLoginAsync(AsyncUnit asyncUnit)
    {
        try
        {
            _loginButton.interactable = false;
            var result = await NetClientGlobal.Instance.Client.ConnectAsync(TimeSpan.FromSeconds(10));

            if (result == true)
            {
                LoginRpc loginRpc    = new LoginRpc(NetClientGlobal.Instance.Client);
                var      loginResult = await loginRpc.Login(SystemInfo.deviceUniqueIdentifier);

                Debug.Log($"Login Result : {loginResult}");
                if (loginResult != 0)
                {
                    return;
                }

                var userInfo = await loginRpc.GetUserInfo();

                Debug.Log($"UserName : {userInfo.Name}");

                var joinResult = await loginRpc.Join();

                Debug.Log($"Join : {joinResult}");

                var purchaseResult = await GameClient.Instance.ShopRpc.PurchaseItem("TestItem");

                Debug.Log($"purchaseResult : {purchaseResult}");
                if (purchaseResult != 1)
                {
                    throw new Exception("Fail to PurchaseItem");
                }

                // Game Scene 으로 이동
                await SceneManager.LoadSceneAsync("Game");
            }
            else
            {
                Debug.LogError("Fail to connect server");
            }
        }
        catch (Exception ex)
        {
            Debug.LogException(ex);
        }
        finally
        {
            if (_loginButton != null)
            {
                _loginButton.interactable = true;
            }
        }
    }
Ejemplo n.º 3
0
 private void OnConnected()
 {
     LoginRpc = new LoginRpc(_client.Client, null, TimeSpan.FromSeconds(10));
     ShopRpc  = new ShopRpc(_client.Client, null, TimeSpan.FromSeconds(10));
 }