您最多选择25个主题 主题必须以中文或者字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

44 行
1.5 KiB

using UnityEngine;
using System.Threading.Tasks;
using Unity.Services.Relay.Apis.Allocations;
using Unity.Services.Relay.Http;
using Unity.Services.Relay.Scheduler;
using TaskScheduler = Unity.Services.Relay.Scheduler.TaskScheduler;
using Unity.Services.Core.Internal;
using Unity.Services.Authentication.Internal;
namespace Unity.Services.Relay
{
internal class RelayServiceProvider : IInitializablePackage
{
private static GameObject _gameObjectFactory;
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)]
static void Register()
{
// Pass an instance of this class to Core
var generatedPackageRegistry =
CoreRegistry.Instance.RegisterPackage(new RelayServiceProvider());
// And specify what components it requires, or provides.
generatedPackageRegistry.DependsOn<IAccessToken>();
;
}
public Task Initialize(CoreRegistry registry)
{
_gameObjectFactory = GameObjectFactory.CreateCoreSdkGameObject();
var httpClient = new HttpClient();
var accessTokenAllocationsApi = registry.GetServiceComponent<IAccessToken>();
if (accessTokenAllocationsApi != null)
{
RelayService.AllocationsApiClient = new AllocationsApiClient(httpClient, accessTokenAllocationsApi);
}
return Task.CompletedTask;
}
}
}