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.

75 lines
1.9 KiB

  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. using Multiplayer;
  6. using TMPro;
  7. public class HomeScreenManager : MonoBehaviour {
  8. public TMP_InputField IP;
  9. public TMP_InputField Port;
  10. public TMP_InputField Name;
  11. public GameObject Server;
  12. public string[] DefaultNames;
  13. public void Start()
  14. {
  15. Screen.orientation = ScreenOrientation.Landscape;
  16. int rand = Random.Range(0, DefaultNames.Length);
  17. IP.text = PlayerPrefs.GetString("IP", "");
  18. Port.text = PlayerPrefs.GetString("PORT", "4444");
  19. Name.text = PlayerPrefs.GetString("NAME", DefaultNames[rand]);
  20. }
  21. public void Connect()
  22. {
  23. int intVal = 0;
  24. bool Succeeded = int.TryParse(Port.text, out intVal);
  25. if (Succeeded)
  26. {
  27. //Destroy(ServerManager.Instance.gameObject);
  28. ClientManager.Instance.Name = Name.text;
  29. ClientManager.Instance.StartClient(IP.text, intVal);
  30. }
  31. PlayerPrefs.SetString("IP", IP.text);
  32. PlayerPrefs.SetString("PORT", Port.text);
  33. PlayerPrefs.SetString("NAME", Name.text);
  34. }
  35. public void Host()
  36. {
  37. Server.SetActive(true);
  38. int intVal = 0;
  39. bool Succeeded = int.TryParse(Port.text, out intVal);
  40. if (Succeeded)
  41. {
  42. ServerManager.Instance.StartServer();
  43. }
  44. else
  45. {
  46. Server.SetActive(false);
  47. }
  48. IP.text = IPGrabber.GetIP(ADDRESSFAM.IPv4);
  49. PlayerPrefs.SetString("PORT", Port.text);
  50. PlayerPrefs.SetString("NAME", Name.text);
  51. PlayerPrefs.SetString("IP", IP.text);
  52. //Connect();
  53. }
  54. public void ChangeName()
  55. {
  56. int rand = Random.Range(0, DefaultNames.Length);
  57. Name.text = DefaultNames[rand];
  58. Debug.Log("Name" + DefaultNames[rand]);
  59. }
  60. }