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.

67 lines
1.6 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. PlayerPrefs.SetString("PORT", Port.text);
  47. PlayerPrefs.SetString("NAME", Name.text);
  48. }
  49. public void ChangeName()
  50. {
  51. int rand = Random.Range(0, DefaultNames.Length);
  52. Name.text = DefaultNames[rand];
  53. Debug.Log("Name" + DefaultNames[rand]);
  54. }
  55. }