GameLift Amazon을 Unity 게임 클라이언트 프로젝트와 통합 - 아마존 GameLift

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

GameLift Amazon을 Unity 게임 클라이언트 프로젝트와 통합

참고

이 주제에서는 Unity용 Amazon GameLift 플러그인의 이전 버전에 대한 정보를 제공합니다. 버전 1.0.0 (2021년 출시) 은 아마존 GameLift 서버 SDK 4.x 또는 이전 버전을 사용합니다. 서버 SDK 5.x를 사용하고 GameLift Anywhere Amazon을 지원하는 최신 버전의 플러그인에 대한 설명서는 을 참조하십시오. 서버 SDK 5.x용 유니티용 아마존 GameLift 플러그인 가이드

이 항목은 백엔드 서비스를 통해 Amazon에서 GameLift 호스팅하는 게임 세션에 연결하도록 게임 클라이언트를 설정하는 데 도움이 됩니다. Amazon GameLift API를 사용하여 매치메이킹을 시작하고 게임 세션 배치를 요청하는 등의 작업을 수행할 수 있습니다.

Amazon 서비스와의 통신을 허용하는 코드를 백엔드 GameLift 서비스 프로젝트에 추가합니다. 백엔드 서비스는 서비스와의 모든 게임 클라이언트 통신을 처리합니다. GameLift 백엔드 서비스에 대한 자세한 내용은 게임 클라이언트 서비스 설계 섹션을 참조하세요.

백엔드 서버는 다음 게임 클라이언트 작업을 처리합니다.

  • 플레이어에 맞게 인증을 사용자 지정할 수 있습니다.

  • Amazon GameLift 서비스에 활성 게임 세션에 대한 정보를 요청하십시오.

  • 새 게임 세션을 생성합니다.

  • 기존 게임 세션에 플레이어를 추가합니다.

  • 기존 게임 세션에서 플레이어를 제거합니다.

필수 조건

Amazon GameLift 클라이언트와의 게임 서버 통신을 설정하기 전에 다음 작업을 완료하십시오.

게임 클라이언트 초기화

참고

이 주제에서는 서버 SDK 4.x 또는 이전 버전을 사용하는 Unity 버전 1.0.0용 Amazon GameLift 플러그인을 참조합니다.

게임 클라이언트를 초기화하는 코드를 추가합니다. 시작 시 이 코드를 실행합니다. 이 코드는 다른 Amazon GameLift 함수에 필요합니다.

  1. AmazonGameLiftClient를 초기화합니다. 기본 클라이언트 구성 또는 사용자 지정 구성으로 AmazonGameLiftClient를 호출합니다. 클라이언트를 구성하는 방법에 대한 자세한 내용은 백엔드 GameLift 서비스에 Amazon 설정 섹션을 참조하세요.

  2. 각 플레이어가 게임 세션에 연결할 수 있도록 고유한 플레이어 ID를 생성합니다. 자세한 내용은 플레이어 ID 생성 섹션을 참조하세요.

    다음 예는 Amazon GameLift 클라이언트를 설정하는 방법을 보여줍니다.

    public class GameLiftClient { private GameLift gl; //A sample way to generate random player IDs. bool includeBrackets = false; bool includeDashes = true; string playerId = AZ::Uuid::CreateRandom().ToString<string>(includeBrackets, includeDashes); private Amazon.GameLift.Model.PlayerSession psession = null; public AmazonGameLiftClient aglc = null; public void CreateGameLiftClient() { //Access Amazon GameLift service by setting up a configuration. //The default configuration specifies a location. var config = new AmazonGameLiftConfig(); config.RegionEndpoint = Amazon.RegionEndpoint.USEast1; CredentialProfile profile = null; var nscf = new SharedCredentialsFile(); nscf.TryGetProfile(profileName, out profile); AWSCredentials credentials = profile.GetAWSCredentials(null); //Initialize GameLift Client with default client configuration. aglc = new AmazonGameLiftClient(credentials, config); } }

특정 플릿에서 게임 세션 생성

참고

이 주제에서는 서버 SDK 4.x 또는 이전 버전을 사용하는 Unity 버전 1.0.0용 Amazon GameLift 플러그인을 참조합니다.

코드를 추가하여 배포된 플릿에서 새 게임 세션을 시작하고 플레이어가 사용할 수 있게 허용합니다. GameLift Amazon에서 새 게임 세션을 생성하고 반환한 GameSession 후에는 플레이어를 추가할 수 있습니다.

  • 새 게임 세션에 대한 요청을 배치합니다.

    • 게임에서 플릿을 사용하는 경우 플릿 또는 별칭 ID, 세션 이름, 게임의 최대 동시 플레이어 수를 포함하여 CreateGameSession()을 호출합니다.

    • 게임에서 대기열을 사용하는 경우 StartGameSessionPlacement()를 호출합니다.

다음 예제는 게임 세션을 만드는 방법을 보여줍니다.

public Amazon.GameLift.Model.GameSession() { var cgsreq = new Amazon.GameLift.Model.CreateGameSessionRequest(); //A unique identifier for the alias with the fleet to create a game session in. cgsreq.AliasId = aliasId; //A unique identifier for a player or entity creating the game session cgsreq.CreatorId = playerId; //The maximum number of players that can be connected simultaneously to the game session. cgsreq.MaximumPlayerSessionCount = 4; //Prompt an available server process to start a game session and retrieves connection information for the new game session Amazon.GameLift.Model.CreateGameSessionResponse cgsres = aglc.CreateGameSession(cgsreq); string gsid = cgsres.GameSession != null ? cgsres.GameSession.GameSessionId : "N/A"; Debug.Log((int)cgsres.HttpStatusCode + " GAME SESSION CREATED: " + gsid); return cgsres.GameSession; }

게임 세션에 플레이어 추가

참고

이 주제에서는 서버 SDK 4.x 또는 이전 버전을 사용하는 Unity 버전 1.0.0용 Amazon GameLift 플러그인을 참조합니다.

GameLift Amazon에서 새 게임 세션을 생성하고 GameSession 객체를 반환한 후 플레이어를 추가할 수 있습니다.

  1. 새 플레이어 세션을 생성하여 게임 세션에서 플레이어 슬롯을 예약합니다. CreatePlayerSession 또는 게임 세션 ID와 각 플레이어의 고유 ID와 함께 CreatePlayerSessions을 사용합니다.

  2. 게임 세션에 연결합니다. PlayerSession 객체를 검색하여 게임 세션의 연결 정보를 가져옵니다. 이 정보를 사용하여 서버 프로세스에 직접 연결을 설정합니다.

    1. 지정된 포트 및 서버 프로세스의 DNS 이름이나 IP 주소를 사용합니다.

    2. 플릿의 DNS 이름과 포트를 사용합니다. 플릿에 TLS 인증서 생성이 활성화된 경우 DNS 이름과 포트가 필요합니다.

    3. 플레이어 세션 ID를 참조합니다. 게임 서버가 들어오는 플레이어 연결을 검증하는 경우 플레이어 세션 ID가 필요합니다.

다음 예는 게임 세션에서 플레이어 스팟을 예약하는 방법에 대해 보여줍니다.

public Amazon.GameLift.Model.PlayerSession CreatePlayerSession(Amazon.GameLift.Model.GameSession gsession) { var cpsreq = new Amazon.GameLift.Model.CreatePlayerSessionRequest(); cpsreq.GameSessionId = gsession.GameSessionId; //Specify game session ID. cpsreq.PlayerId = playerId; //Specify player ID. Amazon.GameLift.Model.CreatePlayerSessionResponse cpsres = aglc.CreatePlayerSession(cpsreq); string psid = cpsres.PlayerSession != null ? cpsres.PlayerSession.PlayerSessionId : "N/A"; return cpsres.PlayerSession; }

다음 코드는 플레이어를 게임 세션과 연결하는 방법을 보여줍니다.

public bool ConnectPlayer(int playerIdx, string playerSessionId) { //Call ConnectPlayer with player ID and player session ID. return server.ConnectPlayer(playerIdx, playerSessionId); }

게임 세션에서 플레이어를 제거합니다.

참고

이 주제에서는 서버 SDK 4.x 또는 이전 버전을 사용하는 Unity 버전 1.0.0용 Amazon GameLift 플러그인을 참조합니다.

플레이어가 게임을 떠나면 게임 세션에서 플레이어를 제거할 수 있습니다.

  1. 플레이어가 서버 프로세스에서 연결이 끊겼음을 Amazon GameLift 서비스에 알립니다. 플레이어의 세션 ID로 RemovePlayerSession을 호출합니다.

  2. RemovePlayerSessionSuccess를 반환하는지 확인합니다. 그런 다음 Amazon은 플레이어 슬롯을 사용할 수 있도록 GameLift 변경하며, Amazon은 새 플레이어에게 GameLift 할당할 수 있습니다.

다음 예는 플레이어 세션을 제거하는 방법을 보여줍니다.

public void DisconnectPlayer(int playerIdx) { //Receive the player session ID. string playerSessionId = playerSessions[playerIdx]; var outcome = GameLiftServerAPI.RemovePlayerSession(playerSessionId); if (outcome.Success) { Debug.Log (":) PLAYER SESSION REMOVED"); } else { Debug.Log(":(PLAYER SESSION REMOVE FAILED. RemovePlayerSession() returned " + outcome.Error.ToString()); } }