TransferOwnership









How do I use Transfer Ownership
Below are practical examples compiled from projects for learning and reference purposes

Featured Snippets


File name: DemoOwnershipGui.cs Copy
8     public void OnOwnershipRequest(object[] viewAndPlayer)
9     {
10         PhotonView view = viewAndPlayer[0] as PhotonView;
11         PhotonPlayer requestingPlayer = viewAndPlayer[1] as PhotonPlayer;
12
13         Debug.Log("OnOwnershipRequest(): Player " + requestingPlayer + " requests ownership of: " + view + ".");
14         if (this.TransferOwnershipOnRequest)
15         {
16             view.TransferOwnership(requestingPlayer.ID);
17         }
18     }
File name: DemoOwnershipGui.cs Copy
23     public void OnGUI()
24     {
25         GUI.skin = this.Skin;
26         GUILayout.BeginArea(new Rect(Screen.width - 200, 0, 200, Screen.height));
27         {
28             string label = TransferOwnershipOnRequest ? "passing objects" : "rejecting to pass";
29             if (GUILayout.Button(label))
30             {
31                 this.TransferOwnershipOnRequest = !this.TransferOwnershipOnRequest;
32             }
33         }
34         GUILayout.EndArea();
35
36
37
38         if (PhotonNetwork.inRoom)
39         {
40             int playerNr = PhotonNetwork.player.ID;
41             string playerIsMaster = PhotonNetwork.player.isMasterClient ? "(master) " : "";
42             string playerColor = PlayerVariables.GetColorName(PhotonNetwork.player.ID);
43             GUILayout.Label(string.Format("player {0}, {1} {2}(you)", playerNr, playerColor, playerIsMaster));
44
45             foreach (PhotonPlayer otherPlayer in PhotonNetwork.otherPlayers)
46             {
47                 playerNr = otherPlayer.ID;
48                 playerIsMaster = otherPlayer.isMasterClient ? "(master)" : "";
49                 playerColor = PlayerVariables.GetColorName(otherPlayer.ID);
50                 GUILayout.Label(string.Format("player {0}, {1} {2}", playerNr, playerColor, playerIsMaster));
51             }
52
53             if (PhotonNetwork.inRoom && PhotonNetwork.otherPlayers.Length == 0)
54             {
55                 GUILayout.Label("Join more clients to switch object-control.");
56             }
57         }
58         else
59         {
60             GUILayout.Label(PhotonNetwork.connectionStateDetailed.ToString());
61         }
62     }
File name: NetworkingPeer.cs Copy
2649     internal protected void TransferOwnership(int viewID, int playerID)
2650     {
2651         Debug.Log("TransferOwnership() view " + viewID + " to: " + playerID + " Time: " + Environment.TickCount % 1000);
2652         //PhotonNetwork.networkingPeer.OpRaiseEvent(PunEvent.OwnershipTransfer, true, new int[] {viewID, playerID}, 0, EventCaching.DoNotCache, null, ReceiverGroup.All, 0);
2653         this.OpRaiseEvent(PunEvent.OwnershipTransfer, new int[] { viewID, playerID }, true, new RaiseEventOptions() { Receivers = ReceiverGroup.All }); // All sends to all via server (including self)
2654     }
File name: PhotonView.cs Copy
272     public void TransferOwnership(PhotonPlayer newOwner)
273     {
274         this.TransferOwnership(newOwner.ID);
275     }
File name: PhotonView.cs Copy
283     public void TransferOwnership(int newOwnerId)
284     {
285         PhotonNetwork.networkingPeer.TransferOwnership(this.viewID, newOwnerId);
286         this.ownerId = newOwnerId; // immediately switch ownership locally, to avoid more updates sent from this client.
287     }

TransferOwnership 438 lượt xem

Gõ tìm kiếm nhanh...