breaking: replacing isHeadless with isServerBuild (#2093)

* replacing isHeadless with isServerBuild

* renaming startOnHeadless

* fixing isServerBuild bool

* making property a field instead

* replacing isServerBuild for #if UNITY_SERVER

* fixing comment and removing extra lines

* removing system from System.Obsolete

* renaming to autoStartServerBuild
This commit is contained in:
James Frowen 2020-08-20 12:56:46 +01:00 committed by GitHub
parent a2124c3522
commit 99d4f8c9bd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 30 additions and 28 deletions

View File

@ -62,11 +62,10 @@ public static long RandomLong()
/// </summary>
public virtual void Start()
{
// headless mode? then start advertising
if (NetworkManager.isHeadless)
{
// Server mode? then start advertising
#if UNITY_SERVER
AdvertiseServer();
}
#endif
}
// Ensure the ports are cleared no matter when Game/Unity UI exits

View File

@ -55,10 +55,11 @@ Setting showStartButton false when the button is pressed hides it in the game sc
public override void OnRoomServerPlayersReady()
{
// calling the base method calls ServerChangeScene as soon as all players are in Ready state.
if (isHeadless)
#if UNITY_SERVER
base.OnRoomServerPlayersReady();
else
#else
showStartButton = true;
#endif
}
public override void OnGUI()

View File

@ -14,10 +14,9 @@ public class NetworkHeadlessLogger : MonoBehaviour
void Awake()
{
if (NetworkManager.isHeadless)
{
#if UNITY_SERVER
LogFactory.ReplaceLogHandler(new ConsoleColorLogHandler(showExceptionStackTrace));
}
#endif
}
}
}

View File

@ -45,10 +45,15 @@ public class NetworkManager : MonoBehaviour
/// <summary>
/// Automatically invoke StartServer()
/// <para>If the application is a Server Build or run with the -batchMode command line arguement, StartServer is automatically invoked.</para>
/// <para>If the application is a Server Build, StartServer is automatically invoked.</para>
/// <para>Server build is true when "Server build" is checked in build menu, or BuildOptions.EnableHeadlessMode flag is in BuildOptions</para>
/// </summary>
[Tooltip("Should the server auto-start when the game is started in a headless build?")]
public bool startOnHeadless = true;
[Tooltip("Should the server auto-start when 'Server Build' is checked in build settings")]
[FormerlySerializedAs("startOnHeadless")]
public bool autoStartServerBuild = true;
[Obsolete("Use autoStartServerBuild instead.")]
public bool startOnHeadless { get => autoStartServerBuild; set => autoStartServerBuild = value; }
/// <summary>
/// Enables verbose debug messages in the console
@ -185,6 +190,7 @@ public class NetworkManager : MonoBehaviour
/// <summary>
/// headless mode detection
/// </summary>
[Obsolete("Use #if UNITY_SERVER instead.")]
public static bool isHeadless => SystemInfo.graphicsDeviceType == GraphicsDeviceType.Null;
// helper enum to know if we started the networkmanager as server/client/host.
@ -255,10 +261,12 @@ public virtual void Start()
// some transports might not be ready until Start.
//
// (tick rate is applied in StartServer!)
if (isHeadless && startOnHeadless)
#if UNITY_SERVER
if (autoStartServerBuild)
{
StartServer();
}
#endif
}
// NetworkIdentity.UNetStaticUpdate is called from UnityEngine while LLAPI network is active.
@ -675,15 +683,10 @@ public virtual void OnApplicationQuit()
/// </summary>
public virtual void ConfigureServerFrameRate()
{
// set a fixed tick rate instead of updating as often as possible
// * if not in Editor (it doesn't work in the Editor)
// * if not in Host mode
#if !UNITY_EDITOR
if (!NetworkClient.active && isHeadless)
{
// only set framerate for server build
#if UNITY_SERVER
Application.targetFrameRate = serverTickRate;
if (logger.logEnabled) logger.Log("Server Tick Rate set to: " + Application.targetFrameRate + " Hz.");
}
#endif
}

View File

@ -29,7 +29,7 @@ public void VariableTest()
{
Assert.That(manager.dontDestroyOnLoad, Is.True);
Assert.That(manager.runInBackground, Is.True);
Assert.That(manager.startOnHeadless, Is.True);
Assert.That(manager.autoStartServerBuild, Is.True);
Assert.That(manager.showDebugMessages, Is.False);
Assert.That(manager.serverTickRate, Is.EqualTo(30));
Assert.That(manager.offlineScene, Is.Empty);

View File

@ -27,7 +27,7 @@ public IEnumerator SetupHost()
identity.assetId = System.Guid.NewGuid();
manager.playerPrefab = playerGO;
manager.startOnHeadless = false;
manager.autoStartServerBuild = false;
yield return null;