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> /// </summary>
public virtual void Start() public virtual void Start()
{ {
// headless mode? then start advertising // Server mode? then start advertising
if (NetworkManager.isHeadless) #if UNITY_SERVER
{
AdvertiseServer(); AdvertiseServer();
} #endif
} }
// Ensure the ports are cleared no matter when Game/Unity UI exits // 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() public override void OnRoomServerPlayersReady()
{ {
// calling the base method calls ServerChangeScene as soon as all players are in Ready state. // calling the base method calls ServerChangeScene as soon as all players are in Ready state.
if (isHeadless) #if UNITY_SERVER
base.OnRoomServerPlayersReady(); base.OnRoomServerPlayersReady();
else #else
showStartButton = true; showStartButton = true;
#endif
} }
public override void OnGUI() public override void OnGUI()

View File

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

View File

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

View File

@ -29,7 +29,7 @@ public void VariableTest()
{ {
Assert.That(manager.dontDestroyOnLoad, Is.True); Assert.That(manager.dontDestroyOnLoad, Is.True);
Assert.That(manager.runInBackground, 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.showDebugMessages, Is.False);
Assert.That(manager.serverTickRate, Is.EqualTo(30)); Assert.That(manager.serverTickRate, Is.EqualTo(30));
Assert.That(manager.offlineScene, Is.Empty); Assert.That(manager.offlineScene, Is.Empty);

View File

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