mirror of
https://github.com/MirrorNetworking/Mirror.git
synced 2024-11-18 02:50:32 +00:00
Simplified TryGetComponent usage
This commit is contained in:
parent
467aa70e3d
commit
5a161a07ce
@ -18,7 +18,7 @@ public class MatchInterestManagement : InterestManagement
|
||||
[ServerCallback]
|
||||
public override void OnSpawned(NetworkIdentity identity)
|
||||
{
|
||||
if (!identity.TryGetComponent<NetworkMatch>(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<NetworkMatch>(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<NetworkMatch>(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<NetworkMatch>(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<NetworkConnectionToClient> newObservers)
|
||||
{
|
||||
if (!identity.TryGetComponent<NetworkMatch>(out NetworkMatch networkMatch))
|
||||
if (!identity.TryGetComponent(out NetworkMatch networkMatch))
|
||||
return;
|
||||
|
||||
Guid matchId = networkMatch.matchId;
|
||||
|
@ -13,7 +13,7 @@ public class TeamInterestManagement : InterestManagement
|
||||
[ServerCallback]
|
||||
public override void OnSpawned(NetworkIdentity identity)
|
||||
{
|
||||
if (!identity.TryGetComponent<NetworkTeam>(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<NetworkTeam>(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<NetworkTeam>(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<NetworkTeam>(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<NetworkConnectionToClient> newObservers)
|
||||
{
|
||||
// If this object doesn't have a NetworkTeam then it's visible to all clients
|
||||
if (!identity.TryGetComponent<NetworkTeam>(out NetworkTeam networkTeam))
|
||||
if (!identity.TryGetComponent(out NetworkTeam networkTeam))
|
||||
{
|
||||
AddAllConnections(newObservers);
|
||||
return;
|
||||
|
@ -153,7 +153,7 @@ public virtual void OnValidate()
|
||||
// always >= 0
|
||||
maxConnections = Mathf.Max(maxConnections, 0);
|
||||
|
||||
if (playerPrefab != null && !playerPrefab.TryGetComponent<NetworkIdentity>(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<NetworkIdentity>(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;
|
||||
|
Loading…
Reference in New Issue
Block a user