NetworkingPeer.HandleEventLeave C# (CSharp) Method

HandleEventLeave() private method

Called when the event Leave (of some other player) arrived. Cleans game objects, views locally. The master will also clean the
private HandleEventLeave ( int actorID, EventData, evLeave ) : void
actorID int ID of player who left.
evLeave EventData,
return void
    private void HandleEventLeave(int actorID, EventData evLeave)
    {
        if (PhotonNetwork.logLevel >= PhotonLogLevel.Informational)
            Debug.Log("HandleEventLeave for player ID: " + actorID);


        // actorNr is fetched out of event above
        if (actorID < 0 || !this.mActors.ContainsKey(actorID))
        {
            Debug.LogError(String.Format("Received event Leave for unknown player ID: {0}", actorID));
            return;
        }

        PhotonPlayer player = this.GetPlayerWithId(actorID);
        if (player == null)
        {
            Debug.LogError("HandleEventLeave for player ID: " + actorID + " has no PhotonPlayer!");
        }

        // having a new master before calling destroy for the leaving player is important!
        // so we elect a new masterclient and ignore the leaving player (who is still in playerlists).
        // note: there is/was a server-side-error which sent 0 as new master instead of skipping the key/value. below is a check for 0 due to that
        if (evLeave.Parameters.ContainsKey(ParameterCode.MasterClientId))
        {
            int newMaster = (int) evLeave[ParameterCode.MasterClientId];
            if (newMaster != 0)
            {
                this.mMasterClientId = (int)evLeave[ParameterCode.MasterClientId];
                this.UpdateMasterClient();
            }
        }
        else if (!this.CurrentGame.serverSideMasterClient)
        {
            this.CheckMasterClient(actorID);
        }


        // destroy objects & buffered messages
        if (this.CurrentGame != null && this.CurrentGame.autoCleanUp)
        {
            this.DestroyPlayerObjects(actorID, true);
        }

        RemovePlayer(actorID, player);

        // finally, send notification (the playerList and masterclient are now updated)
        SendMonoMessage(PhotonNetworkingMessage.OnPhotonPlayerDisconnected, player);
    }

Usage Example

Exemplo n.º 1
0
 public static void RemovePlayer(PhotonPlayer player)
 {
     if (player != null)
     {
         networkingPeer.HandleEventLeave(player.ID);
     }
 }
NetworkingPeer