public void OnPlayerDataChanged(LobbyPlayerData playerData) { var existingPlayer = GetOrCreatePlayer(playerData.Id); bool availableCharactersChanged = existingPlayer.Character != playerData.Character; if (availableCharactersChanged) { _availableCharacters.Add(existingPlayer.Character); _availableCharacters.Remove(playerData.Character); } existingPlayer.Character = playerData.Character; existingPlayer.IsReady = playerData.IsReady; int readyPlayers = 0; for (int i = 0; i < Players.Count; i++) { readyPlayers += Players [i].IsReady ? 1 : 0; } IsGameReadyToStart = readyPlayers >= NeedReadyPlayers; OnModelChanged(); if (availableCharactersChanged) { OnModelAvailableCharactersChanged(); } }
public void ApplyModel(LobbyPlayerData playerData, CharacterVisualData visualData) { _model = playerData; _visualData = visualData; RefreshView(); }
public GlobalPlayer(int deviceId, CharacterType characterTypeAssigned) { LobbyPlayerData = new LobbyPlayerData { Id = deviceId, Character = characterTypeAssigned, IsReady = false }; }
public void AddPlayer(LobbyPlayerData playerData) { var existingPlayer = GetOrCreatePlayer(playerData.Id); existingPlayer.Character = playerData.Character; _availableCharacters.Remove(playerData.Character); OnModelChanged(); OnModelAvailableCharactersChanged(); }
public LobbyModel(int playerAmount, int waitingForReadyPlayers) { NeedReadyPlayers = waitingForReadyPlayers; Players = new List <LobbyPlayerData>(playerAmount); for (int i = 0; i < playerAmount; i++) { Players.Add(LobbyPlayerData.CreateEmpty()); } }
public void OnLobbyPlayerDataChanged(LobbyPlayerData player) { var existingPlayer = Model.GetOrCreatePlayer(player.Id); if (existingPlayer == null) { throw new PlayerDoesntExistException(player.Id); } Debug.LogFormat("OnLobbyPlayerDataChanged: {0} -> {1}", existingPlayer, player); Model.OnPlayerDataChanged(player); }
public void OnLobbyPlayerConnected(LobbyPlayerData playerData) { var existingPlayer = Model.GetPlayerByCharacter(playerData.Character); if (existingPlayer != null) { throw new CharacterAlreadyUsedException(playerData.Character); } Debug.LogFormat("OnLobbyPlayerConnected: {0}", playerData); Model.AddPlayer(playerData); }
void UpdateView(RoomInfo[] infos) { if (infos == null) { return; } Debug.LogError("UpdateView infos.Length=" + infos.Length); LobbyPlayerData[] datas = new LobbyPlayerData[0]; for (int i = 0, length = infos.Length; i < length; i++) { var info = infos[i]; if (info._ownerAccountName == _ownerAccountName) { datas = info._lobbyPlayerDatas.ToArray(); break; } } for (int i = 0, length = _rooms.Count; i < length; i++) { Destroy(_rooms[i].gameObject); } _rooms.Clear(); for (int i = 0, length = datas.Length; i < length; i++) { var go = Instantiate(_itemPrefab); go.gameObject.SetActive(true); go.transform.SetParent(_itemContent); go.transform.localScale = Vector3.one; go.data = datas[i]; go._ownerAccountName = _ownerAccountName; _rooms.Add(go); } }