MORE
How do I use M O R E
Below are practical examples compiled from projects for learning and reference purposes
Featured Snippets
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: GUIFriendsInRoom.cs
Copy
15 public void OnGUI()
16 {
17 if (PhotonNetwork.connectionStateDetailed != PeerState.Joined)
18 {
19 return;
20 }
21
22 GUILayout.BeginArea(GuiRect);
23
24 GUILayout.Label("In-Game");
25 GUILayout.Label("For simplicity, this demo just shows the players in this room. The list will expand when more join.");
26 GUILayout.Label("Your (random) name: " + PhotonNetwork.playerName);
27 GUILayout.Label(PhotonNetwork.playerList.Length + " players in this room.");
28 GUILayout.Label("The others are:");
29 foreach (PhotonPlayer player in PhotonNetwork.otherPlayers)
30 {
31 GUILayout.Label(player.ToString());
32 }
33
34 if (GUILayout.Button("Leave"))
35 {
36 PhotonNetwork.LeaveRoom();
37 }
38 GUILayout.EndArea();
39 }
File name: HubGui.cs
Copy
28 void OnGUI()
29 {
30 GUI.skin = this.Skin;
31 GUILayout.Space(10);
32
33 GUILayout.BeginHorizontal();
34 GUILayout.Space(10);
35 scrollPos = GUILayout.BeginScrollView(scrollPos, GUILayout.Width(320));
36
37 GUILayout.Label("Basics", m_Headline);
38 if (GUILayout.Button("Demo Boxes", GUILayout.Width(280)))
39 {
40 demoDescription = "
41 demoBtn = new DemoBtn() { Text = "Start", Link = "DemoBoxes-Scene" };
42 }
43 if (GUILayout.Button("Demo Worker", GUILayout.Width(280)))
44 {
45 demoDescription = "
46 demoBtn = new DemoBtn() { Text = "Start", Link = "DemoWorker-Scene" };
47 }
48 if (GUILayout.Button("Movement Smoothing", GUILayout.Width(280)))
49 {
50 demoDescription = "
51 demoBtn = new DemoBtn() { Text = "Start", Link = "DemoSynchronization-Scene" };
52 }
53
54 GUILayout.Label("Advanced", m_Headline);
55 if (GUILayout.Button("Ownership Transfer", GUILayout.Width(280)))
56 {
57 demoDescription = "
58 this.demoBtn = new DemoBtn() { Text = "Start", Link = "DemoChangeOwner-Scene" };
59 this.webLink = new DemoBtn();
60 }
61 if (GUILayout.Button("Pickup, Teams, Scores", GUILayout.Width(280)))
62 {
63 demoDescription = "
64 this.demoBtn = new DemoBtn() { Text = "Start", Link = "DemoPickup-Scene" };
65 this.webLink = new DemoBtn();
66 }
67
68 GUILayout.Label("Feature Demos", m_Headline);
69 if (GUILayout.Button("Chat", GUILayout.Width(280)))
70 {
71 demoDescription = "
72 this.demoBtn = new DemoBtn() { Text = "Start", Link = "DemoChat-Scene" };
73 this.webLink = new DemoBtn();
74 }
75 if (GUILayout.Button("RPG Movement", GUILayout.Width(280)))
76 {
77 demoDescription = "
78 this.demoBtn = new DemoBtn() { Text = "Start", Link = "DemoRPGMovement-Scene" };
79 this.webLink = new DemoBtn();
80 }
81 if (GUILayout.Button("Mecanim Animations", GUILayout.Width(280)))
82 {
83 demoDescription = "
84 this.demoBtn = new DemoBtn() { Text = "Start", Link = "DemoMecanim-Scene" };
85 this.webLink = new DemoBtn();
86 }
87 if (GUILayout.Button("2D Game", GUILayout.Width(280)))
88 {
89 demoDescription = "
90 this.demoBtn = new DemoBtn() { Text = "Start", Link = "Demo2DJumpAndRunWithPhysics-Scene" };
91 this.webLink = new DemoBtn();
92 }
93 if (GUILayout.Button("Friends & Authentication", GUILayout.Width(280)))
94 {
95 demoDescription = "
96 this.demoBtn = new DemoBtn() { Text = "Start", Link = "DemoFriends-Scene" };
97 this.webLink = new DemoBtn();
98 }
99
100 GUILayout.Label("Tutorial", m_Headline);
101 if (GUILayout.Button("Marco Polo Tutorial", GUILayout.Width(280)))
102 {
103 demoDescription = "
104 this.demoBtn = new DemoBtn() { Text = "Start", Link = "MarcoPolo-Scene" };
105 this.webLink = new DemoBtn() { Text = "Open Tutorial (www)", Link = "http://tinyurl.com/nmylf44" };
106 }
107 GUILayout.EndScrollView();
108
109 GUILayout.BeginVertical(GUILayout.Width(Screen.width - 345));
110 GUILayout.Label(demoDescription);
111 GUILayout.Space(10);
112 if (!string.IsNullOrEmpty(this.demoBtn.Text))
113 {
114 if (GUILayout.Button(this.demoBtn.Text))
115 {
116 Application.LoadLevel(this.demoBtn.Link);
117 }
118 }
119 if (!string.IsNullOrEmpty(this.webLink.Text))
120 {
121 if (GUILayout.Button(this.webLink.Text))
122 {
123 Application.OpenURL(this.webLink.Link);
124 }
125 }
126 GUILayout.EndVertical();
127
128
129 GUILayout.EndHorizontal();
130 }
File name: PhotonAnimatorViewEditor.cs
Copy
157 private void CheckIfStoredParametersExist()
158 {
159 for (int i = 0; i < this.m_Target.GetSynchronizedParameters().Count; ++i)
160 {
161 string parameterName = this.m_Target.GetSynchronizedParameters()[i].Name;
162 if (DoesParameterExist(parameterName) == false)
163 {
164 Debug.LogWarning("Parameter '" + this.m_Target.GetSynchronizedParameters()[i].Name +
165 "' doesn't exist anymore. Removing it from the list of synchronized parameters");
166 int numberOfRemovedElements = this.m_Target.GetSynchronizedParameters().RemoveAll(item => item.Name == parameterName);
167 EditorUtility.SetDirty(this.m_Target);
168
169 i -= numberOfRemovedElements;
170
171 if (i < 0)
172 {
173 break;
174 }
175 }
176 }
177 }
File name: PhotonTransformViewEditor.cs
Copy
203 private void DrawHelpBox(ref Rect propertyRect, bool isOpen, float height, string helpText, string url)
204 {
205 if (isOpen == true)
206 {
207 Rect helpRect = new Rect(propertyRect.xMin, propertyRect.yMin, propertyRect.width, height - 5);
208 GUI.BeginGroup(helpRect, GUI.skin.box);
209 GUI.Label(new Rect(5, 5, propertyRect.width - 10, height - 30), helpText, PhotonGUI.RichLabel);
210 if (GUI.Button(new Rect(5, height - 30, propertyRect.width - 10, 20), "Read more in our documentation"))
211 {
212 Application.OpenURL(url);
213 }
214 GUI.EndGroup();
215
216 propertyRect.y += height;
217 }
218 }
File name: PhotonEditor.cs
Copy
886 public static void ReLoadCurrentSettings()
887 {
888 // this now warns developers if there are more than one settings files in resources folders. first will be used.
889 UnityEngine.Object[] settingFiles = Resources.LoadAll(PhotonNetwork.serverSettingsAssetFile, typeof(ServerSettings));
890 if (settingFiles != null && settingFiles.Length > 0)
891 {
892 PhotonEditor.Current = (ServerSettings)settingFiles[0];
893
894 if (settingFiles.Length > 1)
895 {
896 Debug.LogWarning(CurrentLang.MoreThanOneLabel + PhotonNetwork.serverSettingsAssetFile + CurrentLang.FilesInResourceFolderLabel + AssetDatabase.GetAssetPath(PhotonEditor.Current));
897 }
898 }
899 }
File name: PhotonNetwork.cs
Copy
674 {
675 get
676 {
677 return 1000 / sendIntervalOnSerialize;
678 }
679
680 set
681 {
682 if (value > sendRate)
683 {
684 Debug.LogError("Error, can not set the OnSerialize SendRate more often then the overall SendRate");
685 value = sendRate;
686 }
687
688 sendIntervalOnSerialize = 1000 / value;
689 if (photonMono != null)
690 {
691 photonMono.updateIntervalOnSerialize = sendIntervalOnSerialize;
692 }
693 }
694 }
File name: PhotonPlayer.cs
Copy
241 public PhotonPlayer GetNextFor(int currentPlayerId)
242 {
243 if (PhotonNetwork.networkingPeer == null || PhotonNetwork.networkingPeer.mActors == null || PhotonNetwork.networkingPeer.mActors.Count < 2)
244 {
245 return null;
246 }
247
248 Dictionary
249 int nextHigherId = int.MaxValue; // we look for the next higher ID
250 int lowestId = currentPlayerId; // if we are the player with the highest ID, there is no higher and we return to the lowest player's id
251
252 foreach (int playerid in players.Keys)
253 {
254 if (playerid < lowestId)
255 {
256 lowestId = playerid; // less than any other ID (which must be at least less than this player's id).
257 }
258 else if (playerid > currentPlayerId && playerid < nextHigherId)
259 {
260 nextHigherId = playerid; // more than our ID and less than those found so far.
261 }
262 }
263
264 //UnityEngine.Debug.LogWarning("Debug. " + currentPlayerId + " lower: " + lowestId + " higher: " + nextHigherId + " ");
265 //UnityEngine.Debug.LogWarning(this.RoomReference.GetPlayer(currentPlayerId));
266 //UnityEngine.Debug.LogWarning(this.RoomReference.GetPlayer(lowestId));
267 //if (nextHigherId != int.MaxValue) UnityEngine.Debug.LogWarning(this.RoomReference.GetPlayer(nextHigherId));
268 return (nextHigherId != int.MaxValue) ? players[nextHigherId] : players[lowestId];
269 }
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 }
File name: ChatClient.cs
Copy
768 private void HandleAuthResponse(OperationResponse operationResponse)
769 {
770 ((IPhotonPeerListener)this).DebugReturn(DebugLevel.INFO, operationResponse.ToStringFull() + " on: " + this.NameServerAddress);
771 if (operationResponse.ReturnCode == 0)
772 {
773 if (this.State == ChatState.ConnectedToNameServer)
774 {
775 this.State = ChatState.Authenticated;
776 this.listener.OnChatStateChange(this.State);
777
778 if (operationResponse.Parameters.ContainsKey(ParameterCode.Secret))
779 {
780 if (this.CustomAuthenticationValues == null)
781 {
782 this.CustomAuthenticationValues = new AuthenticationValues();
783 }
784 this.CustomAuthenticationValues.Secret = operationResponse[ParameterCode.Secret] as string;
785 this.FrontendAddress = (string) operationResponse[ParameterCode.Address];
786
787 // we disconnect and status handler starts to connect to front end
788 this.chatPeer.Disconnect();
789 }
790 else
791 {
792 //TODO: error reaction!
793 }
794 }
795 else if (this.State == ChatState.ConnectingToFrontEnd)
796 {
797 this.msDeltaForServiceCalls = this.msDeltaForServiceCalls * 4; // when we arrived on chat server: limit Service calls some more
798
799 this.State = ChatState.ConnectedToFrontEnd;
800 this.listener.OnChatStateChange(this.State);
801 this.listener.OnConnected();
802 }
803 }
804 else
805 {
806 //((IPhotonPeerListener)this).DebugReturn(DebugLevel.INFO, operationResponse.ToStringFull() + " NS: " + this.NameServerAddress + " FrontEnd: " + this.frontEndAddress);
807
808 switch (operationResponse.ReturnCode)
809 {
810 case ErrorCode.InvalidAuthentication:
811 this.DisconnectedCause = ChatDisconnectCause.InvalidAuthentication;
812 break;
813 case ErrorCode.CustomAuthenticationFailed:
814 this.DisconnectedCause = ChatDisconnectCause.CustomAuthenticationFailed;
815 break;
816 case ErrorCode.InvalidRegion:
817 this.DisconnectedCause = ChatDisconnectCause.InvalidRegion;
818 break;
819 case ErrorCode.MaxCcuReached:
820 this.DisconnectedCause = ChatDisconnectCause.MaxCcuReached;
821 break;
822 case ErrorCode.OperationNotAllowedInCurrentState:
823 this.DisconnectedCause = ChatDisconnectCause.OperationNotAllowedInCurrentState;
824 break;
825 }
826
827 this.State = ChatState.Disconnecting;
828 this.chatPeer.Disconnect();
829 }
830 }
Download file with original file name:MORE
MORE 114 lượt xem
Gõ tìm kiếm nhanh...