Amazon GameLift를 Unity 프로젝트에 통합 - 아마존 GameLift

기계 번역으로 제공되는 번역입니다. 제공된 번역과 원본 영어의 내용이 상충하는 경우에는 영어 버전이 우선합니다.

Amazon GameLift를 Unity 프로젝트에 통합

이 주제에서는 Amazon GameLift Unity용 C#Server SDK 플러그인을 설정하고 이를 게임 프로젝트에 통합하는 방법에 대해 설명합니다.

추가 리소스:

필수 조건

Amazon GameLift Unity용 C# Server SDK 플러그인을 사용하려면 다음 구성 요소가 필요합니다.

  • 플러그인이 지원하는 개발 환경 및 Unity 편집기 버전(Amazon을 통한 개발 지원 GameLift 참조). Unity 버전에 대한 자세한 내용은 Unity 문서의 Unity용 시스템 요구 사항을 참조하세요.

  • Unity 패키지용 Amazon GameLift Server SDK 플러그인. 이 패키지에는 C#용 Server SDK 5+가 포함되어 있습니다. 패키지는 다음 사이트에서 다운로드할 수 있습니다. Amazon GameLift 시작하기.

  • 타사의 범위를 지정하는 레지스트리 UnityNuGet입니다. 이 도구는 타사 DLL을 관리합니다. 자세한 내용은 UnityNuGet GitHub 리포지토리를 참조하세요.

UnityNuGet 설정

게임 프로젝트에 UnityNuGet을 설정하지 않은 경우 다음 단계에 따라 Unity 패키지 관리자를 사용하여 도구를 설치합니다. 또는 NuGet CLI를 사용하여 DLL을 수동으로 다운로드할 수 있습니다. 자세한 내용은 Amazon GameLift Unity용 C# Server SDK README를 참조하세요.

UnityNuGet을 게임 프로젝트에 통합하려면
  1. Unity 편집기에서 프로젝트를 열고 기본 메뉴로 이동하여 편집, 프로젝트 설정을 선택합니다. 옵션에서 패키지 관리자 섹션을 선택하고 범위 지정 레지스트리 그룹을 엽니다.

  2. + 버튼을 선택하고 UnityNuGet 범위 지정 레지스트리에 다음 값을 입력합니다.

    Name: Unity NuGet URL: https://unitynuget-registry.azurewebsites.net Scope(s): org.nuget
  3. Unity 2021 버전 사용자의 경우

    UnityNuGet을 설정한 후 Unity 콘솔에 Assembly Version Validation 오류가 표시되는지 확인합니다. 이러한 오류는 NuGet 패키지의 이름이 엄격한 어셈블리에 대한 바인딩 리디렉션이 Unity 프로젝트 내 경로로 제대로 확인되지 않는 경우 발생합니다. 이 문제를 해결하려면 Unity의 어셈블리 버전 검증을 구성하세요.

    1. Unity 편집기에서 기본 메뉴로 이동하여 편집, 프로젝트 설정을 선택하고 플레이어 섹션을 엽니다.

    2. 어셈블리 버전 검증 옵션을 선택 취소합니다.

플러그인 설치

다음 절차를 사용하여 Amazon GameLift Unity용 C# Server SDK 플러그인을 설치하고 log4net 로깅을 구성합니다.

플러그인을 설치하려면
  1. Unity 편집기에서 프로젝트를 열고 기본 메뉴로 이동하여 , 패키지 관리자를 선택합니다.

  2. + 버튼을 선택하여 새 패키지를 추가합니다. tarball에서 패키지 추가 옵션을 선택합니다.

  3. 디스크의 패키지 선택에서 Amazon GameLift Unity용 C# 서버 SDK 플러그인 다운로드 파일을 찾아 Amazon GameLiftServer버 SDK .tgz 파일을 선택합니다. 열기를 선택하여 플러그인을 설치합니다.

Amazon GameLift Server SDK는 log4net 프레임워크를 사용하여 로그 메시지를 출력합니다. 기본적으로 서버 빌드의 터미널에 메시지를 출력하도록 구성되어 있지만 Unity에는 파일 로깅 지원을 추가하기 위한 구성이 필요합니다. Amazon GameLift Server SDK 패키지 내에서 제공된 샘플을 가져와서 프로젝트에 이러한 지원을 추가할 수 있습니다. 다음 절차를 사용하여 샘플을 추가하고 log4net을 구성합니다.

파일 출력을 위해 log4net을 구성하려면
  1. Unity 편집기에서 프로젝트를 열고 기본 메뉴로 이동하여 , 패키지 관리자를 선택합니다.

  2. 드롭다운 메뉴에서 패키지: 프로젝트에서를 선택한 다음 패키지 목록에서 Amazon GameLift Server SDK를 선택합니다. 그러면 패키지 세부 정보가 열립니다.

  3. 패키지 세부 정보에서 샘플 그룹 옵션을 선택하고 가져오기를 누릅니다.

  4. log4net.config 파일과 함께 제공되는 LoggingConfiguration.cs 스크립트는 구성을 자동으로 실행하며, 구성은 이제 Assets/Samples 프로젝트 폴더에 설정됩니다.

    참고

    log4net.config 파일을 프로젝트의 다른 폴더로 이동해야 하는 경우 LoggingConfiguration.cs 스크립트에 있는 구성 파일의 파일 경로도 새 경로로 업데이트해야 합니다. 자세한 내용은 log4net 구성에 대한 log4net 설명서를 참조하세요.

자세한 지침과 테스트 지침에 대한 자세한 내용은 플러그인 다운로드에 있는 README를 참조하세요.

테스트를 위한 Amazon GameLift Anywhere 플릿 설정

개발 워크스테이션을 Amazon GameLift Anywhere 호스팅 플릿으로 설정하여 Amazon GameLift 통합을 반복적으로 테스트할 수 있습니다. 이 설정을 통해 워크스테이션에서 게임 서버 프로세스를 시작하고, Amazon GameLift에 플레이어 가입 또는 매치메이킹 요청을 보내 게임 세션을 시작하고, 클라이언트를 새 게임 세션에 연결할 수 있습니다. 자체 워크스테이션을 호스팅 서버로 설정하면 Amazon GameLift와의 게임 통합의 모든 측면을 모니터링할 수 있습니다.

워크스테이션 설정에 대한 지침은 Amazon에서 로컬 테스트 설정하기 GameLift Anywhere 섹션을 참조하여 다음 단계를 완료합니다.

  1. 워크스테이션에 대한 사용자 지정 위치를 만듭니다.

  2. 새 사용자 지정 위치를 사용하여 Amazon GameLift Anywhere 플릿을 생성합니다. 요청이 성공하면 플릿 ID가 반환됩니다. 나중에 필요하므로 이 값은 기록해 둡니다.

  3. 워크스테이션을 새 Anywhere 플릿의 컴퓨팅으로 등록합니다. 고유한 컴퓨팅 이름을 제공하고 워크스테이션의 IP 주소를 지정합니다. 성공하면 이 요청은 WebSocket URL의 형태로 서비스 SDK 엔드포인트를 반환합니다. 나중에 필요하므로 이 값은 기록해 둡니다.

  4. 워크스테이션 컴퓨팅을 위한 인증 토큰을 생성합니다. 이 단수명 인증에는 토큰과 만료 날짜가 포함됩니다. 게임 서버는 이를 사용하여 Amazon GameLift 서비스와의 통신을 인증합니다. 워크스테이션 컴퓨팅에 인증을 저장하여 실행 중인 게임 서버 프로세스가 액세스할 수 있도록 합니다.

Amazon GameLift 서버 코드를 Unity 프로젝트에 추가

게임 서버는 Amazon GameLift 서비스와 통신하여 지침을 받고 진행 상태를 보고합니다. 이를 수행하려면 Amazon GameLift Server SDK를 사용하는 게임 서버 코드를 추가합니다.

제공된 코드 예제는 기본적인 필수 통합 요소를 보여줍니다. MonoBehavior를 사용하여 Amazon GameLift를 사용한 간단한 게임 서버 초기화를 설명합니다. 이 예제에서는 테스트를 위해 게임 서버가 Amazon GameLift Anywhere 플릿에서 실행된다고 가정합니다. 여기에는 다음과 같은 코드가 포함됩니다.

  • Amazon GameLift API 클라이언트를 초기화합니다. 이 샘플은 Anywhere 플릿 및 컴퓨팅용 서버 파라미터가 있는 InitSDK() 버전을 사용합니다. 이전 주제 테스트를 위한 Amazon GameLift Anywhere 플릿 설정에서 정의한 대로 WebSocket URL, 플릿 ID, 컴퓨팅 이름(호스트 ID) 및 인증 토큰을 사용합니다.

  • OnStartGameSession, OnProcessTerminateonHealthCheck를 포함한 Amazon GameLift 서비스의 요청에 응답하는 콜백 함수를 구현합니다.

  • 지정된 포트와 함께 ProcessReady()를 호출하여 프로세스가 게임 세션을 호스팅할 준비가 되면 Amazon GameLift 서비스에 알립니다.

이 주제에 제시된 코드는 Amazon GameLift 서비스와의 통신을 설정합니다. 또한 다음의 요청에 응답하는 콜백 함수 집합을 구현합니다. 각 함수와 코드가 수행하는 작업에 대한 자세한 내용은 서버 프로세스 초기화를 참조하세요. 이 코드에 사용된 SDK 작업 및 데이터 유형에 대한 자세한 내용은 C#용 Amazon GameLift Server SDK 참조 섹션을 참조하세요.

이 샘플은 Amazon GameLift를 게임 서버에 추가에 설명된 대로 모든 필수 요소를 추가하는 방법을 보여줍니다. 여기에는 다음이 포함됩니다.

Amazon GameLift 기능 추가에 대한 자세한 내용은 다음 주제를 참조하세요.

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 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 a GameLift Anywhere fleet. //They are not required for a GameLift managed EC2 fleet. ServerParameters serverParameters = new ServerParameters( webSocketUrl, processId, hostId, fleetId, authToken); //InitSDK establishes a local connection with an Amazon GameLift agent //to enable further communication. var initSDKOutcome = GameLiftServerAPI.InitSDK(serverParameters); if (initSDKOutcome.Success) { //Implement callback functions ProcessParameters processParameters = new ProcessParameters( //Implement OnStartGameSession callback (gameSession) => { //GameLift 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) => { //GameLift 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 //GameLift 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 GameLift it is shutting down. GameLiftServerAPI.ProcessEnding(); }, () => { //Implement callback function OnHealthCheck //GameLift 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 GameLift 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 GameLift where to find game session log files. //At the end of a game session, GameLift 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 GameLift 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 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); } } }

추가 리소스

다음 리소스를 사용하여 게임 서버를 테스트하고 기능을 확장합니다.