mirror of
https://github.com/MirrorNetworking/Mirror.git
synced 2024-11-18 11:00:32 +00:00
Simplified TryGetComponent usage
This commit is contained in:
parent
467aa70e3d
commit
5a161a07ce
@ -18,7 +18,7 @@ public class MatchInterestManagement : InterestManagement
|
|||||||
[ServerCallback]
|
[ServerCallback]
|
||||||
public override void OnSpawned(NetworkIdentity identity)
|
public override void OnSpawned(NetworkIdentity identity)
|
||||||
{
|
{
|
||||||
if (!identity.TryGetComponent<NetworkMatch>(out NetworkMatch networkMatch))
|
if (!identity.TryGetComponent(out NetworkMatch networkMatch))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
Guid networkMatchId = networkMatch.matchId;
|
Guid networkMatchId = networkMatch.matchId;
|
||||||
@ -64,7 +64,7 @@ internal void Update()
|
|||||||
foreach (NetworkIdentity identity in NetworkServer.spawned.Values)
|
foreach (NetworkIdentity identity in NetworkServer.spawned.Values)
|
||||||
{
|
{
|
||||||
// Ignore objects that don't have a NetworkMatch component
|
// Ignore objects that don't have a NetworkMatch component
|
||||||
if (!identity.TryGetComponent<NetworkMatch>(out NetworkMatch networkMatch))
|
if (!identity.TryGetComponent(out NetworkMatch networkMatch))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
Guid newMatch = networkMatch.matchId;
|
Guid newMatch = networkMatch.matchId;
|
||||||
@ -128,7 +128,7 @@ void RebuildMatchObservers(Guid matchId)
|
|||||||
public override bool OnCheckObserver(NetworkIdentity identity, NetworkConnectionToClient newObserver)
|
public override bool OnCheckObserver(NetworkIdentity identity, NetworkConnectionToClient newObserver)
|
||||||
{
|
{
|
||||||
// Never observed if no NetworkMatch component
|
// Never observed if no NetworkMatch component
|
||||||
if (!identity.TryGetComponent<NetworkMatch>(out NetworkMatch identityNetworkMatch))
|
if (!identity.TryGetComponent(out NetworkMatch identityNetworkMatch))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// Guid.Empty is never a valid matchId
|
// Guid.Empty is never a valid matchId
|
||||||
@ -136,7 +136,7 @@ public override bool OnCheckObserver(NetworkIdentity identity, NetworkConnection
|
|||||||
return false;
|
return false;
|
||||||
|
|
||||||
// Never observed if no NetworkMatch component
|
// Never observed if no NetworkMatch component
|
||||||
if (!newObserver.identity.TryGetComponent<NetworkMatch>(out NetworkMatch newObserverNetworkMatch))
|
if (!newObserver.identity.TryGetComponent(out NetworkMatch newObserverNetworkMatch))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// Guid.Empty is never a valid matchId
|
// 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)
|
public override void OnRebuildObservers(NetworkIdentity identity, HashSet<NetworkConnectionToClient> newObservers)
|
||||||
{
|
{
|
||||||
if (!identity.TryGetComponent<NetworkMatch>(out NetworkMatch networkMatch))
|
if (!identity.TryGetComponent(out NetworkMatch networkMatch))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
Guid matchId = networkMatch.matchId;
|
Guid matchId = networkMatch.matchId;
|
||||||
|
@ -13,7 +13,7 @@ public class TeamInterestManagement : InterestManagement
|
|||||||
[ServerCallback]
|
[ServerCallback]
|
||||||
public override void OnSpawned(NetworkIdentity identity)
|
public override void OnSpawned(NetworkIdentity identity)
|
||||||
{
|
{
|
||||||
if (!identity.TryGetComponent<NetworkTeam>(out NetworkTeam identityNetworkTeam))
|
if (!identity.TryGetComponent(out NetworkTeam identityNetworkTeam))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
string networkTeamId = identityNetworkTeam.teamId;
|
string networkTeamId = identityNetworkTeam.teamId;
|
||||||
@ -60,7 +60,7 @@ internal void Update()
|
|||||||
foreach (NetworkIdentity netIdentity in NetworkServer.spawned.Values)
|
foreach (NetworkIdentity netIdentity in NetworkServer.spawned.Values)
|
||||||
{
|
{
|
||||||
// Ignore objects that don't have a NetworkTeam component
|
// Ignore objects that don't have a NetworkTeam component
|
||||||
if (!netIdentity.TryGetComponent<NetworkTeam>(out NetworkTeam identityNetworkTeam))
|
if (!netIdentity.TryGetComponent(out NetworkTeam identityNetworkTeam))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
string networkTeamId = identityNetworkTeam.teamId;
|
string networkTeamId = identityNetworkTeam.teamId;
|
||||||
@ -124,7 +124,7 @@ void RebuildTeamObservers(string teamId)
|
|||||||
public override bool OnCheckObserver(NetworkIdentity identity, NetworkConnectionToClient newObserver)
|
public override bool OnCheckObserver(NetworkIdentity identity, NetworkConnectionToClient newObserver)
|
||||||
{
|
{
|
||||||
// Always observed if no NetworkTeam component
|
// Always observed if no NetworkTeam component
|
||||||
if (!identity.TryGetComponent<NetworkTeam>(out NetworkTeam identityNetworkTeam))
|
if (!identity.TryGetComponent(out NetworkTeam identityNetworkTeam))
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
if (identityNetworkTeam.forceShown)
|
if (identityNetworkTeam.forceShown)
|
||||||
@ -135,7 +135,7 @@ public override bool OnCheckObserver(NetworkIdentity identity, NetworkConnection
|
|||||||
return false;
|
return false;
|
||||||
|
|
||||||
// Always observed if no NetworkTeam component
|
// Always observed if no NetworkTeam component
|
||||||
if (!newObserver.identity.TryGetComponent<NetworkTeam>(out NetworkTeam newObserverNetworkTeam))
|
if (!newObserver.identity.TryGetComponent(out NetworkTeam newObserverNetworkTeam))
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
// Null / Empty string is never a valid teamId
|
// 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)
|
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 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);
|
AddAllConnections(newObservers);
|
||||||
return;
|
return;
|
||||||
|
@ -153,7 +153,7 @@ public virtual void OnValidate()
|
|||||||
// always >= 0
|
// always >= 0
|
||||||
maxConnections = Mathf.Max(maxConnections, 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.");
|
Debug.LogError("NetworkManager - Player Prefab must have a NetworkIdentity.");
|
||||||
playerPrefab = null;
|
playerPrefab = null;
|
||||||
@ -1133,7 +1133,7 @@ void OnServerAddPlayerInternal(NetworkConnectionToClient conn, AddPlayerMessage
|
|||||||
return;
|
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.");
|
Debug.LogError("The PlayerPrefab does not have a NetworkIdentity. Please add a NetworkIdentity to the player prefab.");
|
||||||
return;
|
return;
|
||||||
|
Loading…
Reference in New Issue
Block a user