mirror of
https://github.com/MirrorNetworking/Mirror.git
synced 2024-11-18 11:00:32 +00:00
refactor: Simplify GetStartPosition (#828)
* Simplify GetStartPosition - Early out if startPositions.Count = 0 - Reduces the normal returns to single LOC each - Only resets startPositionIndex if it reaches int.MaxValue - Uses modulo and increment-after against count to pick round robin index - Eliminates unnecessary last return that could never be reached * Per Paul's request
This commit is contained in:
parent
ec5b735f4a
commit
bcd3424c0e
@ -691,24 +691,17 @@ public Transform GetStartPosition()
|
||||
// first remove any dead transforms
|
||||
startPositions.RemoveAll(t => t == null);
|
||||
|
||||
if (playerSpawnMethod == PlayerSpawnMethod.Random && startPositions.Count > 0)
|
||||
{
|
||||
// try to spawn at a random start location
|
||||
int index = UnityEngine.Random.Range(0, startPositions.Count);
|
||||
return startPositions[index];
|
||||
}
|
||||
if (playerSpawnMethod == PlayerSpawnMethod.RoundRobin && startPositions.Count > 0)
|
||||
{
|
||||
if (startPositionIndex >= startPositions.Count)
|
||||
{
|
||||
startPositionIndex = 0;
|
||||
}
|
||||
|
||||
Transform startPos = startPositions[startPositionIndex];
|
||||
startPositionIndex += 1;
|
||||
return startPos;
|
||||
}
|
||||
if (startPositions.Count == 0)
|
||||
return null;
|
||||
|
||||
if (playerSpawnMethod == PlayerSpawnMethod.Random)
|
||||
return startPositions[UnityEngine.Random.Range(0, startPositions.Count)];
|
||||
else
|
||||
{
|
||||
Transform startPosition = startPositions[startPositionIndex];
|
||||
startPositionIndex = (startPositionIndex + 1) % startPositions.Count;
|
||||
return startPosition;
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void OnServerRemovePlayer(NetworkConnection conn, NetworkIdentity player)
|
||||
|
Loading…
Reference in New Issue
Block a user