Names
How do I use Names
Below are practical examples compiled from projects for learning and reference purposes
Featured Snippets
File name: PlayerVariables.cs
Copy
6 private static string[] playerColorNames = new string[] {"yellow", "red", "green", "cyan"};
File name: PlayerVariables.cs
Copy
18 public static string GetColorName(int playerId)
19 {
20 if (playerId <= 0)
21 {
22 return "none";
23 }
24 return playerColorNames[playerId%playerColors.Length];
25 }
File name: PhotonTransformViewEditor.cs
Copy
220 private void DrawPropertyWithHelpIcon(ref Rect propertyRect, ref bool isHelpOpen, SerializedProperty property, string tooltip)
221 {
222 Rect propertyFieldRect = new Rect(propertyRect.xMin, propertyRect.yMin, propertyRect.width - 20, propertyRect.height);
223 string propertyName = ObjectNames.NicifyVariableName(property.name);
224 EditorGUI.PropertyField(propertyFieldRect, property, new GUIContent(propertyName, tooltip));
225
226 Rect helpIconRect = new Rect(propertyFieldRect.xMax + 5, propertyFieldRect.yMin, 20, propertyFieldRect.height);
227 isHelpOpen = GUI.Toggle(helpIconRect, isHelpOpen, PhotonGUI.HelpIcon, GUIStyle.none);
228
229 propertyRect.y += EDITOR_LINE_HEIGHT;
230 }
File name: PhotonEditor.cs
Copy
215 static PhotonEditor()
216 {
217 EditorApplication.projectWindowChanged += EditorUpdate;
218 EditorApplication.hierarchyWindowChanged += EditorUpdate;
219 EditorApplication.playmodeStateChanged += PlaymodeStateChanged;
220 EditorApplication.update += OnUpdate;
221
222 WizardIcon = AssetDatabase.LoadAssetAtPath("Assets/Photon Unity Networking/photoncloud-icon.png", typeof(Texture2D)) as Texture2D;
223
224 // to be used in toolbar, the enum needs conversion to string[] being done here, once.
225 Array enumValues = Enum.GetValues(typeof(CloudRegionCode));
226 CloudServerRegionNames = new string[enumValues.Length];
227 for (int i = 0; i < CloudServerRegionNames.Length; i++)
228 {
229 CloudServerRegionNames[i] = enumValues.GetValue(i).ToString();
230 if (CloudServerRegionNames[i].Equals("none"))
231 {
232 CloudServerRegionNames[i] = PhotonEditor.CurrentLang.BestRegionLabel;
233 }
234 }
235
236 // detect optional packages
237 PhotonEditor.CheckPunPlus();
238
239 }
File name: PhotonEditor.cs
Copy
649 protected virtual void OnGuiSetupCloudAppId()
650 {
651 GUILayout.Label(CurrentLang.AppIdLabel);
652
653 GUILayout.BeginHorizontal();
654 this.cloudAppId = EditorGUILayout.TextField(this.cloudAppId);
655
656 open = GUILayout.Toggle(open, PhotonGUI.HelpIcon, GUIStyle.none, GUILayout.ExpandWidth(false));
657
658 GUILayout.EndHorizontal();
659
660 if (open) GUILayout.Label(CurrentLang.AppIdInfoLabel);
661
662
663
664 EditorGUILayout.Separator();
665
666 GUILayout.Label(CurrentLang.CloudRegionLabel);
667
668 GUILayout.BeginHorizontal();
669 int toolbarValue = GUILayout.Toolbar((int)selectedRegion, CloudServerRegionNames); // the enum CloudRegionCode is converted into a string[] in init (toolbar can't use enum)
670 helpRegion = GUILayout.Toggle( helpRegion, PhotonGUI.HelpIcon, GUIStyle.none, GUILayout.ExpandWidth( false ) );
671 GUILayout.EndHorizontal();
672
673
674 if (helpRegion) GUILayout.Label(CurrentLang.RegionalServersInfo);
675 PhotonEditor.selectedRegion = (CloudRegionCode)toolbarValue;
676
677 EditorGUILayout.Separator();
678
679 GUILayout.BeginHorizontal();
680 if (GUILayout.Button(CurrentLang.CancelButton))
681 {
682 GUIUtility.keyboardControl = 0;
683 this.ReApplySettingsToWindow();
684 }
685
686
687
688 if (GUILayout.Button(CurrentLang.SaveButton))
689 {
690 GUIUtility.keyboardControl = 0;
691 this.cloudAppId = this.cloudAppId.Trim();
692 PhotonEditor.Current.UseCloud(this.cloudAppId);
693
694 PhotonEditor.Current.PreferredRegion = PhotonEditor.selectedRegion;
695 PhotonEditor.Current.HostType = (PhotonEditor.Current.PreferredRegion == CloudRegionCode.none)
696 ? ServerSettings.HostingOption.BestRegion
697 : ServerSettings.HostingOption.PhotonCloud;
698 PhotonEditor.Save();
699
700 Inspect();
701 EditorUtility.DisplayDialog(CurrentLang.SettingsSavedTitle, CurrentLang.SettingsSavedMessage, CurrentLang.OkButton);
702 }
703
704 GUILayout.EndHorizontal();
705
706
707
708 GUILayout.Space(20);
709
710 GUILayout.Label(CurrentLang.SetupOwnServerLabel);
711
712 if (GUILayout.Button(CurrentLang.SelfHostSettingsButton))
713 {
714 //this.photonAddress = ServerSettings.DefaultServerAddress;
715 //this.photonPort = ServerSettings.DefaultMasterPort;
716 this.photonSetupState = PhotonSetupStates.SetupSelfHosted;
717 }
718
719 EditorGUILayout.Separator();
720 GUILayout.Label(CurrentLang.OwnHostCloudCompareLabel);
721 if (GUILayout.Button(CurrentLang.ComparisonPageButton))
722 {
723 Application.OpenURL(UrlCompare);
724 }
725 }
File name: NetworkingPeer.cs
Copy
157 public bool IsUsingNameServer { get; protected internal set; }
File name: NetworkingPeer.cs
Copy
163 private static readonly Dictionary
File name: NetworkingPeer.cs
Copy
253 public bool Connect(string serverAddress, ServerConnection type)
254 {
255 if (PhotonHandler.AppQuits)
256 {
257 Debug.LogWarning("Ignoring Connect() because app gets closed. If this is an error, check PhotonHandler.AppQuits.");
258 return false;
259 }
260
261 if (PhotonNetwork.connectionStateDetailed == global::PeerState.Disconnecting)
262 {
263 Debug.LogError("Connect() failed. Can't connect while disconnecting (still). Current state: " + PhotonNetwork.connectionStateDetailed);
264 return false;
265 }
266
267 // connect might fail, if the DNS name can't be resolved or if no network connection is available
268 bool connecting = base.Connect(serverAddress, "");
269 if (connecting)
270 {
271 switch (type)
272 {
273 case ServerConnection.NameServer:
274 State = global::PeerState.ConnectingToNameServer;
275 break;
276 case ServerConnection.MasterServer:
277 State = global::PeerState.ConnectingToMasterserver;
278 break;
279 case ServerConnection.GameServer:
280 State = global::PeerState.ConnectingToGameserver;
281 break;
282 }
283 }
284
285 return connecting;
286 }
File name: NetworkingPeer.cs
Copy
294 public bool ConnectToNameServer()
295 {
296 if (PhotonHandler.AppQuits)
297 {
298 Debug.LogWarning("Ignoring Connect() because app gets closed. If this is an error, check PhotonHandler.AppQuits.");
299 return false;
300 }
301
302 IsUsingNameServer = true;
303 this.CloudRegion = CloudRegionCode.none;
304
305 if (this.State == global::PeerState.ConnectedToNameServer)
306 {
307 return true;
308 }
309
310 #if RHTTP
311 string address = (this.UsedProtocol == ConnectionProtocol.RHttp) ? this.NameServerAddressHttp : this.NameServerAddress;
312 #else
313 string address = this.NameServerAddress;
314 #endif
315
316 if (!address.Contains(":"))
317 {
318 int port = 0;
319 ProtocolToNameServerPort.TryGetValue(this.UsedProtocol, out port);
320 address = string.Format("{0}:{1}", address, port);
321 Debug.Log("Server to connect to: " + address + " settings protocol: " + PhotonNetwork.PhotonServerSettings.Protocol);
322 }
323 if (!base.Connect(address, "ns"))
324 {
325 return false;
326 }
327
328 this.State = global::PeerState.ConnectingToNameServer;
329 return true;
330 }
File name: NetworkingPeer.cs
Copy
336 public bool ConnectToRegionMaster(CloudRegionCode region)
337 {
338 if (PhotonHandler.AppQuits)
339 {
340 Debug.LogWarning("Ignoring Connect() because app gets closed. If this is an error, check PhotonHandler.AppQuits.");
341 return false;
342 }
343
344 IsUsingNameServer = true;
345 this.CloudRegion = region;
346
347 if (this.State == global::PeerState.ConnectedToNameServer)
348 {
349 return this.OpAuthenticate(this.mAppId, this.mAppVersionPun, this.PlayerName, this.CustomAuthenticationValues, region.ToString());
350 }
351
352 #if RHTTP
353 string address = (this.UsedProtocol == ConnectionProtocol.RHttp) ? this.NameServerAddressHttp : this.NameServerAddress;
354 #else
355 string address = this.NameServerAddress;
356 #endif
357
358 if (!address.Contains(":"))
359 {
360 int port = 0;
361 ProtocolToNameServerPort.TryGetValue(this.UsedProtocol, out port);
362 address = string.Format("{0}:{1}", address, port);
363 //Debug.Log("Server to connect to: "+ address + " settings protocol: " + PhotonNetwork.PhotonServerSettings.Protocol);
364 }
365 if (!base.Connect(address, "ns"))
366 {
367 return false;
368 }
369
370 this.State = global::PeerState.ConnectingToNameServer;
371 return true;
372 }
Names 157 lượt xem
Gõ tìm kiếm nhanh...