public void Handle(int cmd, byte[] data) { switch (cmd) { case MessageConst.Battle.RESP_GAME_INIT: //初始化游戏 Debug.Log("开始初始化游戏..."); RespGameInit respGameInit = ProtobufTool.DeSerialize <RespGameInit>(data); BattleStatus.INSTANCE.respGameInit = respGameInit; PlayerManager.self.statusManager.Switch(BattleStatus.INSTANCE); actions.Enqueue(GameInit); break; case MessageConst.Battle.RESP_MOVE_CHESS: RespMoveChess respMoveChess = ProtobufTool.DeSerialize <RespMoveChess>(data); break; case MessageConst.Battle.RESP_CURRENT_GO_INFO: RespCurrentGoInfo respCurrentGoInfo = ProtobufTool.DeSerialize <RespCurrentGoInfo>(data); break; default: break; } }
private void Awake() { BattleStatus battleStatus = PlayerManager.self.statusManager.currentStatus as BattleStatus; respGameInit = battleStatus.respGameInit; selfPlayerId = PlayerManager.self.player.role.roleUid; foreach (TeamInfo teamInfo in respGameInit.teamInfos) { foreach (PlayerFighter fighter in teamInfo.fighters) { if (fighter.playerId == selfPlayerId) { selfTeamId = teamInfo.teamId; } } } List <CardSprite> sprites = respGameInit.allSprite; Debug.LogFormat("sprite size is {0}", sprites.Count); foreach (CardSprite cardSprite in sprites) { //开始初始化棋牌数据 int type = cardSprite.type; ChessPieceType c = (ChessPieceType)(type - 1); string sitName = cardSprite.x + "" + cardSprite.z; string name = c.ToString(); //Debug.LogFormat(sitName); GameObject sitObj = GameObject.Find(sitName); GameObject gameObj = Resources.Load("prefabs/cardPfb/" + name) as GameObject; gameObj = Instantiate(gameObj); ChessPieceController cpc = gameObj.GetComponent <ChessPieceController>(); cpc.chessPiece = new ChessPiece((TeamID)(cardSprite.team), c, cardSprite.x, cardSprite.z); gameObj.transform.position = sitObj.transform.position; if (selfTeamId == (int)TeamID.HEI) { Quaternion quaternion = gameObj.transform.rotation; gameObj.transform.rotation = Quaternion.Euler(0, quaternion.x, quaternion.z); } Material material = Resources.Load("wujiang/Materials/" + cardSprite.bg) as Material; Texture2D texture = Resources.Load("wujiang/" + cardSprite.texture) as Texture2D; Sprite sprite = Sprite.Create(texture, new Rect(0, 0, texture.width, texture.height), new Vector2(0.5f, 0.5f)); MeshRenderer meshRenderer = gameObj.GetComponent <MeshRenderer>(); meshRenderer.materials[0] = material; foreach (SpriteRenderer spriteRenderer in gameObj.GetComponentsInChildren <SpriteRenderer>()) { spriteRenderer.sprite = sprite; break; } } GameObject heiGameObject = GameObject.Find("heiqi"); if (heiGameObject != null) { heiGameObject.SetActive(false); Destroy(heiGameObject); } GameObject hongqiGameObject = GameObject.Find("hongqi"); if (hongqiGameObject != null) { hongqiGameObject.SetActive(false); Destroy(hongqiGameObject); } if (selfTeamId == (int)TeamID.HEI) { GameObject team1Camera = GameObject.Find("Team1Camera"); if (team1Camera != null) { team1Camera.SetActive(false); Destroy(team1Camera); } Camera camera = Resources.Load("prefabs/Team2Camera") as Camera; Instantiate(camera); } if (selfTeamId == (int)TeamID.HONG) { GameObject team2Camera = GameObject.Find("Team2Camera"); if (team2Camera != null) { team2Camera.SetActive(false); Destroy(team2Camera); } } MessageDispatcher.RegisterHandler(MessageConst.Battle.TYPE, this); //初始化完成,向服务器发送消息 NetManager.SendGameInitDone(); }