From 20a2d09d07ab2c47a204e5d583b538a92f72231e Mon Sep 17 00:00:00 2001 From: vis2k Date: Mon, 9 Mar 2020 21:54:19 +0100 Subject: [PATCH] fix: NetworkBehaviour.SyncVarNetworkIdentityEqual made protected again so that Weaver finds it again --- Assets/Mirror/Runtime/NetworkBehaviour.cs | 4 ++- .../Tests/Editor/NetworkBehaviourTests.cs | 26 ++++++++++++++----- 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/Assets/Mirror/Runtime/NetworkBehaviour.cs b/Assets/Mirror/Runtime/NetworkBehaviour.cs index 623daec95..dc37f42fe 100644 --- a/Assets/Mirror/Runtime/NetworkBehaviour.cs +++ b/Assets/Mirror/Runtime/NetworkBehaviour.cs @@ -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) diff --git a/Assets/Mirror/Tests/Editor/NetworkBehaviourTests.cs b/Assets/Mirror/Tests/Editor/NetworkBehaviourTests.cs index 65c52dec4..5f3fd5a02 100644 --- a/Assets/Mirror/Tests/Editor/NetworkBehaviourTests.cs +++ b/Assets/Mirror/Tests/Editor/NetworkBehaviourTests.cs @@ -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(); + 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(); + 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(); + SyncVarNetworkIdentityEqualExposedBehaviour comp = go.AddComponent(); 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(); + SyncVarNetworkIdentityEqualExposedBehaviour comp = go.AddComponent(); 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(); + SyncVarNetworkIdentityEqualExposedBehaviour comp = go.AddComponent(); 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(); + SyncVarNetworkIdentityEqualExposedBehaviour comp = go.AddComponent(); 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