유니티 AWS 서버 - yuniti AWS seobeo

이 주제는 Unity 게임 서버 프로젝트에서 GameLift C# Server SDK를 설정하는 데 도움이 됩니다. 관리형 GameLift 서비스가 사용 중인 운영 체제를 지원하는지 확실하지 않은 경우 커스텀 게임 서버용 단원을 참조하십시오.

C# Server SDK 를 Unity 설정

다음 단계를 따라 C#용 GameLift Server SDK를 빌드하고 Unity 게임 서버 프로젝트에 추가합니다.

를 설정하려면GameLift유니티를 위한 서버 SDK

  1. 를 다운로드합니다.GameLiftServer SDK. 게임 시스템 요구 사항이 지원되는지 확인하려면 Amazon 다운로드 GameLift SDK 단원을 참조하십시오. 서버 SDK zip 파일에는 프로젝트에 필요한 경우 SDK를 빌드할 수 있도록 소스 파일이 포함된 C# Server SDK가 포함되어 있습니다.

  2. C# SDK 라이브러리를 빌드합니다. IDE에서 사용할 C# Server SDK 솔루션 파일을 로드합니다. IDE 기능을 사용하여 복원NuGet프로젝트를 위한 파일입니다. README.md 최소 요구 사항과 추가 빌드 옵션은 C# Server SDK의 파일을 참조하십시오. C# SDK 라이브러리를 생성하는 솔루션을 빌드합니다.

  3. 구성 설정을 확인합니다. Unity Editor에서 게임 프로젝트를 엽니다. 이동File,빌드 설정,player 설정. Other Settings(기타 설정), Configuration(구성)에서 다음 설정을 확인합니다.

    • 스크립팅 실행 시간 버전: 사용 중인 .NET 솔루션으로 설정합니다.

  4. 를 추가합니다.GameLiftUnity 프로젝트에 대한 라이브러리 Unity Editor에서 솔루션 빌드를 통해 생성된 라이브러리를Assets/Plugins프로젝트의 디렉토리입니다. 단원을 참조하십시오.README.md사용 중인 SDK 버전에 대한 전체 라이브러리 목록을 보려면 file 을 참조하십시오.

AddGameLift서버 코드

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

  • AddGameLift를 게임 서버로

  • GameLiftC# 용 Server API reference

다음 코드 예제는 MonoBehavior를 사용하여 GameLift를 사용한 간단한 게임 서버 초기화를 보여줍니다.

using UnityEngine;
using Aws.GameLift.Server;
using System.Collections.Generic;

public class GameLiftServerExampleBehavior : MonoBehaviour
{
    //This is an example of a simple integration with GameLift server SDK that makes game server 
    //processes go active on Amazon GameLift
    public void Start()
    {
        //Set the port that your game service is listening on for incoming player connections (hard-coded here for simplicity)
        var listeningPort = 7777;

        //InitSDK establishes a local connection with the Amazon GameLift agent to enable 
        //further communication.
        var initSDKOutcome = GameLiftServerAPI.InitSDK();
        if (initSDKOutcome.Success)
        {
            ProcessParameters processParameters = new ProcessParameters(
                (gameSession) => {
                    //Respond to new game session activation request. GameLift sends activation request 
                    //to the game server along with a game session object containing game properties 
                    //and other settings. Once the game server is ready to receive player connections, 
                    //invoke GameLiftServerAPI.ActivateGameSession()
                    GameLiftServerAPI.ActivateGameSession();
                },
                () => {
                    //OnProcessTerminate callback. GameLift invokes this callback before shutting down 
                    //an instance hosting this game server. It gives this game server a chance to save
                    //its state, communicate with services, etc., before being shut down. 
                    //In this case, we simply tell GameLift we are indeed going to shut down.
                    GameLiftServerAPI.ProcessEnding();
                }, 
                () => {
                    //This is the HealthCheck callback.
                    //GameLift invokes this callback every 60 seconds or so.
                    //Here, a game server might want to check the health of dependencies and such.
                    //Simply return true if healthy, false otherwise.
                    //The game server has 60 seconds to respond with its health status. 
                    //GameLift will default to 'false' if the game server doesn't respond in time.
                    //In this case, we're always healthy!
                    return true;
                },
                //Here, the game server tells GameLift what port it is listening on for incoming player 
                //connections. In this example, the port is hardcoded for simplicity. Active game
                //that are on the same instance must have unique ports.
                listeningPort, 
                new LogParameters(new List<string>()
                {
                    //Here, the game server tells GameLift what set of files to upload when the game session ends.
                    //GameLift uploads everything specified here for the developers to fetch later.
                    "/local/game/logs/myserver.log"
                }));

            //Calling ProcessReady tells GameLift this game server is ready to receive incoming 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() when the application quits. 
        //This resets the local connection with GameLift's agent.
        GameLiftServerAPI.ProcessEnding();
    }
}