如何将GameLift与Unity3d集成为游戏客户端 [英] How to integrate GameLift with Unity3d as a game client

查看:156
本文介绍了如何将GameLift与Unity3d集成为游戏客户端的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将Unity3d游戏用作GameList客户端.

I am trying to use a Unity3d game as GameList client.

根据 GameLift论坛 ,似乎亚马逊不建议直接将游戏客户端用作GameLift客户端.

According to the GameLift forum, it seems Amazon does not recommend to use a game client as a GameLift client directly.

但是我想尝试一下,因为我不想再提供一个单独的游戏服务.

But I want to give it a try because I do not want one more separate game service.

  1. 第一步是从 GitHub 下载AWS SDK源代码,然后建立.net35版本的dll;

  1. The first step is downloading AWS SDK source code from GitHub and building the .net35 version dll;

将AWSSDK.Core.dll和AWSSDK.GameLift.dll放入/Assets/Plugins;

Put the AWSSDK.Core.dll and AWSSDK.GameLift.dll into /Assets/Plugins;

从MonoBehaviour创建一个新的派生类以创建AmazonGameLiftClient,下面是我的代码:

Create a new derived class from MonoBehaviour to create the AmazonGameLiftClient, below is my code:

public class MyGameLiftClient : MonoBehaviour
{
    private void Awake()
    {    
        AmazonGameLiftConfig gameLiftConfig = 
                new AmazonGameLiftConfig {RegionEndpoint = RegionEndpoint.USWest1};
        AmazonGameLiftClient client = new AmazonGameLiftClient(
                "AwsAccessKeyId",
                "AwsSecrectAcessKey",
                gameLiftConfig);
    }
}

  1. 在这里我遇到了第一个问题:无法创建GameLiftClient a>

解决上述问题后,我尝试使用AmazonGameLiftClient列出舰队:

After fixing the above problem, I tried to use the AmazonGameLiftClient to list the fleets:

AmazonGameLiftConfig gameLiftConfig = new AmazonGameLiftConfig {RegionEndpoint = RegionEndpoint.USWest1};
AmazonGameLiftClient client = new AmazonGameLiftClient(
            "awsAccessKeyId",
            "awsAccessSecretKey",
            gameLiftConfig);
ListFleetsRequest listFleetsRequest = new ListFleetsRequest();
ListFleetsResponse fleets = client.ListFleets(listFleetsRequest);

但我得到以下例外:

NotSupportedException: https://gamelift.us-west-1.amazonaws.com/
System.Net.WebRequest.GetCreator (System.String prefix)
System.Net.WebRequest.Create (System.Uri requestUri)
Amazon.Runtime.Internal.HttpRequest..ctor (System.Uri requestUri)
Amazon.Runtime.Internal.HttpWebRequestFactory.CreateHttpRequest (System.Uri requestUri)
Amazon.Runtime.Internal.HttpHandler`1[System.IO.Stream].CreateWebRequest (IRequestContext requestContext)
Amazon.Runtime.Internal.HttpHandler`1[System.IO.Stream].InvokeSync (IExecutionContext executionContext)
Amazon.Runtime.Internal.PipelineHandler.InvokeSync (IExecutionContext executionContext)
Amazon.Runtime.Internal.Unmarshaller.InvokeSync (IExecutionContext executionContext)
Amazon.Runtime.Internal.PipelineHandler.InvokeSync (IExecutionContext executionContext)
Amazon.Runtime.Internal.ErrorHandler.InvokeSync (IExecutionContext executionContext)

  1. 我在aws.config中添加了一些其他配置以对其进行修复,以下是我的整个aws.config:

<configuration>
  <configSections>
    <section name="aws" type="Amazon.AWSSection, AWSSDK.Core"/>
    <section name="system.diagnostics" type="System.Diagnostics.DiagnosticsConfigurationHandler" />
    <sectionGroup name="system.net" type="System.Net.Configuration.NetSectionGroup, System">
       <section name="authenticationModules" type="System.Net.Configuration.AuthenticationModulesSection, System" />
       <section name="connectionManagement" type="System.Net.Configuration.ConnectionManagementSection, System" />
       <sectionGroup name="mailSettings" type="System.Net.Configuration.MailSettingsSectionGroup, System">
          <section name="smtp" type="System.Net.Configuration.SmtpSection, System" />
       </sectionGroup>
       <section name="requestCaching" type="System.Net.Configuration.RequestCachingSection, System" />
       <section name="settings" type="System.Net.Configuration.SettingsSection, System" />
       <section name="webRequestModules" type="System.Net.Configuration.WebRequestModulesSection, System" />
     </sectionGroup>
  </configSections>
  <aws>
    <logging logTo="Log4Net"/>
    <csmConfig csmEnabled="false"/>
  </aws>
  <system.diagnostics>
     <trace autoflush="true" />
  </system.diagnostics>
  <system.net>  
    <authenticationModules>  
      <add type="System.Net.DigestClient" />  
      <add type="System.Net.NegotiateClient" />  
      <add type="System.Net.KerberosClient" />  
      <add type="System.Net.NtlmClient" />  
      <add type="System.Net.BasicClient" />  
    </authenticationModules>  
    <connectionManagement>  
      <add address="*" maxconnection="2" />  
    </connectionManagement>  
    <webRequestModules>  
      <add prefix="http"  
           type="System.Net.HttpRequestCreator"  
      />  
      <add prefix="https"  
           type="System.Net.HttpRequestCreator"  
      />  
      <add prefix="file"  
           type="System.Net.FileWebRequestCreator"  
      />
    </webRequestModules>  
  </system.net>  
</configuration>

  1. 现在我得到另一个例外:

MissingMethodException: Method not found: 'System.Net.ServicePoint.SetTcpKeepAlive'.
Amazon.Runtime.Internal.HttpHandler`1[System.IO.Stream].CreateWebRequest (IRequestContext requestContext)
Amazon.Runtime.Internal.HttpHandler`1[System.IO.Stream].InvokeSync (IExecutionContext executionContext)
Amazon.Runtime.Internal.PipelineHandler.InvokeSync (IExecutionContext executionContext)
Amazon.Runtime.Internal.Unmarshaller.InvokeSync (IExecutionContext executionContext)
Amazon.Runtime.Internal.PipelineHandler.InvokeSync (IExecutionContext executionContext)
Amazon.Runtime.Internal.ErrorHandler.InvokeSync (IExecutionContext executionContext)

有人对此异常有想法吗?

Does anyone have an idea about this exception?

我的环境:

  • 操作系统:Mac OS X 10.14.1
  • Unity3d:2018.2.12f1
  • AWS SDK核心:3.3.29.10(.net35)
  • AWS SDK GameLift:3.3.12.29(.net35)

推荐答案

最终,我找到了在Unity3d中使用GameLiftClient的方法.

Eventually, I find a way to use GameLiftClient in Unity3d.

先决条件:

  • Windows 10
  • JetBrain Rider ,Visual Studio也应该可以工作
  • 放入"UnityEngine.dll";到C:\ Program Files \ Unity \ Editor \ Data \ Managed \ UnityEngine.dll
  • 设置脚本运行时版本"到".net35等效"在Unity3d项目的项目设置中.
  • Windows 10
  • JetBrain Rider, Visual Studio should also work
  • Put "UnityEngine.dll" to C:\Program Files\Unity\Editor\Data\Managed\UnityEngine.dll
  • Set "Scripting Runtime version" to ".net35 Equivalent" in Project Setting of your Unity3d project.

第1步: Github 下载AWS SDK源并将其解压缩到您喜欢的任何位置.

Step 1: Download AWS SDK Source for from Github and unzip it to anywhere you like.

下载与您使用的GameLift Server SDK兼容的版本更为安全.

It is safer to download the version which is compatible with the GameLift Server SDK you use.

第2步: JetBrain Rider 中打开sdk/AWSSDK.Unity.sln. Visual Studio也应该工作,但我不拥有与该解决方案兼容的正确版本的VS.

Step 2: Open sdk/AWSSDK.Unity.sln in JetBrain Rider. Visual Studio should also work, but I do not own the right version of VS which is compatible with the solution.

第3步: 在Rider的解决方案面板中,在服务"下创建一个新的解决方案文件夹.将其命名为"GameLift". 右键点击"GameLift"文件夹,然后选择添加现有项目".在弹出窗口中,浏览并选择"sdk \ src \ Services \ GameLift \ AWSSDK.GameLift.Net35.csproj".

Step 3: In solution panel of Rider, create a new solution folder under "Services," name it "GameLift". Right click on the "GameLift" folder and choose "Add Existing Project,". In the popup windows, browse and choose "sdk\src\Services\GameLift\AWSSDK.GameLift.Net35.csproj".

现在解决方案应如下所示:

Now the solution should look like:

第4步: 右键点击"AWSSDK.GameLift.Net35.csproj",并选择编辑AWSSDK.GameLift.Net35.csproj" 在Rider的编辑器面板中,将<ProjectReference Include="..\..\Core\AWSSDK.Core.Net35.csproj"/>更改为

Step 4: Right click the "AWSSDK.GameLift.Net35.csproj" and choose "Edit AWSSDK.GameLift.Net35.csproj" In the editor panel of Rider, change <ProjectReference Include="..\..\Core\AWSSDK.Core.Net35.csproj"/> to

<ProjectReference Include="..\..\Core\AWSSDK.Core.Unity.csproj">
  <Project>{5A8B25C1-3D58-4BB6-BF7D-77AD818D9EAD}</Project>
  <Name>AWSSDK.Core.Unity</Name>
</ProjectReference>

默认情况下,从解决方案中包含的任何其他Project设置中复制ProjectReferece. 不要忘记保存文件.

Above ProjectReferece is copied from any other Project setting which is included in the solution by default. Do not forget to save the file.

第5步: 右键点击"AWSSDK.GameLift.Net35.csproj",并选择构建选定的项目".

Step 5: Right-click the "AWSSDK.GameLift.Net35.csproj" and choose "Build Selected Projects".

第6步: 转到"sdk \ src \ Services \ GameLift \ bin \ Debug \ net35"或"sdk \ src \ Services \ GameLift \ bin \ Release \ net35",复制除"UnityEngnine.dll"以外的所有dll.到您的Unity3d项目中.我将它们放在资产/AWSSDK"下.

Step 6: Go to "sdk\src\Services\GameLift\bin\Debug\net35" or "sdk\src\Services\GameLift\bin\Release\net35", copy all dll except the "UnityEngnine.dll" into your Unity3d project. I put them under 'Assets/AWSSDK'.

第7步: 使用以下内容创建资产/AWSSDK/src/Core/Resources/awsconfig.xml":

Step 7: Create 'Assets/AWSSDK/src/Core/Resources/awsconfig.xml' with below content:

<?xml version="1.0" encoding="utf-8"?>
<aws
    region="us-west-1"
    correctForClockSkew="true">
</aws>

步骤8: 现在,它应该能够使用以下代码片段创建GameLiftClient了:

Step 8: Now it should be able to create GameLiftClient using below snippet:

Awake()
{
    UnityInitializer.AttachToGameObject(gameObject);

    AWSConfigs.HttpClient = AWSConfigs.HttpClientOption.UnityWebRequest;

    AmazonGameLiftConfig gameLiftConfig = new AmazonGameLiftConfig
    {
            RegionEndpoint = RegionEndpoint.USWest1
    };

    m_Client = new AmazonGameLiftClient(
                "awsAccessKeyId",
                "awsSecretAccessKey",
                gameLiftConfig);
}

别忘了替换"awsAccessKey".到真正的一个. 此外,将AWS Credentials硬编码到客户端也是不安全的.因此,请仅将此代码段用于测试目的.出于生产目的,可以使用AWS Cognito在运行时分发AWS凭证.

Do not forget to replace the "awsAccessKey" to the real one. Also, it is not safe to hard code AWS Credentials into the client. So please only use this code snippet for test purpose. For production purpose, AWS Cognito can be used to distribute AWS Credentials at runtime.

全部完成.

这篇关于如何将GameLift与Unity3d集成为游戏客户端的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆