public void Update(bool refreshAgents = false) // Update the session { MObjects.SessionUpdate mObject = new MObjects.SessionUpdate(); int _c = agents.Count; mObject.isStarted = isStarted; mObject.isKilled = killed; mObject.mapId = MapLoader.maps[map].clientSceneName; mObject.maxRound = MapLoader.maps[map].roundCount; mObject.round = (ushort)Mathf.Clamp(round, 1, mObject.maxRound); mObject.isStarting = (!isStarted && agents.Count >= MapLoader.maps [map].minPlayers); mObject.teamSize = teamsize; mObject.seconds = (ushort)Mathf.RoundToInt(time - Time.time); bool playersFull = (agents.FindAll(x => x.heroType == HeroType.Player).Count >= MapLoader.maps[map].maxPlayers); for (int i = 0; i < _c; i++) { if (agents[i].user != null && NetworkServer.connections.Contains(agents[i].user)) { mObject.canAddBots = (i == 0 && !isStarted && canAddBots && agents.Count < MapLoader.maps[map].minPlayers && !playersFull && !killed); // send the mobject NetworkServer.SendToClient(agents[i].user.connectionId, MTypes.SessionUpdate, mObject); } if (refreshAgents) { agents [i].AgentInfo(); } } }
public void OnSessionUpdate(NetworkMessage netMsg) { sessionUpdate = netMsg.ReadMessage <MObjects.SessionUpdate>(); isInSession = true; panel_Loading.Open(false); panel_Lobby.Open(false); if (!sessionStarted && sessionUpdate.isStarted) { panel_GameStart.Open(); } panel_Session.Open(!sessionUpdate.isStarted); panel_Game.Open(sessionUpdate.isStarted); panel_AddBot.Open(sessionUpdate.canAddBots); panel_Heroes.Open(!sessionUpdate.isStarted); menuEffect.SetActive(!sessionUpdate.isStarted); panel_Skills.Open(true); panel_Leveling.Open(true); Text_Round.text = sessionUpdate.round + " / " + sessionUpdate.maxRound; if (sessionUpdate.round != round) { panel_RoundStart.GetComponentInChildren <Text>().text = (sessionUpdate.maxRound == sessionUpdate.round) ? Language.GetText(58) : (Language.GetText(4) + sessionUpdate.round); panel_RoundStart.Open(); round = sessionUpdate.round; } panel_Leave.Open(); sessionStarted = sessionUpdate.isStarted; /* * SESSION INFO RECEIVED * */ System.Text.StringBuilder sb = new System.Text.StringBuilder(); if (sessionUpdate.isKilled) { sb.Append("<size=33>" + Language.GetText(42)); } else if (sessionUpdate.isStarted) { if (sessionUpdate.round == sessionUpdate.maxRound) { sb.Append(Language.GetText(17) + ": <size=22>"); } else { sb.Append(Language.GetText(18) + ": <size=18>"); } } else if (!sessionUpdate.isStarting) { sb.Append(Language.GetText(19) + ": <size=18>"); } else { sb.Append(Language.GetText(20) + "... <size=24>"); } sb.Append(sessionUpdate.seconds + " </size>"); panel_Counter.Open(); panel_Counter.GetComponentInChildren <Text>().text = sb.ToString(); if (currentMap != sessionUpdate.mapId) { currentMap = sessionUpdate.mapId; currentMapId = (ushort)MapLoader.maps.FindIndex(x => x.name.Split('@')[0] == sessionUpdate.mapId); SceneManager.LoadScene(currentMap); } }