Beispiel #1
0
        public async Task Connect()
        {
            _hubConnection = new HubConnectionBuilder().WithUrl(_hubUri).Build();
            _hubConnection.On(GameEvents.GameSessionStarted, () => GameSessionStarted?.Invoke());
            _hubConnection.On <bool>(nameof(IsSessionOpen), (isOpen) => IsSessionOpen?.Invoke(isOpen));
            _hubConnection.On(GameEvents.PlayerCreated, () => PlayerCreated?.Invoke());
            _hubConnection.On <ICollection <string> >(nameof(IncomingPlayers), (players) => IncomingPlayers?.Invoke(players));
            _hubConnection.On(GameEvents.GameStarted, () => GameStarted?.Invoke());
            _hubConnection.On <int>(GameEvents.TimeElapsed, countDownSeconds => TimeElapsed?.Invoke(countDownSeconds));
            _hubConnection.On(GameEvents.GameStopped, () => GameStopped?.Invoke());
            _hubConnection.On <int>(GameEvents.RightAnswer, newScore => SentRightAnswer?.Invoke(newScore));
            _hubConnection.On <int>(GameEvents.WrongAnswer, newScore => SentWrongAnswer?.Invoke(newScore));
            _hubConnection.On(GameEvents.RoundEnded, () => RoundEnded?.Invoke());
            _hubConnection.On <string>(GameEvents.Question, question => QuestionSent?.Invoke(question));
            _hubConnection.On <AnswerAndPlayers>(GameEvents.AnswerAndPlayers, answerAndPlayers => GotAnswerAndPlayers?.Invoke(answerAndPlayers));
            _hubConnection.On(GameEvents.NextRoundStarted, () => NextRoundStarted?.Invoke());

            await _hubConnection.StartAsync();
        }
 //Respond to new game session activation request. GameLift sends activation request
 //to the game server along with a game session object containing game properties
 //and other settings. Once the game server is ready to receive player connections,
 //invoke GameLiftServerAPI.ActivateGameSession()
 private void OnStartGameSession(GameSession gameSession)
 {
     Debug.Log(":) GAMELIFT SESSION REQUESTED"); //And then do stuff with it maybe.
     try {
         //Notifies the GameLift service that the server process has activated a game session and is now ready to
         //receive player connections. This action should be called as part of the onStartGameSession() callback
         //function, after all game session initialization has been completed.
         var outcome = GameLiftServerAPI.ActivateGameSession();
         if (outcome.Success)
         {
             Debug.Log(":) GAME SESSION ACTIVATED");
             GameSessionStarted?.Invoke(this, gameSession);
             TerminateIdleGameSession().Forget();
         }
         else
         {
             Debug.Log($":( GAME SESSION ACTIVATION FAILED. ActivateGameSession() returned {outcome.Error}");
         }
     }
     catch (Exception e) {
         Debug.Log(
             $":( GAME SESSION ACTIVATION FAILED. ActivateGameSession() exception \n{e.Message}");
     }
 }
Beispiel #3
0
 public void OnGameSessionStarted(IGameSession gameSession)
 {
     GameSessionStarted?.Invoke(gameSession);
 }