기계 번역으로 제공되는 번역입니다. 제공된 번역과 원본 영어의 내용이 상충하는 경우에는 영어 버전이 우선합니다.
Unity 게임 클라이언트 프로젝트와 Amazon GameLift Servers 통합
참고
이 주제에서는 이전 버전의 Unity용 Amazon GameLift Servers 플러그인에 대한 정보를 제공합니다. 버전 1.x는 Amazon GameLift Servers 4.x 이하용 서버 SDK를 사용합니다. 서버 SDK 5.x를 사용하고 Amazon GameLift Servers Anywhere 및 관리형 컨테이너 호스팅과 같은 최신 기능을 지원하는 최신 플러그인 버전에 대한 설명서는 Amazon GameLift ServersUnity용 플러그인(서버 SDK 5.x) 섹션을 참조하세요.
이 주제는 백엔드 서비스를 통해 Amazon GameLift Servers 호스팅 게임 세션에 연결하도록 게임 클라이언트를 설정하는 데 도움이 됩니다. Amazon GameLift Servers API를 사용하여 매치메이킹을 시작하고 게임 세션 배치를 요청하는 등의 작업을 수행할 수 있습니다.
Amazon GameLift Servers 서비스와의 통신을 허용하는 코드를 백엔드 서비스 프로젝트에 추가합니다. 백엔드 서비스는 GameLift 서비스와의 모든 게임 클라이언트 통신을 처리합니다. 백엔드 서비스에 대한 자세한 내용은 섹션을 참조하세요.
백엔드 서버는 다음 게임 클라이언트 작업을 처리합니다.
-
플레이어에 맞게 인증을 사용자 지정할 수 있습니다.
-
Amazon GameLift Servers 서비스에 활성 게임 세션에 대한 정보를 요청합니다.
-
새 게임 세션을 생성합니다.
-
기존 게임 세션에 플레이어를 추가합니다.
-
기존 게임 세션에서 플레이어를 제거합니다.
사전 조건
Amazon GameLift Servers 클라이언트와의 게임 서버 통신을 설정하기 전에. 먼저 다음 작업을 완료해야 합니다.
게임 클라이언트 초기화
참고
이 주제에서는 서버 SDK 4.x 이하를 사용하는 Unity 버전 1.0.0용 Amazon GameLift Servers 플러그인을 설명합니다.
게임 클라이언트를 초기화하는 코드를 추가합니다. 시작 시 이 코드를 실행하며, 이 코드는 다른 Amazon GameLift Servers 함수에 필요합니다.
-
AmazonGameLiftClient를 초기화합니다. 기본 클라이언트 구성 또는 사용자 지정 구성으로AmazonGameLiftClient를 호출합니다. 클라이언트를 구성하는 방법에 대한 자세한 내용은 Amazon GameLift Servers API를 설정합니다. 섹션을 참조하세요. -
각 플레이어가 게임 세션에 연결할 수 있도록 고유한 플레이어 ID를 생성합니다. 자세한 내용은 플레이어 ID 생성을 참조하세요.
다음 예제에서는 Amazon GameLift Servers 클라이언트를 설정하는 방법을 보여줍니다.
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 Servers 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 Amazon GameLift Servers Client with default client configuration. aglc = new AmazonGameLiftClient(credentials, config); } }
특정 플릿에서 게임 세션 생성
참고
이 주제에서는 서버 SDK 4.x 이하를 사용하는 Unity 버전 1.0.0용 Amazon GameLift Servers 플러그인을 설명합니다.
코드를 추가하여 배포된 플릿에서 새 게임 세션을 시작하고 플레이어가 사용할 수 있게 허용합니다. Amazon GameLift Servers가 새 게임 세션을 만들고 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 Servers 플러그인을 설명합니다.
Amazon GameLift Servers가 새 게임 세션을 만들고 GameSession 객체를 반환한 후에는 플레이어를 참여시킬 수 있습니다.
-
새 플레이어 세션을 생성하여 게임 세션에서 플레이어 슬롯을 예약합니다.
CreatePlayerSession또는 게임 세션 ID와 각 플레이어의 고유 ID와 함께CreatePlayerSessions을 사용합니다. -
게임 세션에 연결합니다.
PlayerSession객체를 검색하여 게임 세션의 연결 정보를 가져옵니다. 이 정보를 사용하여 서버 프로세스에 직접 연결을 설정합니다.-
지정된 포트 및 서버 프로세스의 DNS 이름이나 IP 주소를 사용합니다.
-
플릿의 DNS 이름과 포트를 사용합니다. 플릿에 TLS 인증서 생성이 활성화된 경우 DNS 이름과 포트가 필요합니다.
-
플레이어 세션 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 Servers 플러그인을 설명합니다.
플레이어가 게임을 떠나면 게임 세션에서 플레이어를 제거할 수 있습니다.
-
플레이어가 서버 프로세스와의 연결이 끊겼음을 Amazon GameLift Servers에 알립니다. 플레이어의 세션 ID로
RemovePlayerSession을 호출합니다. -
RemovePlayerSession이Success를 반환하는지 확인합니다. Amazon GameLift Servers는 Amazon GameLift Servers가 새 플레이어에 할당할 수 있도록 플레이어 슬롯을 사용 가능하도록 변경합니다.
다음 예는 플레이어 세션을 제거하는 방법을 보여줍니다.
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()); } }