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

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using Multiplayer;
using TMPro;
public class HomeScreenManager : MonoBehaviour {
public TMP_InputField IP;
public TMP_InputField Port;
public TMP_InputField Name;
public GameObject Server;
public string[] DefaultNames;
public void Start()
{
Screen.orientation = ScreenOrientation.Landscape;
int rand = Random.Range(0, DefaultNames.Length);
IP.text = PlayerPrefs.GetString("IP", "");
Port.text = PlayerPrefs.GetString("PORT", "4444");
Name.text = PlayerPrefs.GetString("NAME", DefaultNames[rand]);
}
public void Connect()
{
int intVal = 0;
bool Succeeded = int.TryParse(Port.text, out intVal);
if (Succeeded)
{
//Destroy(ServerManager.Instance.gameObject);
ClientManager.Instance.Name = Name.text;
ClientManager.Instance.StartClient(IP.text, intVal);
}
PlayerPrefs.SetString("IP", IP.text);
PlayerPrefs.SetString("PORT", Port.text);
PlayerPrefs.SetString("NAME", Name.text);
}
public void Host()
{
Server.SetActive(true);
int intVal = 0;
bool Succeeded = int.TryParse(Port.text, out intVal);
if (Succeeded)
{
ServerManager.Instance.StartServer();
}
else
{
Server.SetActive(false);
}
IP.text = IPGrabber.GetIP(ADDRESSFAM.IPv4);
PlayerPrefs.SetString("PORT", Port.text);
PlayerPrefs.SetString("NAME", Name.text);
PlayerPrefs.SetString("IP", IP.text);
//Connect();
}
public void ChangeName()
{
int rand = Random.Range(0, DefaultNames.Length);
Name.text = DefaultNames[rand];
Debug.Log("Name" + DefaultNames[rand]);
}
}