/// <summary> /// 加载进度 /// </summary> /// <param name="response"></param> private void HandleRoomLoadProgressS2C(BufferEntity response) { RoomLoadProgressS2C s2cMSG = ProtobufHelper.FromBytes <RoomLoadProgressS2C>(response.proto); //更新界面 if (s2cMSG.IsBattleStart == true) { ct.Cancel(); for (int i = 0; i < s2cMSG.RolesID.Count; i++) { playerLoadDIC[s2cMSG.RolesID[i]].transform.Find("Progress") .GetComponent <Text>().text = "100%"; } async.allowSceneActivation = true; Close(); } else { //如果还不能进入战斗场景 for (int i = 0; i < s2cMSG.RolesID.Count; i++) { playerLoadDIC[s2cMSG.RolesID[i]].transform.Find("Progress") .GetComponent <Text>().text = $"{s2cMSG.LoadProgress[i]}%"; } } }
/// <summary> /// 更新所有用户的进度 /// </summary> /// <param name="rolesID"></param> /// <param name="progress"></param> public bool UpdateLoadProgress(int rolesID, int progress) { if (isLoadComplete == true) { return(true); } playerProgress[rolesID] = progress; if (isLoadComplete == false) { foreach (var value in playerProgress.Values) { //100 实际的进度 90客户端异步加载场景 0-0.9 if (value < 100) { isLoadComplete = false; return(false); } } //所有玩家都加载完成了 isLoadComplete = true; //告诉所有客户端 都加载完成了 RoomLoadProgressS2C s2cMSG = new RoomLoadProgressS2C(); s2cMSG.IsBattleStart = true; foreach (var item in playerProgress.Keys) { s2cMSG.RolesID.Add(item); s2cMSG.LoadProgress.Add(playerProgress[item]); } Broadcast(1406, s2cMSG); } return(true); }
/// <summary> /// 获取所有用户的加载进度 /// </summary> /// <param name="s2cMSG"></param> public void GetLoadProgress(ref RoomLoadProgressS2C s2cMSG) { foreach (var item in playerProgress.Keys) { s2cMSG.RolesID.Add(item); s2cMSG.LoadProgress.Add(playerProgress[item]); } }
/// <summary> /// 发送了加载进度过来 /// </summary> /// <param name="request"></param> private void HandleRoomLoadProgressC2S(BufferEntity request) { RoomLoadProgressC2S c2sMSG = ProtobufHelper.FromBytes <RoomLoadProgressC2S>(request.proto); RoomLoadProgressS2C s2cMSG = new RoomLoadProgressS2C(); s2cMSG.IsBattleStart = false; PlayerEntity p = PlayerManager.GetPlayerEntityFromSession(request.session); bool result = p.roomEntity.UpdateLoadProgress(p.rolesInfo.RolesID, c2sMSG.LoadProgress); if (result == true) { //所有玩家都已经加载完成了 } else { p.roomEntity.GetLoadProgress(ref s2cMSG); BufferFactory.CreqateAndSendPackage(request, s2cMSG); } }