Skip to content

Commit d9c9211

Browse files
committed
Use InternalHasAuthority instead of public field
1 parent 02600b9 commit d9c9211

5 files changed

Lines changed: 21 additions & 27 deletions

File tree

com.unity.netcode.gameobjects/Runtime/Core/NetworkBehaviour.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -670,7 +670,7 @@ internal void UpdateNetworkProperties()
670670
IsClient = m_NetworkManager.IsListening && m_NetworkManager.IsClient;
671671
IsServer = m_NetworkManager.IsListening && m_NetworkManager.IsServer;
672672
IsSessionOwner = m_NetworkManager.IsListening && m_NetworkManager.LocalClient.IsSessionOwner;
673-
HasAuthority = m_NetworkObject.HasAuthority;
673+
HasAuthority = m_NetworkObject.InternalHasAuthority();
674674
ServerIsHost = m_NetworkManager.IsListening && m_NetworkManager.ServerIsHost;
675675
}
676676
}

com.unity.netcode.gameobjects/Runtime/Core/NetworkObject.cs

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,6 @@ public void DeferDespawn(int tickOffset, bool destroy = true)
402402
{
403403
NetworkLog.LogErrorServer($"[{name}] This method is only available in distributed authority mode.");
404404
}
405-
406405
return;
407406
}
408407

@@ -412,11 +411,10 @@ public void DeferDespawn(int tickOffset, bool destroy = true)
412411
{
413412
NetworkLog.LogErrorServer($"[{name}] Cannot defer despawn while not spawned.");
414413
}
415-
416414
return;
417415
}
418416

419-
if (!HasAuthority)
417+
if (!InternalHasAuthority())
420418
{
421419
if (NetworkManagerOwner.LogLevel <= LogLevel.Error)
422420
{
@@ -628,12 +626,11 @@ public bool SetOwnershipLock(bool lockOwnership = true)
628626
{
629627
NetworkLog.LogErrorServer($"[{name}][Attempted Lock While not spawned]");
630628
}
631-
632629
return false;
633630
}
634631

635632
// If we don't have authority exit early
636-
if (!HasAuthority)
633+
if (!InternalHasAuthority())
637634
{
638635
if (NetworkManager.LogLevel <= LogLevel.Error)
639636
{
@@ -671,7 +668,6 @@ public bool SetOwnershipLock(bool lockOwnership = true)
671668
{
672669
SendOwnershipStatusUpdate();
673670
}
674-
675671
return true;
676672
}
677673

@@ -797,7 +793,6 @@ public OwnershipRequestStatus RequestOwnership()
797793
{
798794
NetworkLog.LogErrorServer($"[{name}][Invalid Operation] Cannot request ownership of an NetworkObject before it is spawned.");
799795
}
800-
801796
return OwnershipRequestStatus.InvalidOperation;
802797
}
803798
// Exit early the local client is already the owner
@@ -909,7 +904,7 @@ internal void OwnershipRequest(ulong clientRequestingOwnership)
909904

910905
// This action is always authorized as long as the client still has authority.
911906
// We need to pass in that this is a request approval ownership change.
912-
NetworkManagerOwner.SpawnManager.ChangeOwnership(this, clientRequestingOwnership, HasAuthority, true);
907+
NetworkManagerOwner.SpawnManager.ChangeOwnership(this, clientRequestingOwnership, InternalHasAuthority(), true);
913908
}
914909
else
915910
{
@@ -1158,7 +1153,7 @@ public bool HasOwnershipStatus(OwnershipStatus status)
11581153
public bool HasAuthority => InternalHasAuthority();
11591154

11601155
[MethodImpl(MethodImplOptions.AggressiveInlining)]
1161-
private bool InternalHasAuthority()
1156+
internal bool InternalHasAuthority()
11621157
{
11631158
if (!IsSpawned)
11641159
{
@@ -1509,7 +1504,7 @@ public void NetworkShow(ulong clientId)
15091504
return;
15101505
}
15111506

1512-
if (!HasAuthority)
1507+
if (!InternalHasAuthority())
15131508
{
15141509
if (NetworkManagerOwner.DistributedAuthorityMode)
15151510
{
@@ -1604,7 +1599,7 @@ public void NetworkHide(ulong clientId)
16041599
return;
16051600
}
16061601

1607-
if (!HasAuthority)
1602+
if (!InternalHasAuthority())
16081603
{
16091604
if (NetworkManagerOwner.DistributedAuthorityMode)
16101605
{
@@ -1763,7 +1758,7 @@ private void OnDestroy()
17631758
{
17641759
// An authorized destroy is when done by the authority instance or done due to a scene event and the NetworkObject
17651760
// was marked as destroy pending scene event (which means the destroy with scene property was set).
1766-
var isAuthorityDestroy = HasAuthority || NetworkManager.DAHost || DestroyPendingSceneEvent;
1761+
var isAuthorityDestroy = InternalHasAuthority() || NetworkManager.DAHost || DestroyPendingSceneEvent;
17671762

17681763
// If the NetworkObject's GameObject is still valid and the scene is still valid and loaded, then we are still valid
17691764
var isStillValid = gameObject != null && gameObject.scene.IsValid() && gameObject.scene.isLoaded;
@@ -2102,7 +2097,7 @@ public void ChangeOwnership(ulong newOwnerClientId)
21022097
}
21032098
return;
21042099
}
2105-
NetworkManagerOwner.SpawnManager.ChangeOwnership(this, newOwnerClientId, HasAuthority);
2100+
NetworkManagerOwner.SpawnManager.ChangeOwnership(this, newOwnerClientId, InternalHasAuthority());
21062101
}
21072102

21082103
/// <summary>
@@ -2337,7 +2332,7 @@ public bool TrySetParent(NetworkObject parent, bool worldPositionStays = true)
23372332

23382333
// DANGO-TODO: Do we want to worry about ownership permissions here?
23392334
// It wouldn't make sense to not allow parenting, but keeping this note here as a reminder.
2340-
var isAuthority = HasAuthority || (AllowOwnerToParent && IsOwner);
2335+
var isAuthority = InternalHasAuthority() || (AllowOwnerToParent && IsOwner);
23412336

23422337
// If we don't have authority and we are not shutting down, then don't allow any parenting.
23432338
// If we are shutting down and don't have authority then allow it.
@@ -2412,7 +2407,7 @@ private void OnTransformParentChanged()
24122407

24132408
// With distributed authority, we need to track "valid authoritative" parenting changes.
24142409
// So, either the authority or AuthorityAppliedParenting is considered a "valid parenting change".
2415-
var isParentingAuthority = HasAuthority || AuthorityAppliedParenting || (AllowOwnerToParent && IsOwner);
2410+
var isParentingAuthority = InternalHasAuthority() || AuthorityAppliedParenting || (AllowOwnerToParent && IsOwner);
24162411
// If we are spawned and don't have authority; reset the parent back to the cached parent and exit
24172412
if (!isParentingAuthority)
24182413
{
@@ -3407,7 +3402,6 @@ internal static NetworkObject Deserialize(in SerializedObject serializedObject,
34073402
{
34083403
Destroy(networkObject.gameObject);
34093404
}
3410-
34113405
return null;
34123406
}
34133407

@@ -3529,7 +3523,7 @@ internal void SceneChangedUpdate(Scene scene, bool notify = false)
35293523
return;
35303524
}
35313525

3532-
var isAuthority = HasAuthority;
3526+
var isAuthority = InternalHasAuthority();
35333527
SceneOriginHandle = scene.handle;
35343528

35353529
// non-authority needs to update the NetworkSceneHandle

com.unity.netcode.gameobjects/Runtime/SceneManagement/DefaultSceneManagerHandler.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ public void MoveObjectsFromSceneToDontDestroyOnLoad(ref NetworkManager networkMa
302302
}
303303

304304
// Check to determine if we need to allow destroying a non-authority instance
305-
if (distributedAuthority && networkObject.DestroyWithScene && !networkObject.HasAuthority)
305+
if (distributedAuthority && networkObject.DestroyWithScene && !networkObject.InternalHasAuthority())
306306
{
307307
networkObject.DestroyPendingSceneEvent = true;
308308
}
@@ -316,7 +316,7 @@ public void MoveObjectsFromSceneToDontDestroyOnLoad(ref NetworkManager networkMa
316316
UnityEngine.Object.DontDestroyOnLoad(networkObject.gameObject);
317317
}
318318
}
319-
else if (networkObject.HasAuthority)
319+
else if (networkObject.InternalHasAuthority())
320320
{
321321
// We know this instance is going to be destroyed (when it receives the destroy object message).
322322
// We have to invoke this prior to invoking despawn in order to know that we are de-spawning in

com.unity.netcode.gameobjects/Runtime/SceneManagement/NetworkSceneManager.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2713,7 +2713,7 @@ internal void MoveObjectsToDontDestroyOnLoad()
27132713
}
27142714

27152715
// Check to determine if we need to allow destroying a non-authority instance
2716-
if (distributedAuthority && networkObject.DestroyWithScene && !networkObject.HasAuthority)
2716+
if (distributedAuthority && networkObject.DestroyWithScene && !networkObject.InternalHasAuthority())
27172717
{
27182718
networkObject.DestroyPendingSceneEvent = true;
27192719
}
@@ -2731,7 +2731,7 @@ internal void MoveObjectsToDontDestroyOnLoad()
27312731
networkObject.SceneOriginHandle = networkObject.gameObject.scene.handle;
27322732
}
27332733
}
2734-
else if (networkObject.HasAuthority)
2734+
else if (networkObject.InternalHasAuthority())
27352735
{
27362736
networkObject.SetIsDestroying();
27372737
// Only destroy non-scene placed NetworkObjects to avoid warnings about destroying in-scene placed NetworkObjects.
@@ -2889,7 +2889,7 @@ internal bool IsSceneUnloading(NetworkObject networkObject)
28892889
internal void NotifyNetworkObjectSceneChanged(NetworkObject networkObject)
28902890
{
28912891
// Really, this should never happen but in case it does
2892-
if (!networkObject.HasAuthority)
2892+
if (!networkObject.InternalHasAuthority())
28932893
{
28942894
if (NetworkManager.LogLevel == LogLevel.Developer)
28952895
{

com.unity.netcode.gameobjects/Runtime/Spawning/NetworkSpawnManager.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1574,7 +1574,7 @@ internal void ServerDestroySpawnedSceneObjects()
15741574
if (networkObject.InScenePlaced && networkObject.DestroyWithScene
15751575
&& networkObject.gameObject.scene != NetworkManager.SceneManager.DontDestroyOnLoadScene)
15761576
{
1577-
if (networkObject.IsSpawned && networkObject.HasAuthority)
1577+
if (networkObject.IsSpawned && networkObject.InternalHasAuthority())
15781578
{
15791579
networkObject.Despawn(false);
15801580
}
@@ -1729,7 +1729,7 @@ internal void ServerSpawnSceneObjectsOnStartSweep()
17291729
/// </summary>
17301730
internal void OnDespawnNonAuthorityObject([NotNull] NetworkObject networkObject, bool destroyGameObject)
17311731
{
1732-
if (networkObject.HasAuthority)
1732+
if (networkObject.InternalHasAuthority())
17331733
{
17341734
if (NetworkManager.LogLevel <= LogLevel.Error)
17351735
{
@@ -1806,7 +1806,7 @@ internal void OnDespawnObject([NotNull] NetworkObject networkObject, bool destro
18061806
}
18071807
// For mixed authority hierarchies, if the parent is despawned then any removal of children
18081808
// is considered "authority approved". Set the AuthorityAppliedParenting flag.
1809-
spawnedNetObj.AuthorityAppliedParenting = distributedAuthority && !networkObject.HasAuthority;
1809+
spawnedNetObj.AuthorityAppliedParenting = distributedAuthority && !networkObject.InternalHasAuthority();
18101810

18111811
// Try to remove the parent using the cached WorldPositionStays value
18121812
// Note: WorldPositionStays will still default to true if this was an
@@ -1834,7 +1834,7 @@ internal void OnDespawnObject([NotNull] NetworkObject networkObject, bool destro
18341834
networkObject.InvokeBehaviourNetworkDespawn();
18351835

18361836
// Whether we are in distributedAuthority mode and have authority on this object
1837-
var hasDAAuthority = distributedAuthority && (networkObject.HasAuthority || (NetworkManager.DAHost && authorityOverride));
1837+
var hasDAAuthority = distributedAuthority && (networkObject.InternalHasAuthority() || (NetworkManager.DAHost && authorityOverride));
18381838

18391839
// Don't send messages if shutting down
18401840
// Otherwise send messages if we are the authority (either the server, or the DA mode authority of this object).

0 commit comments

Comments
 (0)