Tests: SyncVarCacheNetidForBehaviour: don't use generic magic

This commit is contained in:
vis2k 2021-05-20 13:18:30 +08:00
parent b2105be8f1
commit bbeb544d23

View File

@ -350,12 +350,35 @@ public void SyncVarCacheNetidForIdentity(bool initialState)
[TestCase(false)] [TestCase(false)]
public void SyncVarCacheNetidForBehaviour(bool initialState) public void SyncVarCacheNetidForBehaviour(bool initialState)
{ {
SyncVarCacheNetidForGeneric<SyncVarNetworkBehaviour, SyncVarNetworkBehaviour>( CreateNetworked(out GameObject _, out NetworkIdentity _, out SyncVarNetworkBehaviour serverObject);
(obj) => obj.value, CreateNetworked(out GameObject _, out NetworkIdentity _, out SyncVarNetworkBehaviour clientObject);
(obj, value) => obj.value = value,
(identity) => identity.gameObject.AddComponent<SyncVarNetworkBehaviour>(), NetworkIdentity identity = CreateNetworkIdentity(2047);
initialState SyncVarNetworkBehaviour serverValue = identity.gameObject.AddComponent<SyncVarNetworkBehaviour>();
);
Assert.That(serverValue, Is.Not.Null, "getCreatedValue should not return null");
serverObject.value = serverValue;
clientObject.value = null;
// write server data
bool written = ServerWrite(serverObject, initialState, out ArraySegment<byte> data, out int writeLength);
Assert.IsTrue(written, "did not write");
// remove identity from collection
NetworkIdentity.spawned.Remove(identity.netId);
// read client data, this should be cached in field
ClientRead(clientObject, initialState, data, writeLength);
// check field shows as null
Assert.That(clientObject.value, Is.EqualTo(null), "field should return null");
// add identity back to collection
NetworkIdentity.spawned.Add(identity.netId, identity);
// check field finds value
Assert.That(clientObject.value, Is.EqualTo(serverValue), "fields should return serverValue");
} }
void SyncVarCacheNetidForGeneric<TBehaviour, TValue>( void SyncVarCacheNetidForGeneric<TBehaviour, TValue>(