From 494484ef7867e8322ffb29ad71e89f7c1207ccc8 Mon Sep 17 00:00:00 2001 From: vis2k Date: Tue, 10 Aug 2021 19:32:17 +0800 Subject: [PATCH] ClientSceneTest_LocalPlayer_AsHost: huge cleanup --- .../ClientSceneTests_LocalPlayer_AsHost.cs | 91 +++---------------- 1 file changed, 13 insertions(+), 78 deletions(-) diff --git a/Assets/Mirror/Tests/Runtime/ClientSceneTests_LocalPlayer_AsHost.cs b/Assets/Mirror/Tests/Runtime/ClientSceneTests_LocalPlayer_AsHost.cs index 71502404f..650a2a55e 100644 --- a/Assets/Mirror/Tests/Runtime/ClientSceneTests_LocalPlayer_AsHost.cs +++ b/Assets/Mirror/Tests/Runtime/ClientSceneTests_LocalPlayer_AsHost.cs @@ -7,83 +7,26 @@ namespace Mirror.Tests.Runtime { public class ClientSceneTest_LocalPlayer_AsHost : MirrorPlayModeTest { - protected GameObject networkManagerGo; - protected NetworkManager manager; - - protected GameObject playerGO; - protected NetworkIdentity identity; - - protected virtual bool AutoAddPlayer => true; - - protected virtual void afterStartHost() {} - protected virtual void beforeStopHost() {} - [UnitySetUp] public override IEnumerator UnitySetUp() { - base.SetUp(); + yield return base.UnitySetUp(); - networkManagerGo = transport.gameObject; - manager = networkManagerGo.AddComponent(); - Transport.activeTransport = transport; - - // create a tracked prefab (not spawned) - CreateGameObject(out playerGO); - identity = playerGO.AddComponent(); - identity.assetId = System.Guid.NewGuid(); - - manager.playerPrefab = playerGO; - manager.autoStartServerBuild = false; - manager.autoCreatePlayer = AutoAddPlayer; - - if (Application.isBatchMode) - { - Application.targetFrameRate = 60; - } - - yield return null; - - manager.StartHost(); - - yield return null; - - afterStartHost(); - } - - [UnityTearDown] - public override IEnumerator UnityTearDown() - { - beforeStopHost(); - - yield return null; - - // needed for stophost - Transport.activeTransport = transport; - manager.StopHost(); - - base.TearDown(); + NetworkServer.Listen(1); + ConnectHostClientBlockingAuthenticatedAndReady(); } [UnityTest] public IEnumerator LocalPlayerIsSetToNullAfterNetworkDestroy() { - const uint netId = 1000; - CreateNetworked(out GameObject go, out NetworkIdentity identity); + // need spawned local player + CreateNetworkedAndSpawnPlayer(out GameObject go, out NetworkIdentity identity, NetworkServer.localConnection); - SpawnMessage msg = new SpawnMessage - { - netId = netId, - isLocalPlayer = true, - isOwner = true, - }; - - - NetworkIdentity.spawned[msg.netId] = identity; - NetworkClient.OnHostClientSpawn(msg); + // need to have localPlayer set for this test + Assert.That(NetworkClient.localPlayer, !Is.Null); + // unspawn, wait one frame for OnDestroy to be called NetworkServer.Destroy(identity.gameObject); - - // wait a frame for destroy to happen yield return null; // use "is null" here to avoid unity == check @@ -93,22 +36,14 @@ public IEnumerator LocalPlayerIsSetToNullAfterNetworkDestroy() [UnityTest] public IEnumerator LocalPlayerIsSetToNullAfterNetworkUnspawn() { - const uint netId = 1000; - CreateNetworked(out GameObject go, out NetworkIdentity identity); + // need spawned local player + CreateNetworkedAndSpawnPlayer(out GameObject go, out NetworkIdentity identity, NetworkServer.localConnection); - SpawnMessage msg = new SpawnMessage - { - netId = netId, - isLocalPlayer = true, - isOwner = true, - }; - - NetworkIdentity.spawned[msg.netId] = identity; - NetworkClient.OnHostClientSpawn(msg); + // need to have localPlayer set for this test + Assert.That(NetworkClient.localPlayer, !Is.Null); + // unspawn, wait one frame for OnDestroy to be called NetworkServer.UnSpawn(identity.gameObject); - - // wait a frame for destroy to happen yield return null; // use "is null" here to avoid unity == check