예제 #1
0
    public override void OnReceive(int subCode, object value)
    {
        switch (subCode)
        {
        case AccCode.ACC_LOGIN_SREP:
            SceneMesg sMesg = new SceneMesg(1, () => {
                Debug.Log("场景加载成功");
                UserDto userDto = value as UserDto;
                if (userDto == null)
                {
                    return;
                }
                Dispatch(AreaCode.UI, UIEvent.UI_CHANGE_ID, userDto.Account);
                //TODO 接受返回的数据刷新视图
                Dispatch(AreaCode.UI, UIEvent.UI_REFRESH, userDto);
            });
            Dispatch(AreaCode.SCENE, SceneEvent.SCENE_LOAD, sMesg);
            break;

        case AccCode.ACC_LOGIN_NOACC:
            Dispatch(AreaCode.UI, UIEvent.UI_LOGIN_NOACC, null);
            break;

        case AccCode.ACC_CREATE_SREP:
            SceneMesg sceneMesg = new SceneMesg(1, () => {
                UserDto userDto = value as UserDto;
                if (userDto == null)
                {
                    return;
                }
                if (userDto.Account == "0")
                {
                    return;
                }
                ShowToast.MakeToast("创建成功");
                Dispatch(AreaCode.UI, UIEvent.UI_CHANGE_ID, userDto.Account);
                Dispatch(AreaCode.UI, UIEvent.UI_REFRESH, userDto);
            });
            Dispatch(AreaCode.SCENE, SceneEvent.SCENE_LOAD, sceneMesg);
            break;

        case AccCode.ACC_RELOAD_SREP:
            SceneMesg Mesg = new SceneMesg(1, () => {
                Debug.Log("场景加载成功");
                UserDto userDto = value as UserDto;
                if (userDto == null)
                {
                    return;
                }
                Dispatch(AreaCode.UI, UIEvent.UI_CHANGE_ID, userDto.Account);
                //TODO 接受返回的数据刷新视图
                Dispatch(AreaCode.UI, UIEvent.UI_REFRESH, userDto);
            });
            Dispatch(AreaCode.SCENE, SceneEvent.SCENE_LOAD, Mesg);
            break;

        default:
            break;
        }
    }
예제 #2
0
파일: Login.cs 프로젝트: TNTsama11/CubeWar
 private void onClick()
 {
     if (isConnected)
     {
         string acc = PlayerPrefs.GetString("ID", "0");
         socketMessage.Change(OpCode.ACCOUNT, AccCode.ACC_LOGIN_CREQ, acc);
         Dispatch(AreaCode.NET, 0, socketMessage);
     }
     else
     {
         ShowToast.MakeToast("无法接到服务器");
     }
 }
예제 #3
0
 private void Exit()
 {
     if (isExit)
     {
         Application.Quit();
         NetManager.Instance.OffLine();
     }
     else
     {
         ShowToast.MakeToast("再点一次就退出了");
         isExit = true;
         StartCoroutine(CountDown());
     }
 }
예제 #4
0
 public void Connect()
 {
     ShowToast.MakeToast("尝试连接到服务器");
     try
     {
         socket.Connect(IP, PORT);
         ShowToast.MakeToast("连接服务器成功");
         GameObject.Find("LoginButton").GetComponent <Login>().isConnected = true;
         StartReceive();
     }
     catch (Exception ex)
     {
         // Debug.LogError(ex.Message);
         ShowToast.MakeToast("无法接到服务器");
     }
 }
예제 #5
0
 /// <summary>
 /// 收到数据后回调
 /// </summary>
 /// <param name="ar"></param>
 private void ReceiveCallBack(IAsyncResult ar)
 {
     try
     {
         int    length       = socket.EndReceive(ar);
         byte[] tmpByteArray = new byte[length];
         Buffer.BlockCopy(receiveBuffer, 0, tmpByteArray, 0, length);
         dataCache.AddRange(tmpByteArray);
         if (!isReceiveProcess)
         {
             ProcessReceive();
         }
         StartReceive();
     }
     catch (Exception ex)
     {
         Debug.LogError(ex.Message);
         //断线报错
         //TODO 返回标题界面
         ShowToast.MakeToast("与服务器连接断开");
     }
 }
예제 #6
0
 private void CopyCode()
 {
     GUIUtility.systemCopyBuffer = PlayerPrefs.GetString("ID");
     ShowToast.MakeToast("已复制到剪贴板");
 }