/// <summary> /// 设置和服务器连接交互和回调方法 /// </summary> private void ConnectToUDPServer() { if (udpClient.GetServerIP() != string.Empty) { udpClient.connect(udpClient.GetServerIP(), StaticManager.serverPort, clientPort); udpClient.On(StaticManager.pong_receivePackName, OnPongMsg); udpClient.On(StaticManager.joinSuccess_receivePackName, OnJoinGame); udpClient.On(StaticManager.userDisconnect_receivePackName, OnUserDisconnected); } }
/// <summary> /// Connect client to TicTactoeServer.cs /// </summary> public void ConnectToUDPServer() { if (udpClient.GetServerIP() != string.Empty) { Debug.Log("执行相应ui方法"); //connect to TicTacttoeServer udpClient.connect(udpClient.GetServerIP(), serverPort, clientPort); udpClient.On("PONG", OnPrintPongMsg); udpClient.On("JOIN_SUCCESS", OnJoinGame); udpClient.On("START_GAME", OnStartGame); udpClient.On("UPDATE_BOARD", OnUpdateBoard); udpClient.On("GAME_OVER", OnGameOver); udpClient.On("USER_DISCONNECTED", OnUserDisconnected); } }
//***************************************** Reciving Client Data *****************************************// /// <summary> /// Connect client to any UDP server. /// </summary> public void ConnectToUDPServer(int _serverPort, int _clientPort) { if (udpClient.GetServerIP() != string.Empty) { //connect to udp server udpClient.connect(udpClient.GetServerIP(), _serverPort, _clientPort); //The On method in simplistic terms is used to map a method name to an annonymous function. udpClient.On("SELECTSUIT", OnSelectingSuit); udpClient.On("SUITSELECTED", OnSuitSelected); udpClient.On("GOTACARD", OnGotCard); udpClient.On("GOTCHAL", onGotChal); udpClient.On("CHALDONE", onChalDone); udpClient.On("SHOWCARD", OnShowCard); udpClient.On("CHALSUIT", OnSetChalSuit); udpClient.On("GOTTHROW", OnGotThrow); udpClient.On("THROWDONE", OnThrowDone); udpClient.On("PONG", OnPrintPongMsg); udpClient.On("JOIN_SUCCESS", OnJoinGame); udpClient.On("SPAWN_PLAYER", OnSpawnPlayer); udpClient.On("UPDATE_MOVE", OnUpdatePosition); udpClient.On("USER_DISCONNECTED", OnUserDisconnected); } }