ConnectionArray: syntax improved to simplify code

This commit is contained in:
vis2k 2018-06-13 11:54:43 +02:00
parent b7d128ba73
commit c81c670c95

View File

@ -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;