From c81c670c95444cce80cc6dda1f510fbfdb74e1ea Mon Sep 17 00:00:00 2001 From: vis2k Date: Wed, 13 Jun 2018 11:54:43 +0200 Subject: [PATCH] ConnectionArray: syntax improved to simplify code --- .../Runtime/ConnectionArray.cs | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/Unity-Technologies-networking/Runtime/ConnectionArray.cs b/Unity-Technologies-networking/Runtime/ConnectionArray.cs index e5fb6e53d..4c530c131 100644 --- a/Unity-Technologies-networking/Runtime/ConnectionArray.cs +++ b/Unity-Technologies-networking/Runtime/ConnectionArray.cs @@ -1,6 +1,7 @@ #if ENABLE_UNET using System; using System.Collections.Generic; +using System.Linq; namespace UnityEngine.Networking { @@ -68,11 +69,7 @@ public NetworkConnection Get(int connId) // call this if the connection may not exist (in disconnect handler) public NetworkConnection GetUnsafe(int connId) { - if (connId < 0 || connId >= m_Connections.Count) - { - return null; - } - return m_Connections[connId]; + return (0 <= connId && connId < connections.Count) ? m_Connections[connId] : null; } public void Remove(int connId) @@ -83,7 +80,7 @@ public void Remove(int connId) return; } - if (connId < 0 || connId >= m_Connections.Count) + if (connId >= m_Connections.Count) { if (LogFilter.logWarn) { Debug.LogWarning("ConnectionArray Remove invalid index " + connId); } return; @@ -108,15 +105,9 @@ public bool ContainsPlayer(GameObject player, out NetworkConnection conn) for (int i = LocalIndex; i < m_Connections.Count; i++) { conn = Get(i); - if (conn != null) + if (conn != null && conn.playerControllers.Any(pc => pc.IsValid && pc.gameObject == player)) { - for (int j = 0; j < conn.playerControllers.Count; j++) - { - if (conn.playerControllers[j].IsValid && conn.playerControllers[j].gameObject == player) - { - return true; - } - } + return true; } } return false;