从 Gamelift 迁移
移除 AWS Gamelift SDK
Unity (C#)
using UnityEngine;
using Aws.GameLift.Server;
using System.Collections.Generic;
public class GameLiftServerExampleBehavior : MonoBehaviour
{
// 这是一个与 GameLift 服务器 SDK 简单集成的示例,会使游戏服务器进程在 GameLift 上变为活动状态!
public void Start()
{
// 确定端口号(此处为简便起见硬编码),游戏服务器在此端口上监听玩家连接
var listeningPort = 7777;
// InitSDK 将与 GameLift 的代理建立本地连接以启用进一步通信。
var initSDKOutcome = GameLiftServerAPI.InitSDK();
if (initSDKOutcome.Success)
{
ProcessParameters processParameters = new ProcessParameters(
(gameSession) => {
// 当创建游戏会话时,GameLift 会向游戏服务器发送激活请求,并传递包含游戏属性和其他设置的游戏会话对象。
// 游戏服务器应根据游戏会话对象在此处采取相应操作。
// 一旦游戏服务器准备好接收传入的玩家连接,应调用 GameLiftServerAPI.ActivateGameSession()
GameLiftServerAPI.ActivateGameSession();
},
(updateGameSession) => {
// 当游戏会话被更新时(例如通过 FlexMatch 回填),GameLift 会向游戏
// 服务器发送包含更新后游戏会话对象的请求。游戏服务器随后可以检查提供的
// matchmakerData 并适当地处理新的传入玩家。
// updateReason 是提供此更新的原因。
},
() => {
// OnProcessTerminate 回调。GameLift 会在关闭托管此游戏服务器的实例之前调用此回调。
// 它给这个游戏服务器一个机会在被关闭之前保存其状态、与服务通信等。
// 在此例中,我们简单地告诉 GameLift 我们确实要关闭。
GameLiftServerAPI.ProcessEnding();
},
() => {
// 这是 HealthCheck 回调。
// GameLift 将每大约 60 秒调用此回调一次。
// 在这里,游戏服务器可能想检查依赖项的健康状况等。
// 如果健康则返回 true,否则返回 false。
// 游戏服务器有 60 秒时间来响应其健康状态。如果游戏服务器未及时响应,GameLift 默认为“false”。
// 在此例中,我们始终健康!
return true;
},
listeningPort, // 这个游戏服务器告知 GameLift 它将在端口 7777 上监听传入玩家连接。
new LogParameters(new List<string>()
{
// 在这里,游戏服务器告诉 GameLift 在游戏会话结束时要上传的一组文件。
// GameLift 将上传此处指定的所有内容,供开发者日后获取。
"/local/game/logs/myserver.log"
}));
// 调用 ProcessReady 告诉 GameLift 该游戏服务器已准备好接收传入的游戏会话!
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()
{
// 应用退出时务必调用 GameLiftServerAPI.Destroy()。这会重置与 GameLift 代理的本地连接。
GameLiftServerAPI.Destroy();
}
}Unreal Engine (C++)
将您的游戏服务器容器化
将您的容器推送到仓库
在 Edgegap 上创建应用
最后更新于
这有帮助吗?

