Issue:
Not too long ago players who are currently leaving have been made valid when using the
VRCPlayerAPI.IsValid()
check. While this allows using them during
OnPlayerLeft
etc, it has made knowing when you are dealing with a leaving player a lot more difficult.
When you are for example manually checking who to move ownership of a system to, you have to cache your self that this player is in the process of leaving in
OnPlayerLeft
.
Suggestion:
Add a
VRCPlayerAPI.IsLeaving
check, this should return true if this player is currently in the process of leaving the instance and false if not.
This should allow making systems like thew following easier to implement;
public override void OnPlayerLeft(VRCPlayerApi player)
{
leavingPlayer = player;
}
/// <summary>
/// Returns the <see cref="VRCPlayerApi"/> of a whitelisted player in the instance.
/// Useful for getting a player to move ownership of an object to.
/// </summary>
/// <returns>
/// A <see cref="VRCPlayerApi"/> of a whitelisted player in the instance,
/// or <c>null</c> if none are present.
/// </returns>
public virtual VRCPlayerApi _GetPlayerInInstance()
{
var players = new VRCPlayerApi[VRCPlayerApi.GetPlayerCount()];
VRCPlayerApi.GetPlayers(players);
foreach (var player in players)
{
if (!player.IsValid()) continue;
if (!_IsPlayerWhitelisted(player)) continue;
if (player == leavingPlayer) continue;
return player;
}
return null;
}