Update HostSetup.cs

adding virtual methods for test setup
This commit is contained in:
James Frowen 2021-01-25 16:04:51 +00:00 committed by GitHub
parent 7bcf957c23
commit 3fcc7415b4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,5 +1,4 @@
using System.Collections; using System.Collections;
using NUnit.Framework;
using UnityEngine; using UnityEngine;
using UnityEngine.TestTools; using UnityEngine.TestTools;
@ -14,6 +13,11 @@ public class HostSetup
protected GameObject playerGO; protected GameObject playerGO;
protected NetworkIdentity identity; protected NetworkIdentity identity;
protected virtual bool AutoAddPlayer => true;
protected virtual void afterStartHost() { }
protected virtual void beforeStopHost() { }
[UnitySetUp] [UnitySetUp]
public IEnumerator SetupHost() public IEnumerator SetupHost()
{ {
@ -28,15 +32,30 @@ public IEnumerator SetupHost()
manager.playerPrefab = playerGO; manager.playerPrefab = playerGO;
manager.autoStartServerBuild = false; manager.autoStartServerBuild = false;
manager.autoCreatePlayer = AutoAddPlayer;
if (Application.isBatchMode)
{
Application.targetFrameRate = 60;
}
yield return null; yield return null;
manager.StartHost(); manager.StartHost();
yield return null;
afterStartHost();
} }
[TearDown]
public void ShutdownHost() [UnityTearDown]
public IEnumerator ShutdownHost()
{ {
beforeStopHost();
yield return null;
Object.DestroyImmediate(playerGO); Object.DestroyImmediate(playerGO);
manager.StopHost(); manager.StopHost();
Object.DestroyImmediate(networkManagerGo); Object.DestroyImmediate(networkManagerGo);