40 lines
1.2 KiB
C#
40 lines
1.2 KiB
C#
using PashaBibko.PenguinChase.Network;
|
|
using WebSocketSharp;
|
|
using UnityEngine.UI;
|
|
using UnityEngine;
|
|
|
|
public class MainMenuController : MonoBehaviour
|
|
{
|
|
[Header("References")]
|
|
[SerializeField] private Button HostButton;
|
|
[SerializeField] private Button JoinButton;
|
|
[SerializeField] private InputField HostCode;
|
|
[SerializeField] private Dropdown HostNetworkType;
|
|
|
|
private void Start()
|
|
{
|
|
HostButton.onClick.AddListener(() =>
|
|
{
|
|
Debug.Log($"[{HostNetworkType.captionText.text}]");
|
|
Network.CurrentTransport = HostNetworkType.captionText.text switch
|
|
{
|
|
"Localhost" => TransportType.Localhost,
|
|
"UnityRelay" => TransportType.UnityRelay,
|
|
var _ => throw new System.NotImplementedException("Unknown transport type")
|
|
};
|
|
|
|
Network.Host();
|
|
});
|
|
|
|
JoinButton.onClick.AddListener(() =>
|
|
{
|
|
string code = HostCode.text;
|
|
Network.CurrentTransport = code.IsNullOrEmpty()
|
|
? TransportType.Localhost
|
|
: TransportType.UnityRelay;
|
|
|
|
Network.Join(code);
|
|
});
|
|
}
|
|
}
|