Moved GetStartPosition to correct region

This commit is contained in:
Chris Langsenkamp 2020-05-27 22:51:26 -04:00
parent 9ae7fa2a8c
commit 7d9175dfc7

View File

@ -1092,6 +1092,31 @@ public static void UnRegisterStartPosition(Transform start)
startPositions.Remove(start);
}
/// <summary>
/// This finds a spawn position based on NetworkStartPosition objects in the scene.
/// <para>This is used by the default implementation of OnServerAddPlayer.</para>
/// </summary>
/// <returns>Returns the transform to spawn a player at, or null.</returns>
public Transform GetStartPosition()
{
// first remove any dead transforms
startPositions.RemoveAll(t => t == null);
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;
}
}
#endregion
#region Server Internal Message Handlers
@ -1306,31 +1331,6 @@ public virtual void OnServerAddPlayer(NetworkConnection conn)
NetworkServer.AddPlayerForConnection(conn, player);
}
/// <summary>
/// This finds a spawn position based on NetworkStartPosition objects in the scene.
/// <para>This is used by the default implementation of OnServerAddPlayer.</para>
/// </summary>
/// <returns>Returns the transform to spawn a player at, or null.</returns>
public Transform GetStartPosition()
{
// first remove any dead transforms
startPositions.RemoveAll(t => t == null);
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;
}
}
// Deprecated 5/2/2020
/// <summary>
/// Obsolete: Removed as a security risk. Use <see cref="NetworkServer.RemovePlayerForConnection(NetworkConnection, bool)">NetworkServer.RemovePlayerForConnection</see> instead.