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
@ -686,30 +686,23 @@ public virtual void OnServerAddPlayer(NetworkConnection conn, AddPlayerMessage e
|
|||||||
NetworkServer.AddPlayerForConnection(conn, player);
|
NetworkServer.AddPlayerForConnection(conn, player);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Transform GetStartPosition()
|
public Transform GetStartPosition()
|
||||||
{
|
{
|
||||||
// first remove any dead transforms
|
// first remove any dead transforms
|
||||||
startPositions.RemoveAll(t => t == null);
|
startPositions.RemoveAll(t => t == null);
|
||||||
|
|
||||||
if (playerSpawnMethod == PlayerSpawnMethod.Random && startPositions.Count > 0)
|
if (startPositions.Count == 0)
|
||||||
{
|
return null;
|
||||||
// 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];
|
if (playerSpawnMethod == PlayerSpawnMethod.Random)
|
||||||
startPositionIndex += 1;
|
return startPositions[UnityEngine.Random.Range(0, startPositions.Count)];
|
||||||
return startPos;
|
else
|
||||||
}
|
{
|
||||||
return null;
|
Transform startPosition = startPositions[startPositionIndex];
|
||||||
}
|
startPositionIndex = (startPositionIndex + 1) % startPositions.Count;
|
||||||
|
return startPosition;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public virtual void OnServerRemovePlayer(NetworkConnection conn, NetworkIdentity player)
|
public virtual void OnServerRemovePlayer(NetworkConnection conn, NetworkIdentity player)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user