mirror of
https://github.com/MirrorNetworking/Mirror.git
synced 2024-11-18 02:50:32 +00:00
NetworkProximityChecker: syntax improved to simplify code
This commit is contained in:
parent
6504349fd9
commit
049a73b5a8
@ -48,21 +48,15 @@ public override bool OnCheckObserver(NetworkConnection newObserver)
|
|||||||
return false;
|
return false;
|
||||||
|
|
||||||
// this cant use newObserver.playerControllers[0]. must iterate to find a valid player.
|
// this cant use newObserver.playerControllers[0]. must iterate to find a valid player.
|
||||||
GameObject player = null;
|
PlayerController controller = newObserver.playerControllers.Find(
|
||||||
for (int i = 0; i < newObserver.playerControllers.Count; i++)
|
pc => pc != null && pc.gameObject != null
|
||||||
|
);
|
||||||
|
if (controller != null)
|
||||||
{
|
{
|
||||||
var p = newObserver.playerControllers[i];
|
GameObject player = controller.gameObject;
|
||||||
if (p != null && p.gameObject != null)
|
return Vector3.Distance(player.transform.position, transform.position) < visRange;
|
||||||
{
|
|
||||||
player = p.gameObject;
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if (player == null)
|
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
var pos = player.transform.position;
|
|
||||||
return (pos - transform.position).magnitude < visRange;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override bool OnRebuildObservers(HashSet<NetworkConnection> observers, bool initial)
|
public override bool OnRebuildObservers(HashSet<NetworkConnection> observers, bool initial)
|
||||||
|
Loading…
Reference in New Issue
Block a user