Remove ClientScene.RegisterPrefab with newAssetId

This commit is contained in:
vis2k 2020-09-29 09:33:56 +02:00
parent 8a190282aa
commit 9682a9a7e5
6 changed files with 0 additions and 497 deletions

View File

@ -263,47 +263,6 @@ static void RegisterPrefabIdentity(NetworkIdentity prefab)
prefabs[prefab.assetId] = prefab.gameObject; prefabs[prefab.assetId] = prefab.gameObject;
} }
/// <summary>
/// Registers a prefab with the spawning system.
/// <para>When a NetworkIdentity object is spawned on a server with NetworkServer.SpawnObject(), and the prefab that the object was created from was registered with RegisterPrefab(), the client will use that prefab to instantiate a corresponding client object with the same netId.</para>
/// <para>The NetworkManager has a list of spawnable prefabs, it uses this function to register those prefabs with the ClientScene.</para>
/// <para>The set of current spawnable object is available in the ClientScene static member variable ClientScene.prefabs, which is a dictionary of NetworkAssetIds and prefab references.</para>
/// <para>NOTE: newAssetId can not be set on GameObjects that already have an assetId</para>
/// </summary>
/// <param name="prefab">A GameObject that will be spawned.</param>
/// <param name="newAssetId">An assetId to be assigned to this GameObject. This allows a dynamically created game object to be registered for an already known asset Id.</param>
public static void RegisterPrefab(GameObject prefab, Guid newAssetId)
{
if (prefab == null)
{
Debug.LogError("Could not register prefab because it was null");
return;
}
if (newAssetId == Guid.Empty)
{
Debug.LogError($"Could not register '{prefab.name}' with new assetId because the new assetId was empty");
return;
}
NetworkIdentity identity = prefab.GetComponent<NetworkIdentity>();
if (identity == null)
{
Debug.LogError($"Could not register '{prefab.name}' since it contains no NetworkIdentity component");
return;
}
if (identity.assetId != Guid.Empty && identity.assetId != newAssetId)
{
Debug.LogError($"Could not register '{prefab.name}' to {newAssetId} because it already had an AssetId, Existing assetId {identity.assetId}");
return;
}
identity.assetId = newAssetId;
RegisterPrefabIdentity(identity);
}
/// <summary> /// <summary>
/// Registers a prefab with the spawning system. /// Registers a prefab with the spawning system.
/// <para>When a NetworkIdentity object is spawned on a server with NetworkServer.SpawnObject(), and the prefab that the object was created from was registered with RegisterPrefab(), the client will use that prefab to instantiate a corresponding client object with the same netId.</para> /// <para>When a NetworkIdentity object is spawned on a server with NetworkServer.SpawnObject(), and the prefab that the object was created from was registered with RegisterPrefab(), the client will use that prefab to instantiate a corresponding client object with the same netId.</para>

View File

@ -12,20 +12,6 @@ public abstract class ClientSceneTests_RegisterPrefabBase : ClientSceneTestsBase
{ {
[Test] [Test]
[TestCase(RegisterPrefabOverload.Prefab, false)] [TestCase(RegisterPrefabOverload.Prefab, false)]
[TestCase(RegisterPrefabOverload.Prefab_NewAssetId, true)]
[TestCase(RegisterPrefabOverload.Prefab_SpawnDelegate, false)]
[TestCase(RegisterPrefabOverload.Prefab_SpawnDelegate_NewAssetId, true)]
[TestCase(RegisterPrefabOverload.Prefab_SpawnHandlerDelegate, false)]
[TestCase(RegisterPrefabOverload.Prefab_SpawnHandlerDelegate_NewAssetId, true)]
public void CheckOverloadWithAssetId(RegisterPrefabOverload overload, bool expected)
{
// test to make sure OverloadWithAssetId correctly works with flags
Assert.That(OverloadWithAssetId(overload), Is.EqualTo(expected));
}
[Test]
[TestCase(RegisterPrefabOverload.Prefab, false)]
[TestCase(RegisterPrefabOverload.Prefab_NewAssetId, false)]
[TestCase(RegisterPrefabOverload.Prefab_SpawnDelegate, true)] [TestCase(RegisterPrefabOverload.Prefab_SpawnDelegate, true)]
[TestCase(RegisterPrefabOverload.Prefab_SpawnDelegate_NewAssetId, true)] [TestCase(RegisterPrefabOverload.Prefab_SpawnDelegate_NewAssetId, true)]
[TestCase(RegisterPrefabOverload.Prefab_SpawnHandlerDelegate, true)] [TestCase(RegisterPrefabOverload.Prefab_SpawnHandlerDelegate, true)]
@ -44,21 +30,14 @@ public void CheckOverloadWithHandler(RegisterPrefabOverload overload, bool expec
public enum RegisterPrefabOverload public enum RegisterPrefabOverload
{ {
Prefab = 1, Prefab = 1,
Prefab_NewAssetId = 2,
Prefab_SpawnDelegate = 4, Prefab_SpawnDelegate = 4,
Prefab_SpawnDelegate_NewAssetId = 8, Prefab_SpawnDelegate_NewAssetId = 8,
Prefab_SpawnHandlerDelegate = 16, Prefab_SpawnHandlerDelegate = 16,
Prefab_SpawnHandlerDelegate_NewAssetId = 32, Prefab_SpawnHandlerDelegate_NewAssetId = 32,
WithAssetId = Prefab_NewAssetId | Prefab_SpawnDelegate_NewAssetId | Prefab_SpawnHandlerDelegate_NewAssetId,
WithHandler = Prefab_SpawnDelegate | Prefab_SpawnDelegate_NewAssetId | Prefab_SpawnHandlerDelegate | Prefab_SpawnHandlerDelegate_NewAssetId WithHandler = Prefab_SpawnDelegate | Prefab_SpawnDelegate_NewAssetId | Prefab_SpawnHandlerDelegate | Prefab_SpawnHandlerDelegate_NewAssetId
} }
protected static bool OverloadWithAssetId(RegisterPrefabOverload overload)
{
return (overload & RegisterPrefabOverload.WithAssetId) != 0;
}
protected static bool OverloadWithHandler(RegisterPrefabOverload overload) protected static bool OverloadWithHandler(RegisterPrefabOverload overload)
{ {
return (overload & RegisterPrefabOverload.WithHandler) != 0; return (overload & RegisterPrefabOverload.WithHandler) != 0;
@ -75,9 +54,6 @@ protected void CallRegisterPrefab(GameObject prefab, RegisterPrefabOverload over
case RegisterPrefabOverload.Prefab: case RegisterPrefabOverload.Prefab:
ClientScene.RegisterPrefab(prefab); ClientScene.RegisterPrefab(prefab);
break; break;
case RegisterPrefabOverload.Prefab_NewAssetId:
ClientScene.RegisterPrefab(prefab, anotherGuid);
break;
case RegisterPrefabOverload.Prefab_SpawnDelegate: case RegisterPrefabOverload.Prefab_SpawnDelegate:
ClientScene.RegisterPrefab(prefab, spawnHandler, unspawnHandler); ClientScene.RegisterPrefab(prefab, spawnHandler, unspawnHandler);
break; break;
@ -105,9 +81,6 @@ protected void CallRegisterPrefab(GameObject prefab, RegisterPrefabOverload over
switch (overload) switch (overload)
{ {
case RegisterPrefabOverload.Prefab_NewAssetId:
ClientScene.RegisterPrefab(prefab, guid);
break;
case RegisterPrefabOverload.Prefab_SpawnDelegate_NewAssetId: case RegisterPrefabOverload.Prefab_SpawnDelegate_NewAssetId:
ClientScene.RegisterPrefab(prefab, guid, spawnHandler, unspawnHandler); ClientScene.RegisterPrefab(prefab, guid, spawnHandler, unspawnHandler);
break; break;
@ -140,7 +113,6 @@ protected void CallRegisterPrefab(GameObject prefab, RegisterPrefabOverload over
break; break;
case RegisterPrefabOverload.Prefab: case RegisterPrefabOverload.Prefab:
case RegisterPrefabOverload.Prefab_NewAssetId:
case RegisterPrefabOverload.Prefab_SpawnHandlerDelegate: case RegisterPrefabOverload.Prefab_SpawnHandlerDelegate:
case RegisterPrefabOverload.Prefab_SpawnHandlerDelegate_NewAssetId: case RegisterPrefabOverload.Prefab_SpawnHandlerDelegate_NewAssetId:
Debug.LogError("Overload did not have SpawnDelegate parameter"); Debug.LogError("Overload did not have SpawnDelegate parameter");
@ -165,7 +137,6 @@ protected void CallRegisterPrefab(GameObject prefab, RegisterPrefabOverload over
break; break;
case RegisterPrefabOverload.Prefab: case RegisterPrefabOverload.Prefab:
case RegisterPrefabOverload.Prefab_NewAssetId:
case RegisterPrefabOverload.Prefab_SpawnDelegate: case RegisterPrefabOverload.Prefab_SpawnDelegate:
case RegisterPrefabOverload.Prefab_SpawnDelegate_NewAssetId: case RegisterPrefabOverload.Prefab_SpawnDelegate_NewAssetId:
Debug.LogError("Overload did not have SpawnHandlerDelegate parameter"); Debug.LogError("Overload did not have SpawnHandlerDelegate parameter");
@ -198,15 +169,10 @@ protected void CallRegisterPrefab(GameObject prefab, RegisterPrefabOverload over
break; break;
case RegisterPrefabOverload.Prefab: case RegisterPrefabOverload.Prefab:
case RegisterPrefabOverload.Prefab_NewAssetId:
Debug.LogError("Overload did not have UnSpawnDelegate parameter");
break;
default: default:
Debug.LogError("Overload not found"); Debug.LogError("Overload not found");
break; break;
} }
} }
protected Guid GuidForOverload(RegisterPrefabOverload overload) => OverloadWithAssetId(overload) ? anotherGuid : validPrefabGuid;
} }
} }

View File

@ -1,301 +0,0 @@
using System;
using NUnit.Framework;
using UnityEngine;
using UnityEngine.TestTools;
namespace Mirror.Tests.ClientSceneTests
{
public class ClientSceneTests_RegisterPrefab : ClientSceneTests_RegisterPrefabBase
{
[Test]
[TestCase(RegisterPrefabOverload.Prefab)]
public void Prefab_AddsPrefabToDictionary(RegisterPrefabOverload overload)
{
Guid guid = GuidForOverload(overload);
CallRegisterPrefab(validPrefab, overload);
Assert.IsTrue(prefabs.ContainsKey(guid));
Assert.AreEqual(prefabs[guid], validPrefab);
}
[Test]
[TestCase(RegisterPrefabOverload.Prefab_NewAssetId)]
public void PrefabNewGuid_ErrorDoesNotChangePrefabsAssetId(RegisterPrefabOverload overload)
{
Guid guid = anotherGuid;
LogAssert.Expect(LogType.Error, $"Could not register '{validPrefab.name}' to {guid} because it already had an AssetId, Existing assetId {validPrefabGuid}");
CallRegisterPrefab(validPrefab, overload);
Assert.IsFalse(prefabs.ContainsKey(guid));
NetworkIdentity netId = validPrefab.GetComponent<NetworkIdentity>();
Assert.AreEqual(netId.assetId, validPrefabGuid);
}
[Test]
[TestCase(RegisterPrefabOverload.Prefab_SpawnDelegate_NewAssetId)]
[TestCase(RegisterPrefabOverload.Prefab_SpawnHandlerDelegate_NewAssetId)]
public void HandlerNewGuid_ErrorDoesNotChangePrefabsAssetId(RegisterPrefabOverload overload)
{
Guid guid = anotherGuid;
LogAssert.Expect(LogType.Error, $"Could not register Handler for '{validPrefab.name}' to {guid} because it already had an AssetId, Existing assetId {validPrefabGuid}");
CallRegisterPrefab(validPrefab, overload);
Assert.IsFalse(spawnHandlers.ContainsKey(guid));
Assert.IsFalse(unspawnHandlers.ContainsKey(guid));
NetworkIdentity netId = validPrefab.GetComponent<NetworkIdentity>();
Assert.AreEqual(netId.assetId, validPrefabGuid);
}
[Test]
[TestCase(RegisterPrefabOverload.Prefab_NewAssetId)]
public void PrefabNewGuid_NoErrorWhenNewAssetIdIsSameAsCurrentPrefab(RegisterPrefabOverload overload)
{
Guid guid = validPrefabGuid;
CallRegisterPrefab(validPrefab, overload, guid);
Assert.IsTrue(prefabs.ContainsKey(guid));
NetworkIdentity netId = validPrefab.GetComponent<NetworkIdentity>();
Assert.AreEqual(netId.assetId, validPrefabGuid);
}
[Test]
[TestCase(RegisterPrefabOverload.Prefab_SpawnDelegate_NewAssetId)]
[TestCase(RegisterPrefabOverload.Prefab_SpawnHandlerDelegate_NewAssetId)]
public void HandlerNewGuid_NoErrorWhenAssetIdIsSameAsCurrentPrefab(RegisterPrefabOverload overload)
{
Guid guid = validPrefabGuid;
CallRegisterPrefab(validPrefab, overload, guid);
Assert.IsTrue(spawnHandlers.ContainsKey(guid));
Assert.IsTrue(unspawnHandlers.ContainsKey(guid));
NetworkIdentity netId = validPrefab.GetComponent<NetworkIdentity>();
Assert.AreEqual(netId.assetId, validPrefabGuid);
}
[Test]
[TestCase(RegisterPrefabOverload.Prefab)]
[TestCase(RegisterPrefabOverload.Prefab_NewAssetId)]
[TestCase(RegisterPrefabOverload.Prefab_SpawnDelegate)]
[TestCase(RegisterPrefabOverload.Prefab_SpawnDelegate_NewAssetId)]
[TestCase(RegisterPrefabOverload.Prefab_SpawnHandlerDelegate)]
[TestCase(RegisterPrefabOverload.Prefab_SpawnHandlerDelegate_NewAssetId)]
public void ErrorForNullPrefab(RegisterPrefabOverload overload)
{
string msg = OverloadWithHandler(overload)
? "Could not register handler for prefab because the prefab was null"
: "Could not register prefab because it was null";
LogAssert.Expect(LogType.Error, msg);
CallRegisterPrefab(null, overload);
}
[Test]
[TestCase(RegisterPrefabOverload.Prefab)]
[TestCase(RegisterPrefabOverload.Prefab_NewAssetId)]
[TestCase(RegisterPrefabOverload.Prefab_SpawnDelegate)]
[TestCase(RegisterPrefabOverload.Prefab_SpawnDelegate_NewAssetId)]
[TestCase(RegisterPrefabOverload.Prefab_SpawnHandlerDelegate)]
[TestCase(RegisterPrefabOverload.Prefab_SpawnHandlerDelegate_NewAssetId)]
public void ErrorForPrefabWithoutNetworkIdentity(RegisterPrefabOverload overload)
{
string msg = OverloadWithHandler(overload)
? $"Could not register handler for '{invalidPrefab.name}' since it contains no NetworkIdentity component"
: $"Could not register '{invalidPrefab.name}' since it contains no NetworkIdentity component";
LogAssert.Expect(LogType.Error, msg);
CallRegisterPrefab(invalidPrefab, overload);
}
[Test]
[TestCase(RegisterPrefabOverload.Prefab_NewAssetId)]
[TestCase(RegisterPrefabOverload.Prefab_SpawnDelegate_NewAssetId)]
[TestCase(RegisterPrefabOverload.Prefab_SpawnHandlerDelegate_NewAssetId)]
public void NewGuid_ErrorForEmptyGuid(RegisterPrefabOverload overload)
{
string msg = OverloadWithHandler(overload)
? $"Could not register handler for '{validPrefab.name}' with new assetId because the new assetId was empty"
: $"Could not register '{validPrefab.name}' with new assetId because the new assetId was empty";
LogAssert.Expect(LogType.Error, msg);
CallRegisterPrefab(validPrefab, overload, guid: new Guid());
}
[Test]
[TestCase(RegisterPrefabOverload.Prefab)]
[TestCase(RegisterPrefabOverload.Prefab_SpawnDelegate)]
[TestCase(RegisterPrefabOverload.Prefab_SpawnHandlerDelegate)]
public void ErrorIfPrefabHadSceneId(RegisterPrefabOverload overload)
{
GameObject clone = GameObject.Instantiate(validPrefab);
NetworkIdentity netId = clone.GetComponent<NetworkIdentity>();
// Scene Id needs to not be zero for this test
netId.sceneId = 20;
LogAssert.Expect(LogType.Error, $"Can not Register '{clone.name}' because it has a sceneId, make sure you are passing in the original prefab and not an instance in the scene.");
CallRegisterPrefab(clone, overload);
GameObject.DestroyImmediate(clone);
}
[Test]
[TestCase(RegisterPrefabOverload.Prefab)]
[TestCase(RegisterPrefabOverload.Prefab_SpawnDelegate)]
[TestCase(RegisterPrefabOverload.Prefab_SpawnHandlerDelegate)]
public void WarningForNetworkIdentityInChildren(RegisterPrefabOverload overload)
{
LogAssert.Expect(LogType.Warning, $"Prefab '{prefabWithChildren.name}' has multiple NetworkIdentity components. There should only be one NetworkIdentity on a prefab, and it must be on the root object.");
CallRegisterPrefab(prefabWithChildren, overload);
}
[Test]
[TestCase(RegisterPrefabOverload.Prefab)]
public void Prefab_WarningForAssetIdAlreadyExistingInPrefabsDictionary(RegisterPrefabOverload overload)
{
Guid guid = GuidForOverload(overload);
prefabs.Add(guid, validPrefab);
LogAssert.Expect(LogType.Warning, $"Replacing existing prefab with assetId '{guid}'. Old prefab '{validPrefab.name}', New prefab '{validPrefab.name}'");
CallRegisterPrefab(validPrefab, overload);
}
[Test]
[TestCase(RegisterPrefabOverload.Prefab_SpawnDelegate)]
[TestCase(RegisterPrefabOverload.Prefab_SpawnHandlerDelegate)]
public void Handler_ErrorForAssetIdAlreadyExistingInPrefabsDictionary(RegisterPrefabOverload overload)
{
Guid guid = GuidForOverload(overload);
prefabs.Add(guid, validPrefab);
LogAssert.Expect(LogType.Error, $"assetId '{guid}' is already used by prefab '{validPrefab.name}', unregister the prefab first before trying to add handler");
CallRegisterPrefab(validPrefab, overload);
}
[Test]
[TestCase(RegisterPrefabOverload.Prefab)]
[TestCase(RegisterPrefabOverload.Prefab_SpawnDelegate)]
[TestCase(RegisterPrefabOverload.Prefab_SpawnHandlerDelegate)]
public void WarningForAssetIdAlreadyExistingInHandlersDictionary(RegisterPrefabOverload overload)
{
Guid guid = GuidForOverload(overload);
spawnHandlers.Add(guid, x => null);
unspawnHandlers.Add(guid, x => { });
string msg = OverloadWithHandler(overload)
? $"Replacing existing spawnHandlers for prefab '{validPrefab.name}' with assetId '{guid}'"
: $"Adding prefab '{validPrefab.name}' with assetId '{guid}' when spawnHandlers with same assetId already exists.";
LogAssert.Expect(LogType.Warning, msg);
CallRegisterPrefab(validPrefab, overload);
}
[Test]
[TestCase(RegisterPrefabOverload.Prefab_SpawnDelegate)]
public void SpawnDelegate_AddsHandlerToSpawnHandlers(RegisterPrefabOverload overload)
{
int handlerCalled = 0;
Guid guid = GuidForOverload(overload);
SpawnDelegate handler = new SpawnDelegate((pos, rot) =>
{
handlerCalled++;
return null;
});
CallRegisterPrefab(validPrefab, overload, spawnHandler: handler);
Assert.IsTrue(spawnHandlers.ContainsKey(guid));
// check spawnHandler above is called
SpawnHandlerDelegate handlerInDictionary = spawnHandlers[guid];
handlerInDictionary.Invoke(default);
Assert.That(handlerCalled, Is.EqualTo(1));
}
[Test]
[TestCase(RegisterPrefabOverload.Prefab_SpawnDelegate)]
public void SpawnDelegate_AddsHandlerToSpawnHandlersWithCorrectArguments(RegisterPrefabOverload overload)
{
int handlerCalled = 0;
Vector3 somePosition = new Vector3(10, 20, 3);
Guid guid = GuidForOverload(overload);
SpawnDelegate handler = new SpawnDelegate((pos, assetId) =>
{
handlerCalled++;
Assert.That(pos, Is.EqualTo(somePosition));
Assert.That(assetId, Is.EqualTo(guid));
return null;
});
CallRegisterPrefab(validPrefab, overload, spawnHandler: handler);
Assert.IsTrue(spawnHandlers.ContainsKey(guid));
// check spawnHandler above is called
SpawnHandlerDelegate handlerInDictionary = spawnHandlers[guid];
handlerInDictionary.Invoke(new SpawnMessage { position = somePosition, assetId = guid });
Assert.That(handlerCalled, Is.EqualTo(1));
}
[Test]
[TestCase(RegisterPrefabOverload.Prefab_SpawnDelegate)]
[TestCase(RegisterPrefabOverload.Prefab_SpawnDelegate_NewAssetId)]
public void SpawnDelegate_ErrorWhenSpawnHandlerIsNull(RegisterPrefabOverload overload)
{
Guid guid = GuidForOverload(overload);
LogAssert.Expect(LogType.Error, $"Can not Register null SpawnHandler for {guid}");
CallRegisterPrefab(validPrefab, overload, spawnHandler: null);
}
[Test]
[TestCase(RegisterPrefabOverload.Prefab_SpawnHandlerDelegate)]
public void SpawnHandleDelegate_AddsHandlerToSpawnHandlers(RegisterPrefabOverload overload)
{
Guid guid = GuidForOverload(overload);
SpawnHandlerDelegate handler = new SpawnHandlerDelegate(x => null);
CallRegisterPrefab(validPrefab, overload, spawnHandlerDelegate: handler);
Assert.IsTrue(spawnHandlers.ContainsKey(guid));
Assert.AreEqual(spawnHandlers[guid], handler);
}
[Test]
[TestCase(RegisterPrefabOverload.Prefab_SpawnHandlerDelegate)]
public void SpawnHandleDelegate_ErrorWhenSpawnHandlerIsNull(RegisterPrefabOverload overload)
{
Guid guid = GuidForOverload(overload);
LogAssert.Expect(LogType.Error, $"Can not Register null SpawnHandler for {guid}");
CallRegisterPrefab(validPrefab, overload, spawnHandlerDelegate: null);
}
[Test]
[TestCase(RegisterPrefabOverload.Prefab_SpawnDelegate)]
[TestCase(RegisterPrefabOverload.Prefab_SpawnHandlerDelegate)]
public void Handler_ErrorWhenUnSpawnHandlerIsNull(RegisterPrefabOverload overload)
{
Guid guid = GuidForOverload(overload);
LogAssert.Expect(LogType.Error, $"Can not Register null UnSpawnHandler for {guid}");
CallRegisterPrefab(validPrefab, overload, unspawnHandler: null);
}
}
}

View File

@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: bdfdcfafb85b3be418f2085e38663006
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -1,99 +0,0 @@
using NUnit.Framework;
using UnityEngine;
using UnityEngine.TestTools;
namespace Mirror.Tests.Runtime.ClientSceneTests
{
public class ClientSceneTests_Runtime_RegisterPrefab : ClientSceneTests_RegisterPrefabBase
{
/// <summary>
/// Create scene objects, must be done at runtime so that sceneId isnt set when assetId.get is called
/// </summary>
/// <param name="runtimeObject"></param>
/// <param name="networkIdentity"></param>
protected static void CreateSceneObject(out GameObject runtimeObject, out NetworkIdentity networkIdentity)
{
runtimeObject = new GameObject("Runtime GameObject");
networkIdentity = runtimeObject.AddComponent<NetworkIdentity>();
// set sceneId to zero as it is set in onvalidate (does not set id at runtime)
networkIdentity.sceneId = 0;
}
[Test]
[TestCase(RegisterPrefabOverload.Prefab_SpawnDelegate_NewAssetId)]
[TestCase(RegisterPrefabOverload.Prefab_SpawnHandlerDelegate_NewAssetId)]
public void Handler_AddsSpawnHandlerToDictionaryForRuntimeObject(RegisterPrefabOverload overload)
{
// setup
CreateSceneObject(out GameObject runtimeObject, out NetworkIdentity networkIdentity);
Debug.Assert(networkIdentity.sceneId == 0, "SceneId was not set to 0");
Debug.Assert(runtimeObject.GetComponent<NetworkIdentity>().sceneId == 0, "SceneId was not set to 0");
//test
CallRegisterPrefab(runtimeObject, overload);
Assert.IsTrue(spawnHandlers.ContainsKey(anotherGuid));
// teardown
GameObject.DestroyImmediate(runtimeObject);
}
[Test]
[TestCase(RegisterPrefabOverload.Prefab)]
[TestCase(RegisterPrefabOverload.Prefab_SpawnDelegate)]
[TestCase(RegisterPrefabOverload.Prefab_SpawnHandlerDelegate)]
public void ErrorForEmptyGuid(RegisterPrefabOverload overload)
{
// setup
CreateSceneObject(out GameObject runtimeObject, out NetworkIdentity networkIdentity);
//test
string msg = OverloadWithHandler(overload)
? $"Can not Register handler for '{runtimeObject.name}' because it had empty assetid. If this is a scene Object use RegisterSpawnHandler instead"
: $"Can not Register '{runtimeObject.name}' because it had empty assetid. If this is a scene Object use RegisterSpawnHandler instead";
LogAssert.Expect(LogType.Error, msg);
CallRegisterPrefab(runtimeObject, overload);
// teardown
GameObject.DestroyImmediate(runtimeObject);
}
[Test]
[TestCase(RegisterPrefabOverload.Prefab_NewAssetId)]
public void PrefabNewGuid_AddsRuntimeObjectToDictionary(RegisterPrefabOverload overload)
{
// setup
CreateSceneObject(out GameObject runtimeObject, out NetworkIdentity networkIdentity);
//test
CallRegisterPrefab(runtimeObject, overload);
Assert.IsTrue(prefabs.ContainsKey(anotherGuid));
Assert.AreEqual(prefabs[anotherGuid], runtimeObject);
Assert.AreEqual(networkIdentity.assetId, anotherGuid);
// teardown
GameObject.DestroyImmediate(runtimeObject);
}
[Test]
[TestCase(RegisterPrefabOverload.Prefab_SpawnDelegate_NewAssetId)]
[TestCase(RegisterPrefabOverload.Prefab_SpawnHandlerDelegate_NewAssetId)]
public void Handler_AddsUnSpawnHandlerToDictionaryForRuntimeObject(RegisterPrefabOverload overload)
{
// setup
CreateSceneObject(out GameObject runtimeObject, out NetworkIdentity networkIdentity);
//test
CallRegisterPrefab(runtimeObject, overload);
Assert.IsTrue(unspawnHandlers.ContainsKey(anotherGuid));
// teardown
GameObject.DestroyImmediate(runtimeObject);
}
}
}

View File

@ -1,11 +0,0 @@
fileFormatVersion: 2
guid: c47e4b8fb9faba04792f9e4764a9c929
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: