66 lines
2.1 KiB
C#
66 lines
2.1 KiB
C#
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using TMPro;
|
|
|
|
/// <summary>
|
|
/// Attach to a manager GameObject in host lobby.unity.
|
|
/// Reads radius from the "radius" slider/input and triggers CreateLobby.
|
|
/// Also wires the "vytvořit" button.
|
|
/// </summary>
|
|
public class HostLobbyUI : MonoBehaviour
|
|
{
|
|
[Header("Optional refs (auto-found by name if null)")]
|
|
public Slider radiusSlider;
|
|
public TMP_InputField radiusInput;
|
|
public Button createButton;
|
|
|
|
void Start()
|
|
{
|
|
if (radiusSlider == null)
|
|
{
|
|
var go = GameObject.Find("radius");
|
|
if (go != null) radiusSlider = go.GetComponent<Slider>();
|
|
}
|
|
if (radiusInput == null)
|
|
{
|
|
var go = GameObject.Find("radius");
|
|
if (go != null) radiusInput = go.GetComponent<TMP_InputField>();
|
|
}
|
|
|
|
if (createButton == null)
|
|
{
|
|
// Try all name variants used by the Art team
|
|
var go = GameObject.Find("stvo\u0159it") // stvořit
|
|
?? GameObject.Find("stvorit")
|
|
?? GameObject.Find("vytvo\u0159it") // vytvořit
|
|
?? GameObject.Find("vytvorit");
|
|
if (go != null)
|
|
{
|
|
createButton = go.GetComponent<Button>();
|
|
// Disable the Art team's direct scene-changer so only our
|
|
// wired OnCreateClicked fires (navigation is handled by
|
|
// HandleCreateLobbyResponse after the server confirms).
|
|
var sceneChanger = go.GetComponent<CudlikZmenaSceny>();
|
|
if (sceneChanger != null) sceneChanger.enabled = false;
|
|
}
|
|
}
|
|
|
|
if (createButton != null)
|
|
createButton.onClick.AddListener(OnCreateClicked);
|
|
}
|
|
|
|
private void OnCreateClicked()
|
|
{
|
|
var gm = GameManager.Instance;
|
|
if (gm == null) return;
|
|
|
|
// Read radius from slider or input field
|
|
if (radiusSlider != null)
|
|
gm.pendingRadius = radiusSlider.value;
|
|
else if (radiusInput != null && float.TryParse(radiusInput.text, out float r))
|
|
gm.pendingRadius = r;
|
|
|
|
gm.CreateLobbyButton();
|
|
}
|
|
}
|