Utils.IsHeadless so it can be reused by other classes if needed.

This commit is contained in:
vis2k 2019-02-22 20:43:25 +01:00
parent 2a9d7e2df3
commit d3afa9f26f
2 changed files with 10 additions and 3 deletions

View File

@ -57,9 +57,9 @@ public class NetworkManager : MonoBehaviour
public int numPlayers => NetworkServer.connections.Count(kv => kv.Value.playerController != null);
// runtime data
// this is used to make sure that all scene changes are initialized by UNET.
// this is used to make sure that all scene changes are initialized by UNET.
// Loading a scene manually wont set networkSceneName, so UNET would still load it again on start.
public static string networkSceneName = "";
public static string networkSceneName = "";
[NonSerialized]
public bool isNetworkActive;
public NetworkClient client;
@ -85,7 +85,7 @@ public virtual void Awake()
InitializeSingleton();
// headless mode? then start the server
if (SystemInfo.graphicsDeviceType == GraphicsDeviceType.Null && startOnHeadless)
if (Utils.IsHeadless() && startOnHeadless)
{
Application.targetFrameRate = 60;
StartServer();

View File

@ -1,5 +1,6 @@
using System;
using UnityEngine;
using UnityEngine.Rendering;
namespace Mirror
{
@ -184,5 +185,11 @@ public static float[] UnpackUShortIntoThreeFloats(ushort combined, float minTarg
float w = ScaleByteToFloat(upper, 0x00, 0x1F, minTarget, maxTarget);
return new float[]{u, v, w};
}
// headless mode detection
public static bool IsHeadless()
{
return SystemInfo.graphicsDeviceType == GraphicsDeviceType.Null;
}
}
}