NetworkProximityChecker: syntax improved to simplify code

This commit is contained in:
vis2k 2018-06-11 12:43:18 +02:00
parent 6504349fd9
commit 049a73b5a8

View File

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