Integrazione Amazon GameLift Servers in un progetto Unity - Amazon GameLift Servers

Le traduzioni sono generate tramite traduzione automatica. In caso di conflitto tra il contenuto di una traduzione e la versione originale in Inglese, quest'ultima prevarrà.

Integrazione Amazon GameLift Servers in un progetto Unity

Scopri come integrare l'Amazon GameLift ServersSDK for Unity nei tuoi progetti di gioco per accedere al set completo di funzionalità SDK del server.

Suggerimento

Per una distribuzione più rapida, prova il plug-in Amazon GameLift Servers standalone per Unity. Fornisce flussi di lavoro guidati per l'interfaccia utente per implementare rapidamente il server di gioco con una configurazione minima, in modo da poter provare i componenti del gioco in azione. Consultare Amazon GameLift Serversplugin per Unity (server SDK 5.x).

Risorse aggiuntive:

Installa il server SDK for Unity

Scarica l'open source Amazon GameLift Servers per Unity da. GitHub I file readme del repository contengono i prerequisiti e le istruzioni di installazione.

Configura una flotta Amazon GameLift Servers Anywhere per i test

Puoi configurare la tua workstation di sviluppo come flotta di hosting Amazon GameLift Servers Anywhere per testare in modo iterativo la tua Amazon GameLift Servers integrazione. Con questa configurazione, puoi avviare i processi del server di gioco sulla tua workstation, inviare richieste di iscrizione ai giocatori o di matchmaking per Amazon GameLift Servers avviare sessioni di gioco e connettere i client alle nuove sessioni di gioco. Con la tua workstation configurata come server di hosting, puoi monitorare tutti gli aspetti dell'integrazione del gioco con. Amazon GameLift Servers

Per istruzioni sulla configurazione della workstation, consulta Configura i test locali con Amazon GameLift Servers Ovunque i seguenti passaggi:

  1. Crea una posizione personalizzata per la tua workstation.

  2. Crea una flotta Amazon GameLift Servers Anywhere con la tua nuova posizione personalizzata. In caso di successo, questa richiesta restituisce un ID della flotta. Prendi nota di questo valore, poiché ti servirà in seguito.

  3. Registra la tua workstation come computer nella nuova flotta Anywhere. Fornisci un nome di elaborazione univoco e specifica l'indirizzo IP della tua workstation. In caso di successo, questa richiesta restituisce un endpoint SDK del servizio, sotto forma di URL. WebSocket Prendi nota di questo valore, poiché ti servirà in seguito.

  4. Genera un token di autenticazione per il calcolo della tua workstation. Questa autenticazione di breve durata include il token e una data di scadenza. Il server di gioco lo utilizza per autenticare la comunicazione con il Amazon GameLift Servers servizio. Archivia l'autenticazione sul computer della tua workstation in modo che i processi del server di gioco in esecuzione possano accedervi.

Aggiungi il codice Amazon GameLift Servers del server al tuo progetto Unity

Il tuo server di gioco comunica con il Amazon GameLift Servers servizio per ricevere istruzioni e segnalare lo stato in corso. A tale scopo, aggiungi il codice del server di gioco che utilizza l'SDK del Amazon GameLift Servers server.

L'esempio di codice fornito illustra gli elementi di integrazione di base richiesti. Usa a MonoBehavior per illustrare una semplice inizializzazione del server di gioco con. Amazon GameLift Servers L'esempio presuppone che il server di gioco funzioni su una flotta Amazon GameLift Servers Anywhere per i test. Include codice per:

  • Inizializza un client Amazon GameLift Servers API. L'esempio utilizza la versione InitSDK() con parametri del server per la flotta e l'elaborazione di Anywhere. Utilizza l' WebSocket URL, l'ID della flotta, il nome di calcolo (ID host) e il token di autenticazione, come definito nell'argomento precedente. Configura una flotta Amazon GameLift Servers Anywhere per i test

  • Implementa le funzioni di callback per rispondere alle richieste del Amazon GameLift Servers servizio, tra cui OnStartGameSessionOnProcessTerminate, e. onHealthCheck

  • Chiama ProcessReady () con una porta designata per avvisare il Amazon GameLift Servers servizio quando il processo è pronto per ospitare sessioni di gioco.

Il codice di esempio fornito stabilisce la comunicazione con il Amazon GameLift Servers servizio. Implementa inoltre una serie di funzioni di callback che rispondono alle richieste del servizio. Amazon GameLift Servers Per ulteriori informazioni su ciascuna funzione e sul funzionamento del codice, consulta Inizializzare il processo del server. Per ulteriori informazioni sulle azioni SDK e sui tipi di dati utilizzati in questo codice, leggi. SDK 5.x per server C# per Amazon GameLift Servers -- Azioni

Il codice di esempio mostra come aggiungere la funzionalità richiesta, come descritto in Aggiungi Amazon GameLift Servers al tuo server di gioco. Per ulteriori informazioni sulle azioni dell'SDK del server, consultaSDK 5.x per server C# per Amazon GameLift Servers -- Azioni.

using System.Collections.Generic; using Aws.GameLift.Server; using UnityEngine; public class ServerSDKManualTest : MonoBehaviour { //This example is a simple integration that initializes a game server process //that is running on an Amazon GameLift Servers Anywhere fleet. void Start() { //Identify port number (hard coded here for simplicity) the game server is listening on for player connections var listeningPort = 7777; //WebSocketUrl from RegisterHost call var webSocketUrl = "wss://us-west-2.api.amazongamelift.com"; //Unique identifier for this process var processId = "myProcess"; //Unique identifier for your host that this process belongs to var hostId = "myHost"; //Unique identifier for your fleet that this host belongs to var fleetId = "myFleet"; //Authorization token for this host process var authToken = "myAuthToken"; //Server parameters are required for an Amazon GameLift Servers Anywhere fleet. //They are not required for an Amazon GameLift Servers managed EC2 fleet. ServerParameters serverParameters = new ServerParameters( webSocketUrl, processId, hostId, fleetId, authToken); //InitSDK establishes a local connection with an Amazon GameLift Servers agent //to enable further communication. var initSDKOutcome = GameLiftServerAPI.InitSDK(serverParameters); if (initSDKOutcome.Success) { //Implement callback functions ProcessParameters processParameters = new ProcessParameters( //Implement OnStartGameSession callback (gameSession) => { //Amazon GameLift Servers sends a game session activation request to the game server //with game session object containing game properties and other settings. //Here is where a game server takes action based on the game session object. //When the game server is ready to receive incoming player connections, //it invokes the server SDK call ActivateGameSession(). GameLiftServerAPI.ActivateGameSession(); }, (updateGameSession) => { //Amazon GameLift Servers sends a request when a game session is updated (such as for //FlexMatch backfill) with an updated game session object. //The game server can examine matchmakerData and handle new incoming players. //updateReason explains the purpose of the update. }, () => { //Implement callback function OnProcessTerminate //Amazon GameLift Servers invokes this callback before shutting down the instance hosting this game server. //It gives the game server a chance to save its state, communicate with services, etc., //and initiate shut down. When the game server is ready to shut down, it invokes the //server SDK call ProcessEnding() to tell Amazon GameLift Servers it is shutting down. GameLiftServerAPI.ProcessEnding(); }, () => { //Implement callback function OnHealthCheck //Amazon GameLift Servers invokes this callback approximately every 60 seconds. //A game server might want to check the health of dependencies, etc. //Then it returns health status true if healthy, false otherwise. //The game server must respond within 60 seconds, or Amazon GameLift Servers records 'false'. //In this example, the game server always reports healthy. return true; }, //The game server gets ready to report that it is ready to host game sessions //and that it will listen on port 7777 for incoming player connections. listeningPort, new LogParameters(new List<string>() { //Here, the game server tells Amazon GameLift Servers where to find game session log files. //At the end of a game session, Amazon GameLift Servers uploads everything in the specified //location and stores it in the cloud for access later. "/local/game/logs/myserver.log" })); //The game server calls ProcessReady() to tell Amazon GameLift Servers it's ready to host game sessions. var processReadyOutcome = GameLiftServerAPI.ProcessReady(processParameters); if (processReadyOutcome.Success) { print("ProcessReady success."); } else { print("ProcessReady failure : " + processReadyOutcome.Error.ToString()); } } else { print("InitSDK failure : " + initSDKOutcome.Error.ToString()); } } void OnApplicationQuit() { //Make sure to call GameLiftServerAPI.ProcessEnding() and GameLiftServerAPI.Destroy() before terminating the server process. //These actions notify Amazon GameLift Servers that the process is terminating and frees the API client from memory. GenericOutcome processEndingOutcome = GameLiftServerAPI.ProcessEnding(); GameLiftServerAPI.Destroy(); if (processEndingOutcome.Success) { Environment.Exit(0); } else { Console.WriteLine("ProcessEnding() failed. Error: " + processEndingOutcome.Error.ToString()); Environment.Exit(-1); } } }

Passaggi successivi

Ora che hai preparato una build di server di gioco con le funzionalità minime richieste per l'hostingAmazon GameLift Servers, considera questi potenziali passaggi successivi: