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

  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using Networking.Client;
  5. using System.Runtime.InteropServices;
  6. public class PortManager : MonoBehaviour
  7. {
  8. public int AndroidPort = 2222;
  9. public int WebGLPort = 4444;
  10. [Header("references")]
  11. public ClientLoginManager ClientManager;
  12. public TMPro.TMP_InputField ipField;
  13. public TMPro.TMP_InputField portfield;
  14. [DllImport("__Internal")]
  15. private static extern string GetURLFromPage();
  16. // Start is called before the first frame update
  17. void Start()
  18. {
  19. #if (UNITY_WEBGL && !UNITY_EDITOR)
  20. if (ClientManager != null)
  21. {
  22. ClientManager.Port = WebGLPort;
  23. portfield.text = WebGLPort.ToString();
  24. portfield.transform.parent.gameObject.SetActive(false);
  25. System.Uri url = new System.Uri(GetURLFromPage());
  26. ipField.text = url.Host;
  27. ClientManager.ServerIP = url.Host;
  28. ClientManager.StartClient(url.Host, WebGLPort);
  29. }
  30. #else
  31. if (ClientManager != null)
  32. {
  33. ClientManager.Port = AndroidPort;
  34. portfield.text = AndroidPort.ToString();
  35. }
  36. #endif
  37. }
  38. }