您最多选择25个主题 主题必须以中文或者字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
Jacob Stove Lorentzen 1251eaa2 Merging in latest service versions to staging. 3 年前
..
Documentation~ Branch with Beta packages included. 3 年前
Runtime Merging in latest service versions to staging. 3 年前
CHANGELOG.md Package update and library source changes. 3 年前
CHANGELOG.md.meta Branch with Beta packages included. 3 年前
CONTRIBUTING.md Initial packages checkin. 4 年前
CONTRIBUTING.md.meta Branch with Beta packages included. 3 年前
LICENSE.md Branch with Beta packages included. 3 年前
LICENSE.md.meta Branch with Beta packages included. 3 年前
README.md Branch with Beta packages included. 3 年前
README.md.meta Branch with Beta packages included. 3 年前
Runtime.meta Branch with Beta packages included. 3 年前
Third Party Notices.md Adding new Packages 3 年前
Third Party Notices.md.meta Package update and library source changes. 3 年前
package.json Package update and library source changes. 3 年前
package.json.meta Branch with Beta packages included. 3 年前

README.md

Relay SDK

The Relay SDK provides methods to Create Allocations, Create Join Codes and Use Join Codes to join a host.

Relay SDK depends on the Operate Core SDK.

To use the SDK the player has to be authenticated, using the Authentication SDK:

Using the Relay SDK

Import packages

using Unity.Services.Authentication;
using Unity.Services.Core;
using Unity.Services.Relay;
using Unity.Services.Relay.Allocations;
using Unity.Services.Relay.Http;
using Unity.Services.Relay.Models;

Player authentication

Each player must be authenticated. The simplest way to authenticate players is through anonymous authentication using the Authentication SDK. However, other methods are also supported.

try
{
    await UnityServices.Initialize();
    await AuthenticationService.Instance.SignInAnonymouslyAsync();
    var playerID = Authentication.PlayerId;
}
catch (Exception e)
{
    Debug.Log(e);
}

Setup the host

Typically, the player who is hosting the game creates a Relay server allocation. Allocations reserve capacity on a Relay server and provide a way to address data packets.

try
{
    var maxNumberOfPlayer = 10;
    Response<AllocateResponseBody> response = await RelayService.AllocationsApiClient.CreateAllocationAsync(new CreateAllocationRequest(new AllocationRequest(maxNumberOfPlayer)));
    var allocation = allocationTask.Result.Result.Data.Allocation;
    Debug.Log(allocation.AllocationId);
}
catch (HttpException he)
{
    Debug.Log(he);
}

You can use join codes to allow the host player to invite other players to join the game. The Relay can generate random join codes that are short and easy to read. The join codes are intended to be shared out-of-band, such as through a third-party chat service.

try
{
    Response<JoinCodeResponseBody> response = await RelayService.AllocationsApiClient.CreateJoincodeAsync(new CreateJoincodeRequest(new JoinCodeRequest(hostAllocationId)));
    JoinCodeData joinCodeData = response.Result.Data;
    joinCode = joinCodeData.JoinCode;
    Debug.Log(joinCode);
    UpdateUI();
}
catch (HttpException he)
{
    Debug.Log(he);
}

Setup the client

Players can join the host by using the join code. You can use the Relay SDK to connect (that is, a Relay endpoint) to the host player.

try
{
    Response<JoinResponseBody> response = await RelayService.AllocationsApiClient.JoinRelayAsync(new JoinRelayRequest(new JoinRequest(joinCode)));
    var allocation = response.Result.Data.Allocation;
    Debug.Log(allocation.AllocationId);
}
catch (HttpException he)
{
    Debug.Log(he);
}