From 5a161a07cecb80064c17b66fbed2d2834bbe8568 Mon Sep 17 00:00:00 2001 From: MrGadget1024 <9826063+MrGadget1024@users.noreply.github.com> Date: Sun, 5 Feb 2023 14:14:21 -0500 Subject: [PATCH] Simplified TryGetComponent usage --- .../Match/MatchInterestManagement.cs | 10 +++++----- .../InterestManagement/Team/TeamInterestManagement.cs | 10 +++++----- Assets/Mirror/Core/NetworkManager.cs | 4 ++-- 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/Assets/Mirror/Components/InterestManagement/Match/MatchInterestManagement.cs b/Assets/Mirror/Components/InterestManagement/Match/MatchInterestManagement.cs index 9785d126f..71238d26c 100644 --- a/Assets/Mirror/Components/InterestManagement/Match/MatchInterestManagement.cs +++ b/Assets/Mirror/Components/InterestManagement/Match/MatchInterestManagement.cs @@ -18,7 +18,7 @@ public class MatchInterestManagement : InterestManagement [ServerCallback] public override void OnSpawned(NetworkIdentity identity) { - if (!identity.TryGetComponent(out NetworkMatch networkMatch)) + if (!identity.TryGetComponent(out NetworkMatch networkMatch)) return; Guid networkMatchId = networkMatch.matchId; @@ -64,7 +64,7 @@ internal void Update() foreach (NetworkIdentity identity in NetworkServer.spawned.Values) { // Ignore objects that don't have a NetworkMatch component - if (!identity.TryGetComponent(out NetworkMatch networkMatch)) + if (!identity.TryGetComponent(out NetworkMatch networkMatch)) continue; Guid newMatch = networkMatch.matchId; @@ -128,7 +128,7 @@ void RebuildMatchObservers(Guid matchId) public override bool OnCheckObserver(NetworkIdentity identity, NetworkConnectionToClient newObserver) { // Never observed if no NetworkMatch component - if (!identity.TryGetComponent(out NetworkMatch identityNetworkMatch)) + if (!identity.TryGetComponent(out NetworkMatch identityNetworkMatch)) return false; // Guid.Empty is never a valid matchId @@ -136,7 +136,7 @@ public override bool OnCheckObserver(NetworkIdentity identity, NetworkConnection return false; // Never observed if no NetworkMatch component - if (!newObserver.identity.TryGetComponent(out NetworkMatch newObserverNetworkMatch)) + if (!newObserver.identity.TryGetComponent(out NetworkMatch newObserverNetworkMatch)) return false; // Guid.Empty is never a valid matchId @@ -148,7 +148,7 @@ public override bool OnCheckObserver(NetworkIdentity identity, NetworkConnection public override void OnRebuildObservers(NetworkIdentity identity, HashSet newObservers) { - if (!identity.TryGetComponent(out NetworkMatch networkMatch)) + if (!identity.TryGetComponent(out NetworkMatch networkMatch)) return; Guid matchId = networkMatch.matchId; diff --git a/Assets/Mirror/Components/InterestManagement/Team/TeamInterestManagement.cs b/Assets/Mirror/Components/InterestManagement/Team/TeamInterestManagement.cs index be13a5cf2..b543586f4 100644 --- a/Assets/Mirror/Components/InterestManagement/Team/TeamInterestManagement.cs +++ b/Assets/Mirror/Components/InterestManagement/Team/TeamInterestManagement.cs @@ -13,7 +13,7 @@ public class TeamInterestManagement : InterestManagement [ServerCallback] public override void OnSpawned(NetworkIdentity identity) { - if (!identity.TryGetComponent(out NetworkTeam identityNetworkTeam)) + if (!identity.TryGetComponent(out NetworkTeam identityNetworkTeam)) return; string networkTeamId = identityNetworkTeam.teamId; @@ -60,7 +60,7 @@ internal void Update() foreach (NetworkIdentity netIdentity in NetworkServer.spawned.Values) { // Ignore objects that don't have a NetworkTeam component - if (!netIdentity.TryGetComponent(out NetworkTeam identityNetworkTeam)) + if (!netIdentity.TryGetComponent(out NetworkTeam identityNetworkTeam)) continue; string networkTeamId = identityNetworkTeam.teamId; @@ -124,7 +124,7 @@ void RebuildTeamObservers(string teamId) public override bool OnCheckObserver(NetworkIdentity identity, NetworkConnectionToClient newObserver) { // Always observed if no NetworkTeam component - if (!identity.TryGetComponent(out NetworkTeam identityNetworkTeam)) + if (!identity.TryGetComponent(out NetworkTeam identityNetworkTeam)) return true; if (identityNetworkTeam.forceShown) @@ -135,7 +135,7 @@ public override bool OnCheckObserver(NetworkIdentity identity, NetworkConnection return false; // Always observed if no NetworkTeam component - if (!newObserver.identity.TryGetComponent(out NetworkTeam newObserverNetworkTeam)) + if (!newObserver.identity.TryGetComponent(out NetworkTeam newObserverNetworkTeam)) return true; // Null / Empty string is never a valid teamId @@ -151,7 +151,7 @@ public override bool OnCheckObserver(NetworkIdentity identity, NetworkConnection public override void OnRebuildObservers(NetworkIdentity identity, HashSet newObservers) { // If this object doesn't have a NetworkTeam then it's visible to all clients - if (!identity.TryGetComponent(out NetworkTeam networkTeam)) + if (!identity.TryGetComponent(out NetworkTeam networkTeam)) { AddAllConnections(newObservers); return; diff --git a/Assets/Mirror/Core/NetworkManager.cs b/Assets/Mirror/Core/NetworkManager.cs index 14a82e297..cdea17c74 100644 --- a/Assets/Mirror/Core/NetworkManager.cs +++ b/Assets/Mirror/Core/NetworkManager.cs @@ -153,7 +153,7 @@ public virtual void OnValidate() // always >= 0 maxConnections = Mathf.Max(maxConnections, 0); - if (playerPrefab != null && !playerPrefab.TryGetComponent(out _)) + if (playerPrefab != null && !playerPrefab.TryGetComponent(out NetworkIdentity _)) { Debug.LogError("NetworkManager - Player Prefab must have a NetworkIdentity."); playerPrefab = null; @@ -1133,7 +1133,7 @@ void OnServerAddPlayerInternal(NetworkConnectionToClient conn, AddPlayerMessage return; } - if (autoCreatePlayer && !playerPrefab.TryGetComponent(out _)) + if (autoCreatePlayer && !playerPrefab.TryGetComponent(out NetworkIdentity _)) { Debug.LogError("The PlayerPrefab does not have a NetworkIdentity. Please add a NetworkIdentity to the player prefab."); return;