mirror of
https://github.com/MirrorNetworking/Mirror.git
synced 2024-11-18 11:00:32 +00:00
ClientSceneTest_LocalPlayer_AsHost: huge cleanup
This commit is contained in:
parent
4925f1397a
commit
494484ef78
@ -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<NetworkManager>();
|
||||
Transport.activeTransport = transport;
|
||||
|
||||
// create a tracked prefab (not spawned)
|
||||
CreateGameObject(out playerGO);
|
||||
identity = playerGO.AddComponent<NetworkIdentity>();
|
||||
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
|
||||
|
Loading…
Reference in New Issue
Block a user