Wizard
How do I use Wizard
Below are practical examples compiled from projects for learning and reference purposes
Featured Snippets
File name: WorkerMenu.cs
Copy
65 public void OnGUI()
66 {
67 if (this.Skin != null)
68 {
69 GUI.skin = this.Skin;
70 }
71
72 if (!PhotonNetwork.connected)
73 {
74 if (PhotonNetwork.connecting)
75 {
76 GUILayout.Label("Connecting to: " + PhotonNetwork.ServerAddress);
77 }
78 else
79 {
80 GUILayout.Label("Not connected. Check console output. Detailed connection state: " + PhotonNetwork.connectionStateDetailed + " Server: " + PhotonNetwork.ServerAddress);
81 }
82
83 if (this.connectFailed)
84 {
85 GUILayout.Label("Connection failed. Check setup and use Setup Wizard to fix configuration.");
86 GUILayout.Label(String.Format("Server: {0}", new object[] {PhotonNetwork.ServerAddress}));
87 GUILayout.Label("AppId: " + PhotonNetwork.PhotonServerSettings.AppID);
88
89 if (GUILayout.Button("Try Again", GUILayout.Width(100)))
90 {
91 this.connectFailed = false;
92 PhotonNetwork.ConnectUsingSettings("0.9");
93 }
94 }
95
96 return;
97 }
98
99 Rect content = new Rect((Screen.width - WidthAndHeight.x)/2, (Screen.height - WidthAndHeight.y)/2, WidthAndHeight.x, WidthAndHeight.y);
100 GUI.Box(content,"Join or Create Room");
101 GUILayout.BeginArea(content);
102
103 GUILayout.Space(40);
104
105 // Player name
106 GUILayout.BeginHorizontal();
107 GUILayout.Label("Player name:", GUILayout.Width(150));
108 PhotonNetwork.playerName = GUILayout.TextField(PhotonNetwork.playerName);
109 GUILayout.Space(158);
110 if (GUI.changed)
111 {
112 // Save name
113 PlayerPrefs.SetString("playerName", PhotonNetwork.playerName);
114 }
115 GUILayout.EndHorizontal();
116
117 GUILayout.Space(15);
118
119 // Join room by title
120 GUILayout.BeginHorizontal();
121 GUILayout.Label("Roomname:", GUILayout.Width(150));
122 this.roomName = GUILayout.TextField(this.roomName);
123
124 if (GUILayout.Button("Create Room", GUILayout.Width(150)))
125 {
126 PhotonNetwork.CreateRoom(this.roomName, new RoomOptions() { maxPlayers = 10 }, null);
127 }
128
129 GUILayout.EndHorizontal();
130
131 // Create a room (fails if exist!)
132 GUILayout.BeginHorizontal();
133 GUILayout.FlexibleSpace();
134 //this.roomName = GUILayout.TextField(this.roomName);
135 if (GUILayout.Button("Join Room", GUILayout.Width(150)))
136 {
137 PhotonNetwork.JoinRoom(this.roomName);
138 }
139
140 GUILayout.EndHorizontal();
141
142
143 if (!string.IsNullOrEmpty(this.ErrorDialog))
144 {
145 GUILayout.Label(this.ErrorDialog);
146
147 if (timeToClearDialog < Time.time)
148 {
149 timeToClearDialog = 0;
150 this.ErrorDialog = "";
151 }
152 }
153
154 GUILayout.Space(15);
155
156 // Join random room
157 GUILayout.BeginHorizontal();
158
159 GUILayout.Label(PhotonNetwork.countOfPlayers + " users are online in " + PhotonNetwork.countOfRooms + " rooms.");
160 GUILayout.FlexibleSpace();
161 if (GUILayout.Button("Join Random", GUILayout.Width(150)))
162 {
163 PhotonNetwork.JoinRandomRoom();
164 }
165
166
167 GUILayout.EndHorizontal();
168
169 GUILayout.Space(15);
170 if (PhotonNetwork.GetRoomList().Length == 0)
171 {
172 GUILayout.Label("Currently no games are available.");
173 GUILayout.Label("Rooms will be listed here, when they become available.");
174 }
175 else
176 {
177 GUILayout.Label(PhotonNetwork.GetRoomList().Length + " rooms available:");
178
179 // Room listing: simply call GetRoomList: no need to fetch/poll whatever!
180 this.scrollPos = GUILayout.BeginScrollView(this.scrollPos);
181 foreach (RoomInfo roomInfo in PhotonNetwork.GetRoomList())
182 {
183 GUILayout.BeginHorizontal();
184 GUILayout.Label(roomInfo.name + " " + roomInfo.playerCount + "/" + roomInfo.maxPlayers);
185 if (GUILayout.Button("Join", GUILayout.Width(150)))
186 {
187 PhotonNetwork.JoinRoom(roomInfo.name);
188 }
189
190 GUILayout.EndHorizontal();
191 }
192
193 GUILayout.EndScrollView();
194 }
195
196 GUILayout.EndArea();
197 }
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
276 protected static void Init()
277 {
278 PhotonEditor win = GetWindow(WindowType, false, CurrentLang.WindowTitle, true) as PhotonEditor;
279 win.InitPhotonSetupWindow();
280
281 win.isSetupWizard = false;
282 win.SwitchMenuState(GUIState.Main);
283 }
File name: PhotonEditor.cs
Copy
286 protected static void ShowRegistrationWizard()
287 {
288 PhotonEditor win = GetWindow(WindowType, false, CurrentLang.WindowTitle, true) as PhotonEditor;
289 win.isSetupWizard = true;
290 win.InitPhotonSetupWindow();
291 }
File name: PhotonEditor.cs
Copy
336 // called in editor, opens wizard for initial setup, keeps scene PhotonViews up to date and closes connections when compiling (to avoid issues)
337 private static void EditorUpdate()
338 {
339 if (dontCheckPunSetup || PhotonEditor.Current == null)
340 {
341 return;
342 }
343
344 // serverSetting is null when the file gets deleted. otherwise, the wizard should only run once and only if hosting option is not (yet) set
345 if (!PhotonEditor.Current.DisableAutoOpenWizard && PhotonEditor.Current.HostType == ServerSettings.HostingOption.NotSet)
346 {
347 ShowRegistrationWizard();
348 }
349
350 // Workaround for TCP crash. Plus this surpresses any other recompile errors.
351 if (EditorApplication.isCompiling)
352 {
353 if (PhotonNetwork.connected)
354 {
355 if (lastWarning > EditorApplication.timeSinceStartup - 3)
356 {
357 // Prevent error spam
358 Debug.LogWarning(CurrentLang.WarningPhotonDisconnect);
359 lastWarning = EditorApplication.timeSinceStartup;
360 }
361
362 PhotonNetwork.Disconnect();
363 }
364 }
365 }
File name: PhotonEditor.cs
Copy
367 // called in editor on change of play-mode (used to show a message popup that connection settings are incomplete)
368 private static void PlaymodeStateChanged()
369 {
370 if (dontCheckPunSetup || EditorApplication.isPlaying || !EditorApplication.isPlayingOrWillChangePlaymode)
371 {
372 return;
373 }
374
375 if (PhotonEditor.Current.HostType == ServerSettings.HostingOption.NotSet)
376 {
377 EditorUtility.DisplayDialog(CurrentLang.SetupWizardWarningTitle, CurrentLang.SetupWizardWarningMessage, CurrentLang.OkButton);
378 }
379 }
File name: PhotonEditor.cs
Copy
381 private void SwitchMenuState(GUIState newState)
382 {
383 this.guiState = newState;
384 if (this.isSetupWizard && newState != GUIState.Setup)
385 {
386 this.Close();
387 }
388 }
File name: PhotonEditor.cs
Copy
390 protected virtual void OnGUI()
391 {
392 PhotonSetupStates oldGuiState = this.photonSetupState; // used to fix an annoying Editor input field issue: wont refresh until focus is changed.
393
394 GUI.SetNextControlName("");
395 this.scrollPos = GUILayout.BeginScrollView(this.scrollPos);
396
397 if (this.guiState == GUIState.Uninitialized)
398 {
399 this.ReApplySettingsToWindow();
400 this.guiState = (PhotonEditor.Current.HostType == ServerSettings.HostingOption.NotSet) ? GUIState.Setup : GUIState.Main;
401 }
402
403 if (this.guiState == GUIState.Main)
404 {
405 this.OnGuiMainWizard();
406 }
407 else
408 {
409 this.OnGuiRegisterCloudApp();
410 }
411
412 GUILayout.EndScrollView();
413
414 if (oldGuiState != this.photonSetupState)
415 {
416 GUI.FocusControl("");
417 }
418 }
File name: PhotonEditor.cs
Copy
420 protected virtual void OnGuiRegisterCloudApp()
421 {
422 GUI.skin.label.wordWrap = true;
423 if (!this.isSetupWizard)
424 {
425 GUILayout.BeginHorizontal();
426 GUILayout.FlexibleSpace();
427 if (GUILayout.Button(CurrentLang.MainMenuButton, GUILayout.ExpandWidth(false)))
428 {
429 this.SwitchMenuState(GUIState.Main);
430 }
431
432 GUILayout.EndHorizontal();
433
434 GUILayout.Space(15);
435 }
436
437 if (this.photonSetupState == PhotonSetupStates.RegisterForPhotonCloud)
438 {
439 GUI.skin.label.fontStyle = FontStyle.Bold;
440 GUILayout.Label(CurrentLang.ConnectButton);
441 EditorGUILayout.Separator();
442 GUI.skin.label.fontStyle = FontStyle.Normal;
443
444 GUILayout.Label(CurrentLang.UsePhotonLabel);
445 EditorGUILayout.Separator();
446 this.emailAddress = EditorGUILayout.TextField(CurrentLang.EmailLabel, this.emailAddress);
447
448 if (GUILayout.Button(CurrentLang.SendButton))
449 {
450 GUIUtility.keyboardControl = 0;
451 this.RegisterWithEmail(this.emailAddress);
452 }
453
454 GUILayout.Space(20);
455
456
457 GUILayout.Label(CurrentLang.SignedUpAlreadyLabel);
458 if (GUILayout.Button(CurrentLang.SetupButton))
459 {
460 this.photonSetupState = PhotonSetupStates.SetupPhotonCloud;
461 }
462 EditorGUILayout.Separator();
463
464
465 GUILayout.Label(CurrentLang.RegisterByWebsiteLabel);
466 if (GUILayout.Button(CurrentLang.AccountWebsiteButton))
467 {
468 EditorUtility.OpenWithDefaultApp(UrlAccountPage + Uri.EscapeUriString(this.emailAddress));
469 }
470
471 EditorGUILayout.Separator();
472
473 GUILayout.Label(CurrentLang.SelfHostLabel);
474
475 if (GUILayout.Button(CurrentLang.SelfHostSettingsButton))
476 {
477 this.photonSetupState = PhotonSetupStates.SetupSelfHosted;
478 }
479
480 GUILayout.FlexibleSpace();
481
482
483 if (!InternalEditorUtility.HasAdvancedLicenseOnBuildTarget(BuildTarget.Android) || !InternalEditorUtility.HasAdvancedLicenseOnBuildTarget(BuildTarget.iOS))
484 {
485 GUILayout.Label(CurrentLang.MobileExportNoteLabel);
486 }
487 EditorGUILayout.Separator();
488 }
489 else if (this.photonSetupState == PhotonSetupStates.EmailAlreadyRegistered)
490 {
491 GUI.skin.label.fontStyle = FontStyle.Bold;
492 GUILayout.Label(CurrentLang.OopsLabel);
493 GUI.skin.label.fontStyle = FontStyle.Normal;
494
495 GUILayout.Label(CurrentLang.EmailInUseLabel);
496
497 if (GUILayout.Button(CurrentLang.SeeMyAccountPageButton))
498 {
499 EditorUtility.OpenWithDefaultApp(UrlCloudDashboard + Uri.EscapeUriString(this.emailAddress));
500 }
501
502 EditorGUILayout.Separator();
503
504 GUILayout.Label(CurrentLang.KnownAppIdLabel);
505 GUILayout.BeginHorizontal();
506 if (GUILayout.Button(CurrentLang.CancelButton))
507 {
508 this.photonSetupState = PhotonSetupStates.RegisterForPhotonCloud;
509 }
510
511 if (GUILayout.Button(CurrentLang.SetupButton))
512 {
513 this.photonSetupState = PhotonSetupStates.SetupPhotonCloud;
514 }
515
516 GUILayout.EndHorizontal();
517 }
518 else if (this.photonSetupState == PhotonSetupStates.SetupPhotonCloud)
519 {
520 // cloud setup
521 GUI.skin.label.fontStyle = FontStyle.Bold;
522 GUILayout.Label(CurrentLang.PhotonCloudConnect);
523 GUI.skin.label.fontStyle = FontStyle.Normal;
524
525 EditorGUILayout.Separator();
526 this.OnGuiSetupCloudAppId();
527 this.OnGuiCompareAndHelpOptions();
528 }
529 else if (this.photonSetupState == PhotonSetupStates.SetupSelfHosted)
530 {
531 // self-hosting setup
532 GUI.skin.label.fontStyle = FontStyle.Bold;
533 GUILayout.Label(CurrentLang.SetupOwnHostLabel);
534 GUI.skin.label.fontStyle = FontStyle.Normal;
535
536 EditorGUILayout.Separator();
537
538 this.OnGuiSetupSelfhosting();
539 this.OnGuiCompareAndHelpOptions();
540 }
541 }
File name: PhotonEditor.cs
Copy
543 protected virtual void OnGuiMainWizard()
544 {
545 GUILayout.BeginHorizontal();
546 GUILayout.FlexibleSpace();
547 GUILayout.Label(WizardIcon);
548 GUILayout.FlexibleSpace();
549 GUILayout.EndHorizontal();
550
551 EditorGUILayout.Separator();
552
553 GUILayout.Label(CurrentLang.PUNWizardLabel, EditorStyles.boldLabel);
554 if (isPunPlus)
555 {
556 GUILayout.Label(CurrentLang.MobilePunPlusExportNoteLabel);
557 }
558 else if (!InternalEditorUtility.HasAdvancedLicenseOnBuildTarget(BuildTarget.Android) || !InternalEditorUtility.HasAdvancedLicenseOnBuildTarget(BuildTarget.iOS))
559 {
560 GUILayout.Label(CurrentLang.MobileExportNoteLabel);
561 }
562 EditorGUILayout.Separator();
563
564
565 // settings button
566 GUILayout.BeginHorizontal();
567 GUILayout.Label(CurrentLang.SettingsButton, EditorStyles.boldLabel, GUILayout.Width(100));
568 if (GUILayout.Button(new GUIContent(CurrentLang.SetupButton, CurrentLang.SetupServerCloudLabel)))
569 {
570 this.InitPhotonSetupWindow();
571 }
572
573 GUILayout.EndHorizontal();
574 EditorGUILayout.Separator();
575
576
577 // find / select settings asset
578 GUILayout.BeginHorizontal();
579 GUILayout.Label(CurrentLang.SettingsFileLabel, EditorStyles.boldLabel, GUILayout.Width(100));
580 if (GUILayout.Button(new GUIContent(CurrentLang.LocateSettingsButton, CurrentLang.SettingsHighlightLabel)))
581 {
582 EditorGUIUtility.PingObject(PhotonEditor.Current);
583 }
584
585 GUILayout.EndHorizontal();
586
587
588 GUILayout.FlexibleSpace();
589
590 // converter
591 GUILayout.BeginHorizontal();
592 GUILayout.Label(CurrentLang.ConverterLabel, EditorStyles.boldLabel, GUILayout.Width(100));
593 if (GUILayout.Button(new GUIContent(CurrentLang.StartButton, CurrentLang.UNtoPUNLabel)))
594 {
595 PhotonConverter.RunConversion();
596 }
597
598 GUILayout.EndHorizontal();
599 EditorGUILayout.Separator();
600
601
602 // documentation
603 GUILayout.BeginHorizontal();
604 GUILayout.Label(CurrentLang.DocumentationLabel, EditorStyles.boldLabel, GUILayout.Width(100));
605 GUILayout.BeginVertical();
606 if (GUILayout.Button(new GUIContent(CurrentLang.OpenPDFText, CurrentLang.OpenPDFTooltip)))
607 {
608 EditorUtility.OpenWithDefaultApp(DocumentationLocation);
609 }
610
611 if (GUILayout.Button(new GUIContent(CurrentLang.OpenDevNetText, CurrentLang.OpenDevNetTooltip)))
612 {
613 EditorUtility.OpenWithDefaultApp(UrlDevNet);
614 }
615
616 if (GUILayout.Button(new GUIContent(CurrentLang.OpenCloudDashboardText, CurrentLang.OpenCloudDashboardTooltip)))
617 {
618 EditorUtility.OpenWithDefaultApp(UrlCloudDashboard + Uri.EscapeUriString(this.emailAddress));
619 }
620
621 if (GUILayout.Button(new GUIContent(CurrentLang.OpenForumText, CurrentLang.OpenForumTooltip)))
622 {
623 EditorUtility.OpenWithDefaultApp(UrlForum);
624 }
625
626 GUILayout.EndVertical();
627 GUILayout.EndHorizontal();
628 }
Wizard 153 lượt xem
Gõ tìm kiếm nhanh...