public void FindOrSpawnObject_SpawnHandlerCalledFromDictionary() { const uint netId = 1003; int handlerCalled = 0; SpawnMessage msg = new SpawnMessage { netId = netId, assetId = validPrefabGuid }; GameObject createdInhandler = null; spawnHandlers.Add(validPrefabGuid, (x) => { handlerCalled++; Assert.That(x, Is.EqualTo(msg)); createdInhandler = new GameObject("testObj", typeof(NetworkIdentity)); _createdObjects.Add(createdInhandler); return(createdInhandler); }); bool success = ClientScene.FindOrSpawnObject(msg, out NetworkIdentity networkIdentity); Assert.IsTrue(success); Assert.IsNotNull(networkIdentity); Assert.That(handlerCalled, Is.EqualTo(1)); Assert.That(networkIdentity.gameObject, Is.EqualTo(createdInhandler), "Object returned should be the same object created by the spawn handler"); }
public void FindOrSpawnObject_SpawnsFromPrefabIfBothPrefabAndHandlerExists() { const uint netId = 1003; int handlerCalled = 0; SpawnMessage msg = new SpawnMessage { netId = netId, assetId = validPrefabGuid }; prefabs.Add(validPrefabGuid, validPrefab); spawnHandlers.Add(validPrefabGuid, (x) => { handlerCalled++; GameObject go = new GameObject("testObj", typeof(NetworkIdentity)); _createdObjects.Add(go); return(go); }); bool success = ClientScene.FindOrSpawnObject(msg, out NetworkIdentity networkIdentity); Assert.IsTrue(success); Assert.IsNotNull(networkIdentity); Assert.That(networkIdentity.name, Is.EqualTo(validPrefab.name + "(Clone)")); Assert.That(handlerCalled, Is.EqualTo(0), "Handler should not have been called"); }
public void FindOrSpawnObject_ErrorWhenNoExistingAndAssetIdAndSceneIdAreBothEmpty() { const uint netId = 1001; SpawnMessage msg = new SpawnMessage { assetId = new Guid(), sceneId = 0, netId = netId }; LogAssert.Expect(LogType.Error, $"OnSpawn message with netId '{netId}' has no AssetId or sceneId"); bool success = ClientScene.FindOrSpawnObject(msg, out NetworkIdentity networkIdentity); Assert.IsFalse(success); Assert.IsNull(networkIdentity); }
public void FindOrSpawnObject_ErrorWhenSceneIdIsNotInSpawnableObjectsDictionary() { const uint netId = 1004; const int sceneId = 100021; SpawnMessage msg = new SpawnMessage { netId = netId, sceneId = sceneId, }; LogAssert.Expect(LogType.Error, $"Spawn scene object not found for {msg.sceneId.ToString("X")} SpawnableObjects.Count={spawnableObjects.Count}"); LogAssert.Expect(LogType.Error, $"Could not spawn assetId={msg.assetId} scene={msg.sceneId} netId={msg.netId}"); bool success = ClientScene.FindOrSpawnObject(msg, out NetworkIdentity networkIdentity); Assert.IsFalse(success); Assert.IsNull(networkIdentity); }
public void FindOrSpawnObject_UsesSceneIdToSpawnFromSpawnableObjectsDictionary() { const uint netId = 1003; const int sceneId = 100020; SpawnMessage msg = new SpawnMessage { netId = netId, sceneId = sceneId }; NetworkIdentity sceneObject = CreateSceneObject(sceneId); bool success = ClientScene.FindOrSpawnObject(msg, out NetworkIdentity networkIdentity); Assert.IsTrue(success); Assert.IsNotNull(networkIdentity); Assert.That(networkIdentity, Is.EqualTo(sceneObject)); }
public void FindOrSpawnObject_SpawnsUsingSceneIdInsteadOfAssetId() { const uint netId = 1003; const int sceneId = 100020; SpawnMessage msg = new SpawnMessage { netId = netId, sceneId = sceneId, assetId = validPrefabGuid }; prefabs.Add(validPrefabGuid, validPrefab); NetworkIdentity sceneObject = CreateSceneObject(sceneId); bool success = ClientScene.FindOrSpawnObject(msg, out NetworkIdentity networkIdentity); Assert.IsTrue(success); Assert.IsNotNull(networkIdentity); Assert.That(networkIdentity, Is.EqualTo(sceneObject)); }
public void FindOrSpawnObject_ErrorWhenPrefabInNullInDictionary() { const uint netId = 1002; SpawnMessage msg = new SpawnMessage { netId = netId, assetId = validPrefabGuid }; // could happen if the prefab is destroyed or unloaded prefabs.Add(validPrefabGuid, null); LogAssert.Expect(LogType.Error, $"Failed to spawn server object, did you forget to add it to the NetworkManager? assetId={msg.assetId} netId={msg.netId}"); LogAssert.Expect(LogType.Error, $"Could not spawn assetId={msg.assetId} scene={msg.sceneId} netId={msg.netId}"); bool success = ClientScene.FindOrSpawnObject(msg, out NetworkIdentity networkIdentity); Assert.IsFalse(success); Assert.IsNull(networkIdentity); }
public void FindOrSpawnObject_SpawnsFromPrefabDictionary() { const uint netId = 1002; SpawnMessage msg = new SpawnMessage { netId = netId, assetId = validPrefabGuid }; prefabs.Add(validPrefabGuid, validPrefab); bool success = ClientScene.FindOrSpawnObject(msg, out NetworkIdentity networkIdentity); Assert.IsTrue(success); Assert.IsNotNull(networkIdentity); Assert.That(networkIdentity.name, Is.EqualTo(validPrefab.name + "(Clone)")); // cleanup GameObject.DestroyImmediate(networkIdentity.gameObject); }
public void FindOrSpawnObject_ErrorWhenSpawnHanlderReturnsNull() { const uint netId = 1003; SpawnMessage msg = new SpawnMessage { netId = netId, assetId = validPrefabGuid }; spawnHandlers.Add(validPrefabGuid, (x) => { return(null); }); LogAssert.Expect(LogType.Error, $"Spawn Handler returned null, Handler assetId '{msg.assetId}'"); LogAssert.Expect(LogType.Error, $"Could not spawn assetId={msg.assetId} scene={msg.sceneId} netId={msg.netId}"); bool success = ClientScene.FindOrSpawnObject(msg, out NetworkIdentity networkIdentity); Assert.IsFalse(success); Assert.IsNull(networkIdentity); }
public void FindOrSpawnObject_FindExistingObject() { const uint netId = 1000; GameObject go = new GameObject(); NetworkIdentity existing = go.AddComponent<NetworkIdentity>(); existing.netId = netId; spawned.Add(netId, existing); SpawnMessage msg = new SpawnMessage { netId = netId }; bool success = ClientScene.FindOrSpawnObject(msg, out NetworkIdentity found); Assert.IsTrue(success); Assert.That(found, Is.EqualTo(existing)); // cleanup GameObject.DestroyImmediate(found.gameObject); }
public void FindOrSpawnObject_ErrorWhenSpawnHanlderReturnsWithoutNetworkIdentity() { const uint netId = 1003; SpawnMessage msg = new SpawnMessage { netId = netId, assetId = validPrefabGuid }; spawnHandlers.Add(validPrefabGuid, (x) => { GameObject go = new GameObject("testObj"); _createdObjects.Add(go); return(go); }); LogAssert.Expect(LogType.Error, $"Object Spawned by handler did not have a NetworkIdentity, Handler assetId '{validPrefabGuid}'"); LogAssert.Expect(LogType.Error, $"Could not spawn assetId={msg.assetId} scene={msg.sceneId} netId={msg.netId}"); bool success = ClientScene.FindOrSpawnObject(msg, out NetworkIdentity networkIdentity); Assert.IsFalse(success); Assert.IsNull(networkIdentity); }