mirror of
https://github.com/MirrorNetworking/Mirror.git
synced 2024-11-18 02:50:32 +00:00
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:
parent
a2124c3522
commit
99d4f8c9bd
@ -62,11 +62,10 @@ public static long RandomLong()
|
||||
/// </summary>
|
||||
public virtual void Start()
|
||||
{
|
||||
// headless mode? then start advertising
|
||||
if (NetworkManager.isHeadless)
|
||||
{
|
||||
AdvertiseServer();
|
||||
}
|
||||
// Server mode? then start advertising
|
||||
#if UNITY_SERVER
|
||||
AdvertiseServer();
|
||||
#endif
|
||||
}
|
||||
|
||||
// Ensure the ports are cleared no matter when Game/Unity UI exits
|
||||
|
@ -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)
|
||||
base.OnRoomServerPlayersReady();
|
||||
else
|
||||
showStartButton = true;
|
||||
#if UNITY_SERVER
|
||||
base.OnRoomServerPlayersReady();
|
||||
#else
|
||||
showStartButton = true;
|
||||
#endif
|
||||
}
|
||||
|
||||
public override void OnGUI()
|
||||
|
@ -14,10 +14,9 @@ public class NetworkHeadlessLogger : MonoBehaviour
|
||||
|
||||
void Awake()
|
||||
{
|
||||
if (NetworkManager.isHeadless)
|
||||
{
|
||||
LogFactory.ReplaceLogHandler(new ConsoleColorLogHandler(showExceptionStackTrace));
|
||||
}
|
||||
#if UNITY_SERVER
|
||||
LogFactory.ReplaceLogHandler(new ConsoleColorLogHandler(showExceptionStackTrace));
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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)
|
||||
{
|
||||
Application.targetFrameRate = serverTickRate;
|
||||
if (logger.logEnabled) logger.Log("Server Tick Rate set to: " + Application.targetFrameRate + " Hz.");
|
||||
}
|
||||
// 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
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
|
@ -27,7 +27,7 @@ public IEnumerator SetupHost()
|
||||
identity.assetId = System.Guid.NewGuid();
|
||||
|
||||
manager.playerPrefab = playerGO;
|
||||
manager.startOnHeadless = false;
|
||||
manager.autoStartServerBuild = false;
|
||||
|
||||
yield return null;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user