/// <summary> /// 得到排行榜传输模型 /// </summary> /// <param name="rankListDto"></param> private void GetRankListDto(RankListDto rankListDto) { if (rankListDto == null) { return; } foreach (var go in listGo) { Destroy(go); } listGo.Clear(); for (int i = 0; i < rankListDto.rankList.Count; i++) { if (rankListDto.rankList[i].UserName == Models.GameModel.userDto.UserName) { GameObject go = Instantiate(go_ItemPre, m_Parent); go.transform.Find("Index/txt_Index").GetComponent <Text>().text = (i + 1).ToString(); go.transform.Find("txt_UserName").GetComponent <Text>().text = "我"; go.transform.Find("txt_CoinCount").GetComponent <Text>().text = rankListDto.rankList[i].CoinCount.ToString(); go.transform.Find("Index/txt_Index").GetComponent <Text>().color = Color.red; go.transform.Find("txt_UserName").GetComponent <Text>().color = Color.red; go.transform.Find("txt_CoinCount").GetComponent <Text>().color = Color.red; listGo.Add(go); } else { GameObject go = Instantiate(go_ItemPre, m_Parent); go.transform.Find("Index/txt_Index").GetComponent <Text>().text = (i + 1).ToString(); go.transform.Find("txt_UserName").GetComponent <Text>().text = rankListDto.rankList[i].UserName; go.transform.Find("txt_CoinCount").GetComponent <Text>().text = rankListDto.rankList[i].CoinCount.ToString(); listGo.Add(go); } } }
/// <summary> /// 客户端获取排行榜信息的请求 /// </summary> /// <param name="client"></param> private void GetRank(ClientPeer client) { SingleExecute.Instance.Exeecute(() => { RankListDto dto = DatabaseManager.GetRankListDto(); client.SendMsg(OpCode.Account, AccountCode.GetRank_SRES, dto); }); }
private void HandleGetRankList(ClientPeer client) { SingleExec.Exec(() => { RankListDto dto = DatabaseManager.GetRankListDto(); client.SendNetMsg(OpCode.account, AccountCode.getRankListSRes, dto); }); }
public static void StartConnect() { rankListDto = new RankListDto(); idClientDic = new Dictionary <int, ClientPeer>(); string conStr = "database=zjhgame;data source=127.0.0.1;port=3306;user=root;pwd=gunxueqiu"; sqlConcect = new MySqlConnection(conStr); sqlConcect.Open(); }
/// <summary> /// 连接数据库 /// </summary> public static void StartConnection() { rankListDto = new RankListDto(); idClientDic = new Dictionary <int, ClientPeer>(); string conStr = "database=golden_fraud;data source=127.0.0.1;port=3306;user=root;pwd=root"; sqlConnection = new MySqlConnection(conStr); sqlConnection.Open(); }
/// <summary> /// 客户端获取排行榜的请求处理 /// </summary> /// <param name="client"></param> private void GetRankList(ClientPeer client) { SingleExecute.Instance.Execute(() => { Console.WriteLine("请求排行榜信息"); RankListDto dto = DatabaseManager.GetRankListDto(); client.SendMsg(OpCode.Account, AccountCode.GetRankList_SRES, dto); Console.WriteLine("发送排行榜信息" + OpCode.Account + AccountCode.GetRankList_SRES); }); }
void GenerateRankList(RankListDto dto) { //先清空排行榜里面的东西,再重新生成一份 foreach (Transform child in scrollViewContentTransform) { Destroy(child.gameObject); } GameObject rankListItemPrefab = ResourceManager.GetRankListItem(); List <RankItemDto> list = dto.list; for (int i = 0; i < list.Count; i++) { RankItemDto item = list[i]; GameObject rankListItem = Instantiate(rankListItemPrefab); rankListItem.GetComponent <RankListItem>().SetInfo(i + 1, item.username, item.coin); rankListItem.transform.SetParent(scrollViewContentTransform); rankListItem.transform.localScale = Vector3.one; } }
/// <summary> /// 得到排行榜传输模型,进行解析 /// </summary> /// <param name="dto"></param> private void GetRankListDto(RankListDto dto) { if (dto == null) { return; } // 先销毁之前的 排行榜 List foreach (var go in listGo) { Destroy(go); } listGo.Clear(); // 清空 排行榜 List 列表 for (int i = 0; i < dto.rankList.Count; i++) { if (dto.rankList[i].name == Models.GameModel.userDto.name) // 如果是自己 { GameObject go = Instantiate(itemPre, parent); go.transform.Find("Index/txtIndex").GetComponent <Text>().text = (i + 1).ToString(); // 排名 go.transform.Find("Index/txtIndex").GetComponent <Text>().color = Color.red; // 排名字体变成红色 go.transform.Find("txtName").GetComponent <Text>().text = "我"; // 将用户名改成我 go.transform.Find("txtName").GetComponent <Text>().color = Color.red; // 用户名字体变成红色 go.transform.Find("txtCoin").GetComponent <Text>().text = Models.GameModel.userDto.coin.ToString(); // 金币数 go.transform.Find("txtCoin").GetComponent <Text>().color = Color.red; // 金币字体变成红色 listGo.Add(go); } else { GameObject go = Instantiate(itemPre, parent); go.transform.Find("Index/txtIndex").GetComponent <Text>().text = (i + 1).ToString(); // 排名 go.transform.Find("txtName").GetComponent <Text>().text = dto.rankList[i].name; // 用户名 go.transform.Find("txtCoin").GetComponent <Text>().text = dto.rankList[i].coin.ToString(); // 金币数 listGo.Add(go); } } }
public static RankListDto GetRankListDto(int maxCount = 10) { MySqlCommand cmd = connection.CreateCommand(); cmd.CommandText = "select username,coin from user_info order by coin desc"; MySqlDataReader reader = cmd.ExecuteReader(); RankListDto resultList = new RankListDto(); RankItemDto item = new RankItemDto(); int count = 0; if (reader.HasRows) { while (reader.Read() && count < maxCount) { item.username = reader.GetString("username"); item.coin = reader.GetInt32("coin"); resultList.list.Add(item); count += 1; } } reader.Close(); return(resultList); }
private void HandleGetRankListSRes(RankListDto dto) { EventCenter.BroadCast(EventType.UISetRankList, dto); }