From 6ab0a0a7c274807d962d215e3dea045453950e10 Mon Sep 17 00:00:00 2001 From: Paul Pacheco Date: Fri, 22 Feb 2019 19:17:15 -0600 Subject: [PATCH] use C#7 out variable declaration --- Assets/Mirror/Runtime/NetworkServer.cs | 37 +++++++++----------------- 1 file changed, 12 insertions(+), 25 deletions(-) diff --git a/Assets/Mirror/Runtime/NetworkServer.cs b/Assets/Mirror/Runtime/NetworkServer.cs index 196ef6677..0e4d72a20 100644 --- a/Assets/Mirror/Runtime/NetworkServer.cs +++ b/Assets/Mirror/Runtime/NetworkServer.cs @@ -337,8 +337,7 @@ static void OnDisconnected(int connectionId) { if (LogFilter.Debug) { Debug.Log("Server disconnect client:" + connectionId); } - NetworkConnection conn; - if (connections.TryGetValue(connectionId, out conn)) + if (connections.TryGetValue(connectionId, out NetworkConnection conn)) { conn.Disconnect(); RemoveConnection(connectionId); @@ -365,8 +364,7 @@ static void OnDisconnected(NetworkConnection conn) static void OnDataReceived(int connectionId, byte[] data) { - NetworkConnection conn; - if (connections.TryGetValue(connectionId, out conn)) + if (connections.TryGetValue(connectionId, out NetworkConnection conn)) { OnData(conn, data); } @@ -459,8 +457,7 @@ public static void ClearHandlers() public static void SendToClient(int connectionId, short msgType, MessageBase msg) { - NetworkConnection conn; - if (connections.TryGetValue(connectionId, out conn)) + if (connections.TryGetValue(connectionId, out NetworkConnection conn)) { conn.Send(msgType, msg); return; @@ -483,8 +480,7 @@ public static void SendToClientOfPlayer(NetworkIdentity identity, short msgType, public static bool ReplacePlayerForConnection(NetworkConnection conn, GameObject player, Guid assetId) { - NetworkIdentity identity; - if (GetNetworkIdentity(player, out identity)) + if (GetNetworkIdentity(player, out NetworkIdentity identity)) { identity.SetDynamicAssetId(assetId); } @@ -498,8 +494,7 @@ public static bool ReplacePlayerForConnection(NetworkConnection conn, GameObject public static bool AddPlayerForConnection(NetworkConnection conn, GameObject player, Guid assetId) { - NetworkIdentity identity; - if (GetNetworkIdentity(player, out identity)) + if (GetNetworkIdentity(player, out NetworkIdentity identity)) { identity.SetDynamicAssetId(assetId); } @@ -798,8 +793,7 @@ static void OnCommandMessage(NetworkMessage netMsg) { CommandMessage message = netMsg.ReadMessage(); - NetworkIdentity identity; - if (!NetworkIdentity.spawned.TryGetValue(message.netId, out identity)) + if (!NetworkIdentity.spawned.TryGetValue(message.netId, out NetworkIdentity identity)) { Debug.LogWarning("Spawned object not found when handling Command message [netId=" + message.netId + "]"); return; @@ -916,8 +910,7 @@ public static void DestroyPlayerForConnection(NetworkConnection conn) HashSet tmp = new HashSet(conn.clientOwnedObjects); foreach (uint netId in tmp) { - NetworkIdentity identity; - if (NetworkIdentity.spawned.TryGetValue(netId, out identity)) + if (NetworkIdentity.spawned.TryGetValue(netId, out NetworkIdentity identity)) { Destroy(identity.gameObject); } @@ -1022,8 +1015,7 @@ public static void Spawn(GameObject obj, Guid assetId) { if (VerifyCanSpawn(obj)) { - NetworkIdentity identity; - if (GetNetworkIdentity(obj, out identity)) + if (GetNetworkIdentity(obj, out NetworkIdentity identity)) { identity.SetDynamicAssetId(assetId); } @@ -1066,8 +1058,7 @@ public static void Destroy(GameObject obj) return; } - NetworkIdentity identity; - if (GetNetworkIdentity(obj, out identity)) + if (GetNetworkIdentity(obj, out NetworkIdentity identity)) { DestroyObject(identity, true); } @@ -1081,8 +1072,7 @@ public static void UnSpawn(GameObject obj) return; } - NetworkIdentity identity; - if (GetNetworkIdentity(obj, out identity)) + if (GetNetworkIdentity(obj, out NetworkIdentity identity)) { DestroyObject(identity, false); } @@ -1090,9 +1080,7 @@ public static void UnSpawn(GameObject obj) internal static bool InvokeBytes(ULocalConnectionToServer conn, byte[] buffer) { - ushort msgType; - byte[] content; - if (Protocol.UnpackMessage(buffer, out msgType, out content)) + if (Protocol.UnpackMessage(buffer, out ushort msgType, out byte[] content)) { if (handlers.ContainsKey((short)msgType) && s_LocalConnection != null) { @@ -1108,8 +1096,7 @@ internal static bool InvokeBytes(ULocalConnectionToServer conn, byte[] buffer) [Obsolete("Use NetworkIdentity.spawned[netId] instead.")] public static GameObject FindLocalObject(uint netId) { - NetworkIdentity identity; - if (NetworkIdentity.spawned.TryGetValue(netId, out identity)) + if (NetworkIdentity.spawned.TryGetValue(netId, out NetworkIdentity identity)) { return identity.gameObject; }