private void CheckMasterClient(int leavingPlayerId)
{
bool currentMasterIsLeaving = this.mMasterClientId == leavingPlayerId;
bool someoneIsLeaving = leavingPlayerId > 0;
// return early if SOME player (leavingId > 0) is leaving AND it's NOT the current master
if (someoneIsLeaving && !currentMasterIsLeaving)
{
return;
}
// picking the player with lowest ID (longest in game).
int lowestActorNumber;
if (this.mActors.Count <= 1)
{
lowestActorNumber = this.mLocalActor.ID;
}
else
{
// keys in mActors are their actorNumbers
lowestActorNumber = Int32.MaxValue;
foreach (int key in this.mActors.Keys)
{
if (key < lowestActorNumber && key != leavingPlayerId)
{
lowestActorNumber = key;
}
}
}
this.mMasterClientId = lowestActorNumber;
// callback ONLY when the current master left
if (someoneIsLeaving)
{
SendMonoMessage(PhotonNetworkingMessage.OnMasterClientSwitched, this.GetPlayerWithId(lowestActorNumber));
}
}