mirror of
https://github.com/MirrorNetworking/Mirror.git
synced 2024-11-18 02:50:32 +00:00
ConnectionArray: syntax improved to simplify code
This commit is contained in:
parent
b7d128ba73
commit
c81c670c95
@ -1,6 +1,7 @@
|
|||||||
#if ENABLE_UNET
|
#if ENABLE_UNET
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
|
||||||
namespace UnityEngine.Networking
|
namespace UnityEngine.Networking
|
||||||
{
|
{
|
||||||
@ -68,11 +69,7 @@ public NetworkConnection Get(int connId)
|
|||||||
// call this if the connection may not exist (in disconnect handler)
|
// call this if the connection may not exist (in disconnect handler)
|
||||||
public NetworkConnection GetUnsafe(int connId)
|
public NetworkConnection GetUnsafe(int connId)
|
||||||
{
|
{
|
||||||
if (connId < 0 || connId >= m_Connections.Count)
|
return (0 <= connId && connId < connections.Count) ? m_Connections[connId] : null;
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return m_Connections[connId];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Remove(int connId)
|
public void Remove(int connId)
|
||||||
@ -83,7 +80,7 @@ public void Remove(int connId)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (connId < 0 || connId >= m_Connections.Count)
|
if (connId >= m_Connections.Count)
|
||||||
{
|
{
|
||||||
if (LogFilter.logWarn) { Debug.LogWarning("ConnectionArray Remove invalid index " + connId); }
|
if (LogFilter.logWarn) { Debug.LogWarning("ConnectionArray Remove invalid index " + connId); }
|
||||||
return;
|
return;
|
||||||
@ -108,15 +105,9 @@ public bool ContainsPlayer(GameObject player, out NetworkConnection conn)
|
|||||||
for (int i = LocalIndex; i < m_Connections.Count; i++)
|
for (int i = LocalIndex; i < m_Connections.Count; i++)
|
||||||
{
|
{
|
||||||
conn = Get(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++)
|
return true;
|
||||||
{
|
|
||||||
if (conn.playerControllers[j].IsValid && conn.playerControllers[j].gameObject == player)
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
Loading…
Reference in New Issue
Block a user