added: network scene, networking packages
This commit is contained in:
@@ -1,6 +1,14 @@
|
||||
using UnityEngine;
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using Codice.Client.Common.WebApi;
|
||||
using Sirenix.OdinInspector;
|
||||
using Unity.Netcode;
|
||||
using Unity.Netcode.Transports.UTP;
|
||||
using Unity.Services.Authentication;
|
||||
using Unity.Services.Relay;
|
||||
using Unity.Services.Relay.Models;
|
||||
using Unity.Services.Core;
|
||||
|
||||
public class SessionManager : MonoBehaviour{
|
||||
// Start is called once before the first execution of Update after the MonoBehaviour is created
|
||||
@@ -11,5 +19,19 @@ public class SessionManager : MonoBehaviour{
|
||||
void Update(){
|
||||
|
||||
}
|
||||
|
||||
[Button]
|
||||
public async Task<string> StartHostWithRelay(int maxConnections, string connectionType)
|
||||
{
|
||||
await UnityServices.InitializeAsync();
|
||||
if (!AuthenticationService.Instance.IsSignedIn)
|
||||
{
|
||||
await AuthenticationService.Instance.SignInAnonymouslyAsync();
|
||||
}
|
||||
var allocation = await RelayService.Instance.CreateAllocationAsync(maxConnections);
|
||||
NetworkManager.Singleton.GetComponent<UnityTransport>().SetRelayServerData(AllocationUtils.ToRelayServerData(allocation, connectionType));
|
||||
var joinCode = await RelayService.Instance.GetJoinCodeAsync(allocation.AllocationId);
|
||||
return NetworkManager.Singleton.StartHost() ? joinCode : null;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user