NetworkingPeer.DestroyPlayerObjects C# (CSharp) Method

DestroyPlayerObjects() public method

Destroys all Instantiates and RPCs locally and (if not localOnly) sends EvDestroy(player) and clears related events in the server buffer.
public DestroyPlayerObjects ( int playerId, bool localOnly ) : void
playerId int
localOnly bool
return void
    public void DestroyPlayerObjects(int playerId, bool localOnly)
    {
        if (playerId <= 0)
        {
            Debug.LogError("Failed to Destroy objects of playerId: " + playerId);
            return;
        }

        if (!localOnly)
        {
            // clean server's Instantiate and RPC buffers
            this.OpRemoveFromServerInstantiationsOfPlayer(playerId);
            this.OpCleanRpcBuffer(playerId);

            // send Destroy(player) to anyone else
            this.SendDestroyOfPlayer(playerId);
        }

        // locally cleaning up that player's objects
        HashSet<GameObject> playersGameObjects = new HashSet<GameObject>();
        foreach (PhotonView view in this.photonViewList.Values)
        {
            if (view.CreatorActorNr == playerId)
            {
                playersGameObjects.Add(view.gameObject);
            }
        }

        // any non-local work is already done, so with the list of that player's objects, we can clean up (locally only)
        foreach (GameObject gameObject in playersGameObjects)
        {
            this.RemoveInstantiatedGO(gameObject, true);
        }

        // with ownership transfer, some objects might lose their owner.
        // in that case, the creator becomes the owner again. every client can apply this. done below.
        foreach (PhotonView view in this.photonViewList.Values)
        {
            if (view.ownerId == playerId)
            {
                view.ownerId = view.CreatorActorNr;
                //Debug.Log("Creator is: " + view.ownerId);
            }
        }
    }

Usage Example

Exemplo n.º 1
0
    /// <summary>
    /// Destroy all GameObjects/PhotonViews of this player.
    /// </summary>
    /// <param name="player"></param>
    public static void DestroyPlayerObjects(PhotonPlayer player)
    {
        if (!VerifyCanUseNetwork())
        {
            return;
        }

        networkingPeer.DestroyPlayerObjects(player);
    }
All Usage Examples Of NetworkingPeer::DestroyPlayerObjects
NetworkingPeer