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.

74 lines
1.7 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. int rand = Random.Range(0, DefaultNames.Length);
  16. IP.text = PlayerPrefs.GetString("IP", "");
  17. Port.text = PlayerPrefs.GetString("PORT", "4444");
  18. Name.text = PlayerPrefs.GetString("NAME", DefaultNames[rand]);
  19. }
  20. public void Connect()
  21. {
  22. int intVal = 0;
  23. bool Succeeded = int.TryParse(Port.text, out intVal);
  24. if (Succeeded)
  25. {
  26. Destroy(ServerManager.Instance.gameObject);
  27. ClientManager.Instance.StartClient(IP.text, intVal);
  28. }
  29. PlayerPrefs.SetString("IP", IP.text);
  30. PlayerPrefs.SetString("PORT", Port.text);
  31. PlayerPrefs.SetString("NAME", Name.text);
  32. }
  33. public void Host()
  34. {
  35. Server.SetActive(true);
  36. int intVal = 0;
  37. bool Succeeded = int.TryParse(Port.text, out intVal);
  38. if (Succeeded)
  39. {
  40. ServerManager.Instance.StartServer();
  41. }
  42. else
  43. {
  44. Server.SetActive(false);
  45. }
  46. IP.text = "127.0.0.1";
  47. PlayerPrefs.SetString("PORT", Port.text);
  48. PlayerPrefs.SetString("NAME", Name.text);
  49. PlayerPrefs.SetString("IP", IP.text);
  50. Connect();
  51. }
  52. public void ChangeName()
  53. {
  54. int rand = Random.Range(0, DefaultNames.Length);
  55. Name.text = DefaultNames[rand];
  56. Debug.Log("Name" + DefaultNames[rand]);
  57. }
  58. }