deltavr multiplayer 2.0

This commit is contained in:
Toomas Tamm
2023-05-08 15:56:10 +03:00
parent 978809a002
commit 07b9b9e2f4
10937 changed files with 2968397 additions and 1521012 deletions

View File

@@ -0,0 +1,117 @@
using System.Collections.Generic;
using System.Net;
using UnityEngine;
namespace FishNet.Discovery
{
public sealed class NetworkDiscoveryHUD : MonoBehaviour
{
[SerializeField]
private NetworkDiscovery networkDiscovery;
private Camera _camera;
private readonly List<IPEndPoint> _endPoints = new List<IPEndPoint>();
private Vector2 _serversListScrollVector;
private bool _useVR;
private void Start()
{
if (networkDiscovery == null) networkDiscovery = FindObjectOfType<NetworkDiscovery>();
_camera = GetComponentInChildren<Camera>();
_useVR = PlayerPrefs.GetInt("UseVR", 0) == 1;
networkDiscovery.ServerFoundCallback += (endPoint) =>
{
if (!_endPoints.Contains(endPoint)) _endPoints.Add(endPoint);
};
}
private void OnGUI()
{
GUILayoutOption buttonHeight = GUILayout.Height(30.0f);
using (new GUILayout.AreaScope(new Rect(Screen.width - 240.0f - 10.0f, 10.0f, 240.0f, Screen.height - 20.0f)))
{
GUILayout.Box("Settings");
using (new GUILayout.HorizontalScope())
{
bool useVRNew = GUILayout.Toggle(_useVR, "Use VR");
if (useVRNew != _useVR)
{
_useVR = useVRNew;
PlayerPrefs.SetInt("UseVR", _useVR ? 1 : 0);
Debug.Log($"UseVR set to {_useVR}");
}
}
GUILayout.Box("Server");
using (new GUILayout.HorizontalScope())
{
if (GUILayout.Button("Start", buttonHeight)) InstanceFinder.ServerManager.StartConnection();
if (GUILayout.Button("Stop", buttonHeight)) InstanceFinder.ServerManager.StopConnection(true);
}
GUILayout.Box("Advertising");
using (new GUILayout.HorizontalScope())
{
if (networkDiscovery.IsAdvertising)
{
if (GUILayout.Button("Stop", buttonHeight)) networkDiscovery.StopAdvertisingServer();
}
else
{
if (GUILayout.Button("Start", buttonHeight)) networkDiscovery.StartAdvertisingServer();
}
}
GUILayout.Box("Searching");
using (new GUILayout.HorizontalScope())
{
if (networkDiscovery.IsSearching)
{
if (GUILayout.Button("Stop", buttonHeight)) networkDiscovery.StopSearchingForServers();
}
else
{
if (GUILayout.Button("Start", buttonHeight)) networkDiscovery.StartSearchingForServers();
}
}
if (_endPoints.Count > 0)
{
GUILayout.Box("Servers");
using (new GUILayout.ScrollViewScope(_serversListScrollVector))
{
for (int i = 0; i < _endPoints.Count; i++)
{
string ipAddress = _endPoints[i].Address.ToString();
if (GUILayout.Button(ipAddress))
{
//networkDiscovery.StopAdvertisingServer();
networkDiscovery.StopSearchingForServers();
_camera.enabled = false;
InstanceFinder.ClientManager.StartConnection(ipAddress);
}
}
}
}
}
}
}
}