fix: NetworkBehaviour.SyncVarNetworkIdentityEqual made protected again so that Weaver finds it again

This commit is contained in:
vis2k 2020-03-09 21:54:19 +01:00
parent 165a1dd94c
commit 20a2d09d07
2 changed files with 23 additions and 7 deletions

View File

@ -537,8 +537,10 @@ protected GameObject GetSyncVarGameObject(uint netId, ref GameObject gameObjectF
}
// helper function for [SyncVar] NetworkIdentities.
// IMPORTANT: keep as 'protected', not 'internal', otherwise Weaver
// can't resolve it
[EditorBrowsable(EditorBrowsableState.Never)]
internal bool SyncVarNetworkIdentityEqual(NetworkIdentity newIdentity, uint netIdField)
protected bool SyncVarNetworkIdentityEqual(NetworkIdentity newIdentity, uint netIdField)
{
uint newNetId = 0;
if (newIdentity != null)

View File

@ -21,6 +21,14 @@ public bool SyncVarGameObjectEqualExposed(GameObject newGameObject, uint netIdFi
}
}
class SyncVarNetworkIdentityEqualExposedBehaviour : NetworkBehaviour
{
public bool SyncVarNetworkIdentityEqualExposed(NetworkIdentity newNetworkIdentity, uint netIdField)
{
return SyncVarNetworkIdentityEqual(newNetworkIdentity, netIdField);
}
}
// we need to inherit from networkbehaviour to test protected functions
public class NetworkBehaviourSendCommandInternalComponent : NetworkBehaviour
{
@ -923,7 +931,8 @@ public void SyncVarNetworkIdentityEqualZeroNetIdNullIsTrue()
// better to return false here.
// => we possibly return false so that resync doesn't happen when
// GO disappears? or not?
bool result = emptyBehaviour.SyncVarNetworkIdentityEqual(null, identity.netId);
SyncVarNetworkIdentityEqualExposedBehaviour comp = gameObject.AddComponent<SyncVarNetworkIdentityEqualExposedBehaviour>();
bool result = comp.SyncVarNetworkIdentityEqualExposed(null, identity.netId);
Assert.That(result, Is.True);
}
@ -935,7 +944,8 @@ public void SyncVarNetworkIdentityEqualNull()
identity.netId = 42;
// null should return false
bool result = emptyBehaviour.SyncVarNetworkIdentityEqual(null, identity.netId);
SyncVarNetworkIdentityEqualExposedBehaviour comp = gameObject.AddComponent<SyncVarNetworkIdentityEqualExposedBehaviour>();
bool result = comp.SyncVarNetworkIdentityEqualExposed(null, identity.netId);
Assert.That(result, Is.False);
}
@ -949,8 +959,9 @@ public void SyncVarNetworkIdentityEqualValidIdentityWithDifferentNetId()
// gameobject with valid networkidentity and netid that is different
GameObject go = new GameObject();
NetworkIdentity ni = go.AddComponent<NetworkIdentity>();
SyncVarNetworkIdentityEqualExposedBehaviour comp = go.AddComponent<SyncVarNetworkIdentityEqualExposedBehaviour>();
ni.netId = 43;
bool result = emptyBehaviour.SyncVarNetworkIdentityEqual(ni, identity.netId);
bool result = comp.SyncVarNetworkIdentityEqualExposed(ni, identity.netId);
Assert.That(result, Is.False);
// clean up
@ -967,8 +978,9 @@ public void SyncVarNetworkIdentityEqualValidIdentityWithSameNetId()
// gameobject with valid networkidentity and netid that is different
GameObject go = new GameObject();
NetworkIdentity ni = go.AddComponent<NetworkIdentity>();
SyncVarNetworkIdentityEqualExposedBehaviour comp = go.AddComponent<SyncVarNetworkIdentityEqualExposedBehaviour>();
ni.netId = 42;
bool result = emptyBehaviour.SyncVarNetworkIdentityEqual(ni, identity.netId);
bool result = comp.SyncVarNetworkIdentityEqualExposed(ni, identity.netId);
Assert.That(result, Is.True);
// clean up
@ -985,8 +997,9 @@ public void SyncVarNetworkIdentityEqualUnspawnedIdentity()
// gameobject with valid networkidentity and 0 netid that is unspawned
GameObject go = new GameObject();
NetworkIdentity ni = go.AddComponent<NetworkIdentity>();
SyncVarNetworkIdentityEqualExposedBehaviour comp = go.AddComponent<SyncVarNetworkIdentityEqualExposedBehaviour>();
LogAssert.Expect(LogType.Warning, "SetSyncVarNetworkIdentity NetworkIdentity " + ni + " has a zero netId. Maybe it is not spawned yet?");
bool result = emptyBehaviour.SyncVarNetworkIdentityEqual(ni, identity.netId);
bool result = comp.SyncVarNetworkIdentityEqualExposed(ni, identity.netId);
Assert.That(result, Is.False);
// clean up
@ -1000,8 +1013,9 @@ public void SyncVarNetworkIdentityEqualUnspawnedIdentityZeroNetIdIsTrue()
// unspawned go and identity.netid==0 returns true (=equal)
GameObject go = new GameObject();
NetworkIdentity ni = go.AddComponent<NetworkIdentity>();
SyncVarNetworkIdentityEqualExposedBehaviour comp = go.AddComponent<SyncVarNetworkIdentityEqualExposedBehaviour>();
LogAssert.Expect(LogType.Warning, "SetSyncVarNetworkIdentity NetworkIdentity " + ni + " has a zero netId. Maybe it is not spawned yet?");
bool result = emptyBehaviour.SyncVarNetworkIdentityEqual(ni, identity.netId);
bool result = comp.SyncVarNetworkIdentityEqualExposed(ni, identity.netId);
Assert.That(result, Is.True);
// clean up