using UnityEngine; using System; using System.Threading.Tasks; using Reset; 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{ public GameObject playerPrefab; // Start is called once before the first execution of Update after the MonoBehaviour is created void Start(){ } public void StartSession(){ Instantiate(playerPrefab); } public void StartOnlineSession(){ // Not handled in this script for now } // Update is called once per frame void Update(){ } [Button] public async Task 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().SetRelayServerData(AllocationUtils.ToRelayServerData(allocation, connectionType)); var joinCode = await RelayService.Instance.GetJoinCodeAsync(allocation.AllocationId); Debug.Log(joinCode); return NetworkManager.Singleton.StartClient() ? joinCode : null; } }