Ejemplo n.º 1
0
        public void OnPressedPlay()
        {
            stateLocker.SetActive(true);

            _socket.GetGames((getGamesData) =>
            {
                var availableGame = getGamesData?.games?.FirstOrDefault(g => !g.isStarted);
                if (availableGame != null)
                {
                    _socket.JoinGame(availableGame.id, response =>
                    {
                        PrepareForGameStart(response.game, response.eta);
                    }, () => Debug.LogError($"Join game{availableGame.id} failed"));
                }
                else
                {
                    var gameName = $"{DateTime.Now}";

                    _socket.CreateGame(gameName, (response) =>
                    {
                        PrepareForGameStart(response.game, response.eta);
                    }, () => Debug.LogError("CreateGame failed"));
                }
            }, () => Debug.LogError("GetGames failed"));
        }