fix network discovery ; use git submodule

This commit is contained in:
in0finite 2022-04-03 02:19:39 +02:00
parent 0445f29dfd
commit 0edb0e3641
8 changed files with 165 additions and 79 deletions

3
.gitmodules vendored
View file

@ -10,3 +10,6 @@
[submodule "Assets/NavMeshes"]
path = Assets/NavMeshes
url = https://github.com/GTA-ASM/NavMeshes
[submodule "Assets/NetworkDiscoveryUnity"]
path = Assets/NetworkDiscoveryUnity
url = https://github.com/in0finite/NetworkDiscoveryUnity

@ -0,0 +1 @@
Subproject commit 723c3eadcd07f79083e8f2434ec6432b59deb9c0

View file

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: c87fbb2ff57b3b74b88c20989a0bac78
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -39,6 +39,9 @@ GameObject:
- component: {fileID: 2483599330734961439}
- component: {fileID: 6746758691818800092}
- component: {fileID: 6423383668577662412}
- component: {fileID: 492799016881118158}
- component: {fileID: 5842669163583086755}
- component: {fileID: 450012255851182817}
m_Layer: 0
m_Name: GameManager
m_TagString: Untagged
@ -550,3 +553,50 @@ MonoBehaviour:
m_EditorClassIdentifier:
m_maxTimePerFrameMs: 0
m_navMeshPathfindingIterationsPerFrame: 1000
--- !u!114 &492799016881118158
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1297494511425690}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 65d5e9cc49a255842837a7d853db68fe, type: 3}
m_Name:
m_EditorClassIdentifier:
m_serverPort: 18418
gameServerPortNumber: 7777
--- !u!114 &5842669163583086755
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1297494511425690}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 97d06c4b188731a47baf1a65a4b8a512, type: 3}
m_Name:
m_EditorClassIdentifier:
drawGUI: 0
offsetX: 5
offsetY: 150
width: 500
height: 400
refreshInterval: 3
onConnectEvent:
m_PersistentCalls:
m_Calls: []
--- !u!114 &450012255851182817
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1297494511425690}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 98aa3365f77ceca4b89c239f0d96a766, type: 3}
m_Name:
m_EditorClassIdentifier:

View file

@ -11,8 +11,6 @@ GameObject:
- component: {fileID: 434938348018962339}
- component: {fileID: 2570981519678807036}
- component: {fileID: 4862460140142645991}
- component: {fileID: 8720984785530044672}
- component: {fileID: 2615086005589439192}
m_Layer: 0
m_Name: NetworkManager
m_TagString: Untagged
@ -48,14 +46,14 @@ MonoBehaviour:
m_EditorClassIdentifier:
dontDestroyOnLoad: 1
runInBackground: 1
startOnHeadless: 0
autoStartServerBuild: 0
serverTickRate: 30
showDebugMessages: 0
offlineScene:
onlineScene:
transport: {fileID: 4862460140142645991}
networkAddress: localhost
maxConnections: 20
authenticator: {fileID: 0}
playerPrefab: {fileID: 3871880573184668455, guid: 750f4b120647dadf39075cba7361800a,
type: 3}
autoCreatePlayer: 1
@ -82,63 +80,15 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: c7424c1070fad4ba2a7a96b02fbeb4bb, type: 3}
m_Name:
m_EditorClassIdentifier:
OnClientConnected:
m_PersistentCalls:
m_Calls: []
OnClientDataReceived:
m_PersistentCalls:
m_Calls: []
OnClientError:
m_PersistentCalls:
m_Calls: []
OnClientDisconnected:
m_PersistentCalls:
m_Calls: []
OnServerConnected:
m_PersistentCalls:
m_Calls: []
OnServerDataReceived:
m_PersistentCalls:
m_Calls: []
OnServerError:
m_PersistentCalls:
m_Calls: []
OnServerDisconnected:
m_PersistentCalls:
m_Calls: []
port: 7777
NoDelay: 1
SendTimeout: 5000
ReceiveTimeout: 30000
serverMaxMessageSize: 16384
serverMaxReceivesPerTick: 10000
serverSendQueueLimitPerConnection: 10000
serverReceiveQueueLimitPerConnection: 10000
clientMaxMessageSize: 16384
--- !u!114 &8720984785530044672
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 4549513672316258300}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 65d5e9cc49a255842837a7d853db68fe, type: 3}
m_Name:
m_EditorClassIdentifier:
m_serverPort: 18418
gameServerPortNumber: 7777
--- !u!114 &2615086005589439192
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 4549513672316258300}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 97d06c4b188731a47baf1a65a4b8a512, type: 3}
m_Name:
m_EditorClassIdentifier:
drawGUI: 1
offsetX: 5
offsetY: 150
width: 500
height: 400
refreshInterval: 3
clientMaxReceivesPerTick: 1000
clientSendQueueLimit: 10000
clientReceiveQueueLimit: 10000

View file

@ -0,0 +1,61 @@
using UnityEngine;
using SanAndreasUnity.Utilities;
using NetworkDiscoveryUnity;
namespace SanAndreasUnity.Net
{
public class NetworkDiscoveryManager : StartupSingleton<NetworkDiscoveryManager>
{
public const string NumPlayersKey = "NumPlayers";
public const string MaxNumPlayersKey = "MaxNumPlayers";
public NetworkDiscovery NetworkDiscovery { get; private set; }
protected override void OnSingletonAwake()
{
this.NetworkDiscovery = this.GetComponentOrThrow<NetworkDiscovery>();
}
protected override void OnSingletonStart()
{
NetManager.Instance.onServerStatusChanged -= OnServerStatusChanged;
NetManager.Instance.onServerStatusChanged += OnServerStatusChanged;
Player.onStart -= OnPlayerStart;
Player.onStart += OnPlayerStart;
Player.onDisable -= OnPlayerDisable;
Player.onDisable += OnPlayerDisable;
this.AssignPlayerCounts();
}
private void OnServerStatusChanged()
{
if (NetStatus.IsServer)
{
this.AssignPlayerCounts();
this.NetworkDiscovery.EnsureServerIsInitialized();
}
else
this.NetworkDiscovery.CloseServerUdpClient();
}
private void OnPlayerStart(Player player)
{
this.AssignPlayerCounts();
}
private void OnPlayerDisable(Player player)
{
this.AssignPlayerCounts();
}
private void AssignPlayerCounts()
{
this.NetworkDiscovery.RegisterResponseData(NumPlayersKey, Player.AllPlayersList.Count.ToString());
this.NetworkDiscovery.RegisterResponseData(MaxNumPlayersKey, NetManager.maxNumPlayers.ToString());
}
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 98aa3365f77ceca4b89c239f0d96a766
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -4,7 +4,7 @@ using SanAndreasUnity.Utilities;
using SanAndreasUnity.Net;
using System.Linq;
using System.Threading.Tasks;
using Mirror.Discovery;
using NetworkDiscoveryUnity;
namespace SanAndreasUnity.UI
{
@ -45,11 +45,15 @@ namespace SanAndreasUnity.UI
float height = width * 9f / 16f;
this.windowRect = GUIUtils.GetCenteredRect(new Vector2(width, height));
m_netDiscoveryHUD = Mirror.NetworkManager.singleton.GetComponentOrThrow<NetworkDiscoveryHUD>();
// TODO: NetworkDiscoveryHud connection actions & draw gui
// m_netDiscoveryHUD.connectAction = this.ConnectFromDiscovery;
// m_netDiscoveryHUD.drawGUI = false;
m_netDiscoveryHUD = NetworkDiscoveryManager.Singleton.NetworkDiscovery.GetComponentOrThrow<NetworkDiscoveryHUD>();
m_netDiscoveryHUD.drawGUI = false;
m_netDiscoveryHUD.onConnectEvent.RemoveAllListeners();
m_netDiscoveryHUD.onConnectEvent.AddListener(this.ConnectFromDiscovery);
m_netDiscoveryHUD.additionalDataToDisplay.AddRange(new string[]
{
NetworkDiscoveryManager.NumPlayersKey,
NetworkDiscoveryManager.MaxNumPlayersKey,
});
}
void Update()
@ -88,9 +92,8 @@ namespace SanAndreasUnity.UI
}
else if (LanTabIndex == m_currentTabIndex)
{
//TODO: NetDiscovery Hud window resizing
//m_netDiscoveryHUD.width = (int) this.WindowSize.x - 30;
//m_netDiscoveryHUD.DisplayServers();
m_netDiscoveryHUD.width = (int) this.WindowSize.x - 30;
m_netDiscoveryHUD.DisplayServers();
}
else if (InternetTabIndex == m_currentTabIndex)
{
@ -165,10 +168,9 @@ namespace SanAndreasUnity.UI
{
if (LanTabIndex == m_currentTabIndex)
{
//TODO: NetDiscovery Hud visibility & button stuff
// GUI.enabled = ! m_netDiscoveryHUD.IsRefreshing;
// buttonText = m_netDiscoveryHUD.IsRefreshing ? ( "Refreshing." + new string('.', (int) ((Time.time * 2) % 3)) ) : "Refresh LAN";
// buttonAction = () => m_netDiscoveryHUD.Refresh();
GUI.enabled = ! m_netDiscoveryHUD.IsRefreshing;
buttonText = m_netDiscoveryHUD.IsRefreshing ? ( "Refreshing." + new string('.', (int) ((Time.time * 2) % 3)) ) : "Refresh LAN";
buttonAction = () => m_netDiscoveryHUD.Refresh();
}
else if (InternetTabIndex == m_currentTabIndex)
{
@ -208,20 +210,20 @@ namespace SanAndreasUnity.UI
void ConnectDirectly()
{
this.Connect(m_ipStr, int.Parse(m_portStr));
this.Connect(m_ipStr, ushort.Parse(m_portStr));
}
void ConnectFromDiscovery(ServerResponse info)
void ConnectFromDiscovery(NetworkDiscovery.DiscoveryInfo info)
{
this.Connect(info.EndPoint.Address.ToString(), info.EndPoint.Port);
this.Connect(info.EndPoint.Address.ToString(), info.GetGameServerPort());
}
void ConnectToServerFromMasterServer(ServerInfo serverInfo)
{
Connect(serverInfo.IP, serverInfo.Port);
Connect(serverInfo.IP, (ushort) serverInfo.Port);
}
void Connect(string ip, int port)
void Connect(string ip, ushort port)
{
try
{