Updated the UI. Refresh button is disabled for now and multiplayer needs testing. Added quit button.
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
using FishNet;
|
||||
using FishNet.Discovery;
|
||||
using FishNet.Managing.Scened;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Net;
|
||||
@@ -10,15 +11,21 @@ using UnityEngine.UI;
|
||||
public class NetworkMenuUI : MonoBehaviour
|
||||
{
|
||||
[Header("UI References")]
|
||||
public Toggle VRToggle;
|
||||
|
||||
public Button startPlayingButton;
|
||||
public Button reloadButton;
|
||||
public Button joinMultiplayerButton;
|
||||
public Transform serverListContainer;
|
||||
public GameObject serverListItemPrefab;
|
||||
public TMP_Text statusText;
|
||||
public Button quitButton;
|
||||
|
||||
[Header("Networking")]
|
||||
public NetworkDiscovery networkDiscovery;
|
||||
public Camera uiCamera; // Optional, disable if connecting
|
||||
public Camera uiCamera;
|
||||
public AudioListener placeholderAudioListener;
|
||||
private bool _useVR;
|
||||
//public Image coverImage;
|
||||
|
||||
private readonly List<IPEndPoint> foundServers = new();
|
||||
@@ -28,8 +35,22 @@ public class NetworkMenuUI : MonoBehaviour
|
||||
if (networkDiscovery == null)
|
||||
networkDiscovery = FindObjectOfType<NetworkDiscovery>();
|
||||
|
||||
_useVR = PlayerPrefs.GetInt("UseVR", 0) == 1;
|
||||
VRToggle.isOn = _useVR;
|
||||
|
||||
// React to UI toggle changes
|
||||
VRToggle.onValueChanged.AddListener((isOn) =>
|
||||
{
|
||||
_useVR = isOn;
|
||||
PlayerPrefs.SetInt("UseVR", _useVR ? 1 : 0);
|
||||
PlayerPrefs.Save();
|
||||
Debug.Log($"UseVR set to {_useVR}");
|
||||
});
|
||||
|
||||
startPlayingButton.onClick.AddListener(OnStartPlaying);
|
||||
reloadButton.onClick.AddListener(OnReload);
|
||||
joinMultiplayerButton.onClick.AddListener(OnJoinMultiplayer);
|
||||
quitButton.onClick.AddListener(OnQuit);
|
||||
|
||||
networkDiscovery.ServerFoundCallback += OnServerFound;
|
||||
}
|
||||
@@ -40,6 +61,14 @@ public class NetworkMenuUI : MonoBehaviour
|
||||
StartCoroutine(HostAndSearchRoutine());
|
||||
}
|
||||
|
||||
private void OnReload()
|
||||
{
|
||||
|
||||
//UnityEngine.SceneManagement.Scene currentScene = UnityEngine.SceneManagement.SceneManager.GetActiveScene();
|
||||
//UnityEngine.SceneManagement.SceneManager.LoadScene(currentScene.name);
|
||||
|
||||
|
||||
}
|
||||
|
||||
private void OnJoinMultiplayer()
|
||||
{
|
||||
@@ -49,6 +78,12 @@ public class NetworkMenuUI : MonoBehaviour
|
||||
networkDiscovery.StartSearchingForServers();
|
||||
}
|
||||
|
||||
private void OnQuit()
|
||||
{
|
||||
Debug.Log("Quitting application");
|
||||
Application.Quit();
|
||||
}
|
||||
|
||||
private void OnServerFound(IPEndPoint endPoint)
|
||||
{
|
||||
if (foundServers.Contains(endPoint)) return;
|
||||
@@ -61,9 +96,11 @@ public class NetworkMenuUI : MonoBehaviour
|
||||
networkDiscovery.StopSearchingForServers();
|
||||
|
||||
uiCamera.enabled = false;
|
||||
Debug.Log("Disabled placeholder audio source");
|
||||
placeholderAudioListener.enabled = false;
|
||||
//coverImage.gameObject.SetActive(false);
|
||||
|
||||
InstanceFinder.ClientManager.StartConnection("192.168.42.212");
|
||||
InstanceFinder.ClientManager.StartConnection(endPoint.Address.ToString());
|
||||
statusText.text = $"Joined server: {endPoint.Address}";
|
||||
return;
|
||||
}
|
||||
@@ -78,6 +115,10 @@ public class NetworkMenuUI : MonoBehaviour
|
||||
{
|
||||
networkDiscovery.StopSearchingForServers();
|
||||
if (uiCamera != null) uiCamera.enabled = false;
|
||||
if (placeholderAudioListener != null) {
|
||||
Debug.Log("Disabled placeholder audio source");
|
||||
placeholderAudioListener.enabled = false;
|
||||
}
|
||||
//coverImage.gameObject.SetActive(false);
|
||||
InstanceFinder.ClientManager.StartConnection(endPoint.Address.ToString());
|
||||
statusText.text = $"Joined server: {endPoint.Address}";
|
||||
@@ -121,6 +162,12 @@ public class NetworkMenuUI : MonoBehaviour
|
||||
{
|
||||
var firstServer = foundServers[0];
|
||||
//networkDiscovery.StopAdvertisingServer();
|
||||
if (uiCamera != null) uiCamera.enabled = false;
|
||||
if (placeholderAudioListener != null)
|
||||
{
|
||||
Debug.Log("Disabled placeholder audio source");
|
||||
placeholderAudioListener.enabled = false;
|
||||
}
|
||||
networkDiscovery.StopSearchingForServers();
|
||||
InstanceFinder.ClientManager.StartConnection(firstServer.Address.ToString());
|
||||
statusText.text = $"Joined server: {firstServer.Address}";
|
||||
|
||||
Reference in New Issue
Block a user