기계 번역으로 제공되는 번역입니다. 제공된 번역과 원본 영어의 내용이 상충하는 경우에는 영어 버전이 우선합니다.
Amazon GameLift Servers를 Unity 프로젝트에 통합
Unity용 Amazon GameLift Servers SDK를 게임 프로젝트에 통합하여 전체 서버 SDK 기능 세트에 액세스하는 방법을 알아봅니다.
도움말
더 빠른 배포를 위해 Unity용 Amazon GameLift Servers 독립 실행형 플러그인을 사용해 보세요. 최소한의 설정으로 게임 서버를 빠르게 배포할 수 있는 안내 UI 워크플로를 제공하므로 게임 구성 요소를 실제로 사용해 볼 수 있습니다. Amazon GameLift ServersUnity용 플러그인(서버 SDK 5.x)을(를) 참조하세요.
추가 리소스:
Unity용 서버 SDK 설치
GitHub
테스트용 Amazon GameLift Servers Anywhere 플릿 설정
개발 워크스테이션을 Amazon GameLift Servers Anywhere 호스팅 플릿으로 설정하여 Amazon GameLift Servers 통합을 반복적으로 테스트할 수 있습니다. 이 설정을 통해 워크스테이션에서 게임 서버 프로세스를 시작하고, Amazon GameLift Servers에 플레이어 가입 또는 매치메이킹 요청을 보내 게임 세션을 시작하고, 클라이언트를 새 게임 세션에 연결할 수 있습니다. 자체 워크스테이션을 호스팅 서버로 설정하면 Amazon GameLift Servers와의 게임 통합의 모든 측면을 모니터링할 수 있습니다.
워크스테이션 설정에 대한 지침은 Amazon GameLift Servers Anywhere를 사용하는 로컬 테스트 설정 섹션을 참조하여 다음 단계를 완료합니다.
워크스테이션에 대한 사용자 지정 위치를 만듭니다.
새 사용자 지정 위치를 사용하여 Amazon GameLift Servers Anywhere 플릿을 생성합니다. 요청이 성공하면 플릿 ID가 반환됩니다. 나중에 필요하므로 이 값은 기록해 둡니다.
워크스테이션을 새 Anywhere 플릿의 컴퓨팅으로 등록합니다. 고유한 컴퓨팅 이름을 제공하고 워크스테이션의 IP 주소를 지정합니다. 성공하면 이 요청은 WebSocket URL의 형태로 서비스 SDK 엔드포인트를 반환합니다. 나중에 필요하므로 이 값은 기록해 둡니다.
워크스테이션 컴퓨팅을 위한 인증 토큰을 생성합니다. 이 단수명 인증에는 토큰과 만료 날짜가 포함됩니다. 게임 서버는 이를 사용하여 Amazon GameLift Servers 서비스와의 통신을 인증합니다. 워크스테이션 컴퓨팅에 인증을 저장하여 실행 중인 게임 서버 프로세스가 액세스할 수 있도록 합니다.
Amazon GameLift Servers 서버 코드를 Unity 프로젝트에 추가
게임 서버는 Amazon GameLift Servers 서비스와 통신하여 지침을 받고 진행 상태를 보고합니다. 이를 수행하려면 Amazon GameLift Servers 서버 SDK를 사용하는 게임 서버 코드를 추가합니다.
제공된 코드 예제는 기본적인 필수 통합 요소를 보여줍니다. MonoBehavior를 사용하여 Amazon GameLift Servers로 간단한 게임 서버 초기화를 설명합니다. 이 예제에서는 테스트를 위해 게임 서버가 Amazon GameLift Servers Anywhere 플릿에서 실행된다고 가정합니다. 여기에는 다음과 같은 코드가 포함됩니다.
-
Amazon GameLift Servers API 클라이언트를 초기화합니다. 이 샘플은 Anywhere 플릿 및 컴퓨팅용 서버 파라미터가 있는
InitSDK()버전을 사용합니다. 이전 주제 테스트용 Amazon GameLift Servers Anywhere 플릿 설정에서 정의한 대로 WebSocket URL, 플릿 ID, 컴퓨팅 이름(호스트 ID) 및 인증 토큰을 사용합니다. -
OnStartGameSession,OnProcessTerminate,onHealthCheck를 포함한 Amazon GameLift Servers 서비스의 요청에 응답하는 콜백 함수를 구현합니다. -
지정된 포트와 함께 ProcessReady()를 호출하여 프로세스가 게임 세션을 호스팅할 준비가 되면 Amazon GameLift Servers 서비스에 알립니다.
제공된 샘플 코드는 Amazon GameLift Servers 서비스와의 통신을 설정합니다. 또한 Amazon GameLift Servers 서비스의 요청에 응답하는 콜백 함수 집합을 구현합니다. 각 함수와 코드가 수행하는 작업에 대한 자세한 내용은 서버 프로세스 초기화를 참조하세요. 이 코드에 사용된 SDK 작업 및 데이터 유형에 대한 자세한 내용은 Amazon GameLift Servers용 C# 서버 SDK 5.x - 작업 섹션을 참조하세요.
샘플 코드는 게임 서버에 Amazon GameLift Servers 추가에 설명된 대로 필요한 기능을 추가하는 방법을 보여줍니다. 서버 SDK 작업에 대한 자세한 내용은 Amazon GameLift Servers용 C# 서버 SDK 5.x - 작업 섹션을 참조하세요.
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); } } }
다음 단계
이제 Amazon GameLift Servers를 사용하여 호스팅하는 데 필요한 최소 기능으로 게임 서버 빌드를 준비했으므로 다음 단계를 고려하세요.
-
테스트 및 개발을 위해 통합 게임 서버를 배포합니다. Anywhere 플릿을 사용하면 로컬 시스템을 호스팅 리소스로 설정하고 이를 사용하여 게임 서버 및 게임 클라이언트 연결을 테스트할 수 있습니다. 클라우드 기반 호스팅의 경우 관리형 EC2 또는 관리형 컨테이너 플릿에 게임 서버를 배포합니다. 지침에 대해서는 다음 주제를 참조하세요.
-
선택적 기능을 추가하여 게임 서버 통합을 사용자 지정합니다. 예를 들어 고유한 플레이어 IDs로 플레이어 세션을 추가하거나, 매치메이킹 채우기를 설정하거나, 다른 AWS 리소스(예: 데이터베이스 또는 콘텐츠 스토리지 서비스)에 대한 게임 서버 액세스를 관리할 수 있습니다. 지침에 대해서는 다음 주제를 참조하세요.
-
게임 클라이언트 구성 요소를 사용자 지정하여 게임 세션을 요청하고, 연결 정보를 수신하며, 게임 서버에 직접 연결하여 게임을 플레이합니다. 지침에 대해서는 다음 주제를 참조하세요.