diff --git a/Assets/Mirror/Runtime/NetworkBehaviour.cs b/Assets/Mirror/Runtime/NetworkBehaviour.cs index 3fd42141b..623daec95 100644 --- a/Assets/Mirror/Runtime/NetworkBehaviour.cs +++ b/Assets/Mirror/Runtime/NetworkBehaviour.cs @@ -469,8 +469,10 @@ public static CmdDelegate GetDelegate(int cmdHash) #region Helpers // helper function for [SyncVar] GameObjects. + // IMPORTANT: keep as 'protected', not 'internal', otherwise Weaver + // can't resolve it [EditorBrowsable(EditorBrowsableState.Never)] - internal bool SyncVarGameObjectEqual(GameObject newGameObject, uint netIdField) + protected bool SyncVarGameObjectEqual(GameObject newGameObject, uint netIdField) { uint newNetId = 0; if (newGameObject != null) diff --git a/Assets/Mirror/Tests/Editor/NetworkBehaviourTests.cs b/Assets/Mirror/Tests/Editor/NetworkBehaviourTests.cs index d2b3a9df5..65c52dec4 100644 --- a/Assets/Mirror/Tests/Editor/NetworkBehaviourTests.cs +++ b/Assets/Mirror/Tests/Editor/NetworkBehaviourTests.cs @@ -13,6 +13,14 @@ class EmptyBehaviour : NetworkBehaviour { } + class SyncVarGameObjectEqualExposedBehaviour : NetworkBehaviour + { + public bool SyncVarGameObjectEqualExposed(GameObject newGameObject, uint netIdField) + { + return SyncVarGameObjectEqual(newGameObject, netIdField); + } + } + // we need to inherit from networkbehaviour to test protected functions public class NetworkBehaviourSendCommandInternalComponent : NetworkBehaviour { @@ -781,7 +789,8 @@ public void SyncVarGameObjectEqualZeroNetIdNullIsTrue() // better to return false here. // => we possibly return false so that resync doesn't happen when // GO disappears? or not? - bool result = emptyBehaviour.SyncVarGameObjectEqual(null, identity.netId); + SyncVarGameObjectEqualExposedBehaviour comp = gameObject.AddComponent(); + bool result = comp.SyncVarGameObjectEqualExposed(null, identity.netId); Assert.That(result, Is.True); } @@ -793,7 +802,8 @@ public void SyncVarGameObjectEqualNull() identity.netId = 42; // null should return false - bool result = emptyBehaviour.SyncVarGameObjectEqual(null, identity.netId); + SyncVarGameObjectEqualExposedBehaviour comp = gameObject.AddComponent(); + bool result = comp.SyncVarGameObjectEqualExposed(null, identity.netId); Assert.That(result, Is.False); } @@ -808,7 +818,8 @@ public void SyncVarGameObjectEqualZeroNetIdAndGOWithoutIdentityComponentIsTrue() // => we possibly return false so that resync doesn't happen when // GO disappears? or not? GameObject go = new GameObject(); - bool result = emptyBehaviour.SyncVarGameObjectEqual(go, identity.netId); + SyncVarGameObjectEqualExposedBehaviour comp = go.AddComponent(); + bool result = comp.SyncVarGameObjectEqualExposed(go, identity.netId); Assert.That(result, Is.True); } @@ -821,7 +832,8 @@ public void SyncVarGameObjectEqualWithoutIdentityComponent() // gameobject without networkidentity component should return false GameObject go = new GameObject(); - bool result = emptyBehaviour.SyncVarGameObjectEqual(go, identity.netId); + SyncVarGameObjectEqualExposedBehaviour comp = go.AddComponent(); + bool result = comp.SyncVarGameObjectEqualExposed(go, identity.netId); Assert.That(result, Is.False); // clean up @@ -838,8 +850,9 @@ public void SyncVarGameObjectEqualValidGOWithDifferentNetId() // gameobject with valid networkidentity and netid that is different GameObject go = new GameObject(); NetworkIdentity ni = go.AddComponent(); + SyncVarGameObjectEqualExposedBehaviour comp = go.AddComponent(); ni.netId = 43; - bool result = emptyBehaviour.SyncVarGameObjectEqual(go, identity.netId); + bool result = comp.SyncVarGameObjectEqualExposed(go, identity.netId); Assert.That(result, Is.False); // clean up @@ -856,8 +869,9 @@ public void SyncVarGameObjectEqualValidGOWithSameNetId() // gameobject with valid networkidentity and netid that is different GameObject go = new GameObject(); NetworkIdentity ni = go.AddComponent(); + SyncVarGameObjectEqualExposedBehaviour comp = go.AddComponent(); ni.netId = 42; - bool result = emptyBehaviour.SyncVarGameObjectEqual(go, identity.netId); + bool result = comp.SyncVarGameObjectEqualExposed(go, identity.netId); Assert.That(result, Is.True); // clean up @@ -874,8 +888,9 @@ public void SyncVarGameObjectEqualUnspawnedGO() // gameobject with valid networkidentity and 0 netid that is unspawned GameObject go = new GameObject(); go.AddComponent(); + SyncVarGameObjectEqualExposedBehaviour comp = go.AddComponent(); LogAssert.Expect(LogType.Warning, "SetSyncVarGameObject GameObject " + go + " has a zero netId. Maybe it is not spawned yet?"); - bool result = emptyBehaviour.SyncVarGameObjectEqual(go, identity.netId); + bool result = comp.SyncVarGameObjectEqualExposed(go, identity.netId); Assert.That(result, Is.False); // clean up @@ -889,8 +904,9 @@ public void SyncVarGameObjectEqualUnspawnedGOZeroNetIdIsTrue() // unspawned go and identity.netid==0 returns true (=equal) GameObject go = new GameObject(); go.AddComponent(); + SyncVarGameObjectEqualExposedBehaviour comp = go.AddComponent(); LogAssert.Expect(LogType.Warning, "SetSyncVarGameObject GameObject " + go + " has a zero netId. Maybe it is not spawned yet?"); - bool result = emptyBehaviour.SyncVarGameObjectEqual(go, identity.netId); + bool result = comp.SyncVarGameObjectEqualExposed(go, identity.netId); Assert.That(result, Is.True); // clean up