48 lines
1.3 KiB
C#
48 lines
1.3 KiB
C#
using Netcode.Transports.Facepunch;
|
|
using Unity.Netcode;
|
|
using Unity.Netcode.Transports.UTP;
|
|
using UnityEngine;
|
|
using UnityEngine.SceneManagement;
|
|
using UnityEngine.UI;
|
|
|
|
public class NetworkSetup : MonoBehaviour
|
|
{
|
|
[SerializeField] private Button LocalBtn;
|
|
[SerializeField] private Button SteamBtn;
|
|
[SerializeField] private GameObject ButtonsHolder;
|
|
[SerializeField] private GameObject LoadingText;
|
|
|
|
private void OnEnable()
|
|
{
|
|
LocalBtn.onClick.AddListener(OnLocalClicked);
|
|
SteamBtn.onClick.AddListener(OnSteamClicked);
|
|
}
|
|
|
|
private void OnLocalClicked()
|
|
{
|
|
LoadingText.SetActive(true);
|
|
ButtonsHolder.SetActive(false);
|
|
|
|
var transport = NetworkManager.Singleton.gameObject.AddComponent<UnityTransport>();
|
|
NetworkManager.Singleton.NetworkConfig.NetworkTransport = transport;
|
|
|
|
NextScene();
|
|
}
|
|
|
|
private void OnSteamClicked()
|
|
{
|
|
LoadingText.SetActive(true);
|
|
ButtonsHolder.SetActive(false);
|
|
var transport = NetworkManager.Singleton.gameObject.AddComponent<FacepunchTransport>();
|
|
NetworkManager.Singleton.NetworkConfig.NetworkTransport = transport;
|
|
|
|
NextScene();
|
|
}
|
|
|
|
private void NextScene()
|
|
{
|
|
int currentScene = SceneManager.GetActiveScene().buildIndex;
|
|
SceneManager.LoadScene(++currentScene);
|
|
}
|
|
}
|