Add headless check to Discovery (#1485)

This commit is contained in:
MrGadget 2020-02-07 06:13:09 -05:00 committed by GitHub
parent 9f7c30c1ac
commit 90d92fc0cf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 1 deletions

View File

@ -22,7 +22,7 @@ public class NetworkDiscovery : NetworkDiscoveryBase<ServerRequest, ServerRespon
[Tooltip("Invoked when a server is found")] [Tooltip("Invoked when a server is found")]
public ServerFoundUnityEvent OnServerFound; public ServerFoundUnityEvent OnServerFound;
public void Start() public override void Start()
{ {
ServerId = RandomLong(); ServerId = RandomLong();
@ -31,6 +31,8 @@ public void Start()
// Or just let the user assign it in the inspector // Or just let the user assign it in the inspector
if (transport == null) if (transport == null)
transport = Transport.activeTransport; transport = Transport.activeTransport;
base.Start();
} }
/// <summary> /// <summary>

View File

@ -57,6 +57,18 @@ public static long RandomLong()
return value1 + ((long)value2 << 32); return value1 + ((long)value2 << 32);
} }
/// <summary>
/// virtual so that inheriting classes' Start() can call base.Start() too
/// </summary>
public virtual void Start()
{
// headless mode? then start advertising
if (NetworkManager.isHeadless)
{
AdvertiseServer();
}
}
// Ensure the ports are cleared no matter when Game/Unity UI exits // Ensure the ports are cleared no matter when Game/Unity UI exits
void OnApplicationQuit() void OnApplicationQuit()
{ {