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

45 行
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;
using Unity.Services.Authentication;
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 scheduler = _gameObjectFactory.GetComponent<TaskScheduler>();
var httpClient = new HttpClient(scheduler);
var accessTokenAllocationsApi = registry.GetServiceComponent<IAccessToken>();
if (accessTokenAllocationsApi != null)
{
RelayService.AllocationsApiClient = new AllocationsApiClient(httpClient, scheduler, accessTokenAllocationsApi);
}
return Task.CompletedTask;
}
}
}