feat(NetworkManager): Ability to toggle auto-start in Editor (#3694)

* feat(NetworkManager): Ability to toggle auto-start in Editor

* use Application.isEditor

---------

Co-authored-by: mischa <info@noobtuts.com>
This commit is contained in:
MrGadget 2023-12-06 08:27:46 -05:00 committed by GitHub
parent 92b99335d8
commit ab99215e68
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -29,11 +29,14 @@ public class NetworkManager : MonoBehaviour
public bool runInBackground = true;
/// <summary>Should the server auto-start when 'Server Build' is checked in build settings</summary>
[Header("Headless Builds")]
[Header("Auto-Start Options")]
[Tooltip("Choose whether Server or Client should auto-start in headless builds")]
public HeadlessStartOptions headlessStartMode = HeadlessStartOptions.DoNothing;
[Tooltip("Headless Start Mode in Editor\nwhen enabled, headless start mode will be used in editor as well.")]
public bool editorAutoStart;
/// <summary>Server Update frequency, per second. Use around 60Hz for fast paced games like Counter-Strike to minimize latency. Use around 30Hz for games like WoW to minimize computations. Use around 1-10Hz for slow paced games like EVE.</summary>
[Tooltip("Server & Client send rate per second. Use 60-100Hz for fast paced games like Counter-Strike to minimize latency. Use around 30Hz for games like WoW to minimize computations. Use around 1-10Hz for slow paced games like EVE.")]
[FormerlySerializedAs("serverTickRate")]
@ -256,11 +259,11 @@ public virtual void Start()
// We can't do this in Awake because Awake is for initialization
// and some transports might not be ready until Start.
//
// don't auto start in editor where we have a UI, only in builds.
// otherwise if we switch to 'Dedicated Server' target and press
// Play, it would auto start the server every time.
// Auto-starting in Editor is useful for debugging, so that can
// be enabled with editorAutoStart.
if (Utils.IsHeadless())
{
if (!Application.isEditor || editorAutoStart)
switch (headlessStartMode)
{
case HeadlessStartOptions.AutoStartServer: