You cannot 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.8 KiB
C#
74 lines
1.8 KiB
C#
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using System.Net;
|
|
using System.Net.Sockets;
|
|
|
|
public class MultiplayerMenuManager : MonoBehaviour
|
|
{
|
|
[Header("UI Panels")]
|
|
public GameObject hostPopup;
|
|
public GameObject joinPopup;
|
|
|
|
[Header("Host Popup Elements")]
|
|
public Text hostIPText;
|
|
|
|
[Header("Join Popup Elements")]
|
|
public InputField joinIPInput;
|
|
|
|
// === Called when HOST button is clicked ===
|
|
public void OnClick_Host()
|
|
{
|
|
string localIP = GetLocalIPAddress();
|
|
hostIPText.text = "Your IP: " + localIP;
|
|
hostPopup.SetActive(true); // Just show popup for now
|
|
}
|
|
public void OnClick_HostConfirm()
|
|
{
|
|
//NetworkManager.singleton.StartHost(); // Actually starts the host now
|
|
}
|
|
|
|
// === Called when JOIN button is clicked ===
|
|
public void OnClick_Join()
|
|
{
|
|
joinPopup.SetActive(true);
|
|
}
|
|
|
|
// === Called when JOIN > START is clicked ===
|
|
public void OnClick_JoinConfirm()
|
|
{
|
|
string ip = joinIPInput.text.Trim();
|
|
//if (!string.IsNullOrEmpty(ip))
|
|
//{
|
|
// NetworkManager.singleton.networkAddress = ip;
|
|
// NetworkManager.singleton.StartClient();
|
|
//}
|
|
}
|
|
|
|
// === Close popups ===
|
|
public void OnClick_CloseAllPopups()
|
|
{
|
|
hostPopup.SetActive(false);
|
|
joinPopup.SetActive(false);
|
|
}
|
|
|
|
// === Utility: Get local IP for LAN ===
|
|
private string GetLocalIPAddress()
|
|
{
|
|
string localIP = "Unavailable";
|
|
try
|
|
{
|
|
var host = Dns.GetHostEntry(Dns.GetHostName());
|
|
foreach (var ip in host.AddressList)
|
|
{
|
|
if (ip.AddressFamily == AddressFamily.InterNetwork)
|
|
{
|
|
localIP = ip.ToString();
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
catch { }
|
|
return localIP;
|
|
}
|
|
}
|