private void MoveTo(GameObject sit) { BattlePoint fromPoint = new BattlePoint() { x = pickCpc.chessPiece.x, z = pickCpc.chessPiece.z }; string name = sit.name; int _x = Convert.ToInt32(name.Substring(0, 1)); int _z = Convert.ToInt32(name.Substring(1, 1)); Debug.LogFormat("棋子移动目的地[{0},{1}]", _x, _z); BattlePoint toPoint = new BattlePoint() { x = _x, z = _z }; MoveChess moveChess = new MoveChess() { fromPoint = fromPoint, toPoint = toPoint }; NetManager.SendMoveChess(moveChess); }
static public void SendMoveChess(MoveChess moveChess) { MarsMessage marsMessage = new MarsMessage() { messageType = MessageConst.Battle.TYPE, cmd = MessageConst.Battle.REQ_MOVE_CHESS, data = ProtobufTool.Serialize(moveChess) }; clientSocket.Send(marsMessage); }
public void ReceiveChessMove(RespMoveChess respMoveChess) { long roleUid = respMoveChess.roleUid; MoveChess moveChess = respMoveChess.moveChess; string toSitName = moveChess.toPoint.x + "" + moveChess.toPoint.z; GameObject toSit = GameObject.Find(toSitName); string fromSitName = moveChess.fromPoint.x + "" + moveChess.fromPoint.z; Debug.LogFormat("收到服务器移动信息,from={0},to={1}", fromSitName, toSitName); GameObject fromSit = GameObject.Find(fromSitName); SitController sitController = fromSit.GetComponent <SitController>(); GameObject pickObject = sitController.chessPieceObj; ChessPieceController pickCpc = pickObject.GetComponent <ChessPieceController>(); SitController sitc = toSit.GetComponent <SitController>(); if (sitc.chessPieceObj != null) { //把该位置原来的棋子注销 Destroy(sitc.chessPieceObj); } pickCpc.MoveTo(toSit); sitc.chessPieceObj = pickCpc.gameObject; ClearState(); }