using UnityEngine;
public class UICreateServer : MonoBehaviour
{
public UIButton button;
public UILabel buttonText;
public UIInput serverName;
public bool internet = false;
public string lobbyServ;
void Start ()
{
UIEventListener.Get(button.gameObject).onClick = OnButtonClick;
EventDelegate.Set(serverName.onSubmit, OnNameChange);
}
void OnEnable ()
{
UpdateButtonText();
}
void OnButtonClick (GameObject go)
{
if (!TNServerInstance.isActive)
{
TNServerInstance.serverName = string.IsNullOrEmpty(serverName.value) ? "LAN Server" : serverName.value;
if(!internet)
{
TNServerInstance.Start(5127, 0, null, 5129);
UpdateButtonText();
}
else
{
TNServerInstance.Start (5127,0,null,TNServerInstance.Type.Tcp,TNet.Tools.ResolveEndPoint (lobbyServ,5129));
UpdateButtonText();
}
}
else
{
TNServerInstance.Stop();
UpdateButtonText();
}
}
void OnNameChange ()
{
TNServerInstance.serverName = string.IsNullOrEmpty(UIInput.current.value) ? "LAN Server" : UIInput.current.value;
}
void UpdateButtonText ()
{
buttonText.text = Localization.Localize(TNServerInstance.isActive ? "Stop" : "Start");
}
}