You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

52 lines
1.2 KiB

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Networking.Client;
using System.Runtime.InteropServices;
public class PortManager : MonoBehaviour
{
public int AndroidPort = 2222;
public int WebGLPort = 4444;
[Header("references")]
public ClientLoginManager ClientManager;
public TMPro.TMP_InputField ipField;
public TMPro.TMP_InputField portfield;
[DllImport("__Internal")]
private static extern string GetURLFromPage();
// Start is called before the first frame update
void Start()
{
#if (UNITY_WEBGL && !UNITY_EDITOR)
if (ClientManager != null)
{
ClientManager.Port = WebGLPort;
portfield.text = WebGLPort.ToString();
portfield.transform.parent.gameObject.SetActive(false);
System.Uri url = new System.Uri(GetURLFromPage());
ipField.text = url.Host;
ClientManager.ServerIP = url.Host;
ClientManager.StartClient(url.Host, WebGLPort);
}
#else
if (ClientManager != null)
{
ClientManager.Port = AndroidPort;
portfield.text = AndroidPort.ToString();
}
#endif
}
}