Window









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

Featured Snippets


File name: frmLogin.cs Copy
53         private void frmLogin_Activated(object sender, EventArgs e)
54         {
55             this.WindowState = FormWindowState.Normal;
56         }
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
294     protected void InitPhotonSetupWindow()
295     {
296         this.minSize = MinSize;
297
298         this.SwitchMenuState(GUIState.Setup);
299         this.ReApplySettingsToWindow();
300
301         switch (PhotonEditor.Current.HostType)
302         {
303             case ServerSettings.HostingOption.PhotonCloud:
304             case ServerSettings.HostingOption.BestRegion:
305                 this.photonSetupState = PhotonSetupStates.SetupPhotonCloud;
306                 break;
307             case ServerSettings.HostingOption.SelfHosted:
308                 this.photonSetupState = PhotonSetupStates.SetupSelfHosted;
309                 break;
310             case ServerSettings.HostingOption.NotSet:
311             default:
312                 this.photonSetupState = PhotonSetupStates.RegisterForPhotonCloud;
313                 break;
314         }
315     }
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
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     }
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: PhotonEditor.cs Copy
727     protected virtual void OnGuiSetupSelfhosting()
728     {
729         GUILayout.Label(CurrentLang.YourPhotonServerLabel);
730
731         this.photonAddress = EditorGUILayout.TextField(CurrentLang.AddressIPLabel, this.photonAddress);
732         this.photonPort = EditorGUILayout.IntField(CurrentLang.PortLabel, this.photonPort);
733         this.photonProtocol = (ConnectionProtocol)EditorGUILayout.EnumPopup("Protocol", this.photonProtocol);
734         EditorGUILayout.Separator();
735
736         GUILayout.BeginHorizontal();
737         if (GUILayout.Button(CurrentLang.CancelButton))
738         {
739             GUIUtility.keyboardControl = 0;
740             this.ReApplySettingsToWindow();
741         }
742
743         if (GUILayout.Button(CurrentLang.SaveButton))
744         {
745             GUIUtility.keyboardControl = 0;
746
747             PhotonEditor.Current.UseMyServer(this.photonAddress, this.photonPort, null);
748             PhotonEditor.Current.Protocol = this.photonProtocol;
749             PhotonEditor.Save();
750
751             Inspect();
752             EditorUtility.DisplayDialog(CurrentLang.SettingsSavedTitle, CurrentLang.SettingsSavedMessage, CurrentLang.OkButton);
753         }
754
755         GUILayout.EndHorizontal();
756
757
758         GUILayout.Space(20);
759
760
761         // license
762         GUILayout.BeginHorizontal();
763         GUILayout.Label(CurrentLang.LicensesLabel, EditorStyles.boldLabel, GUILayout.Width(100));
764
765         if (GUILayout.Button(new GUIContent(CurrentLang.LicenseDownloadText, CurrentLang.LicenseDownloadTooltip)))
766         {
767             EditorUtility.OpenWithDefaultApp(UrlFreeLicense);
768         }
769
770         GUILayout.EndHorizontal();
771
772
773         GUILayout.Space(20);
774
775
776         GUILayout.Label(CurrentLang.TryPhotonAppLabel);
777
778         if (GUILayout.Button(CurrentLang.GetCloudAppButton))
779         {
780             this.cloudAppId = string.Empty;
781             this.photonSetupState = PhotonSetupStates.RegisterForPhotonCloud;
782         }
783
784         EditorGUILayout.Separator();
785         GUILayout.Label(CurrentLang.OwnHostCloudCompareLabel);
786         if (GUILayout.Button(CurrentLang.ComparisonPageButton))
787         {
788             Application.OpenURL(UrlCompare);
789         }
790     }
File name: PhotonEditor.cs Copy
792     protected virtual void RegisterWithEmail(string email)
793     {
794         EditorUtility.DisplayProgressBar(CurrentLang.ConnectionTitle, CurrentLang.ConnectionInfo, 0.5f);
795         var client = new AccountService();
796         client.RegisterByEmail(email, RegisterOrigin); // this is the synchronous variant using the static RegisterOrigin. "result" is in the client
797
798         EditorUtility.ClearProgressBar();
799         if (client.ReturnCode == 0)
800         {
801             PhotonEditor.Current.UseCloud(client.AppId, 0);
802             PhotonEditor.Save();
803             this.ReApplySettingsToWindow();
804             this.photonSetupState = PhotonSetupStates.SetupPhotonCloud;
805         }
806         else
807         {
808             if (client.Message.Contains(CurrentLang.EmailInUseLabel))
809             {
810                 this.photonSetupState = PhotonSetupStates.EmailAlreadyRegistered;
811             }
812             else
813             {
814                 EditorUtility.DisplayDialog(CurrentLang.ErrorTextTitle, client.Message, CurrentLang.OkButton);
815                 // Debug.Log(client.Exception);
816                 this.photonSetupState = PhotonSetupStates.RegisterForPhotonCloud;
817             }
818         }
819     }

Download file with original file name:Window

Window 122 lượt xem

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