DisplayDialog









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

Featured Snippets


File name: PhotonConverter.cs Copy
18     public static void RunConversion()
19     {
20         //Ask if user has made a backup.
21         int option = EditorUtility.DisplayDialogComplex("Conversion", "Attempt automatic conversion from Unity Networking to Photon Unity Networking \"PUN\"?", "Yes", "No!", "Pick Script Folder");
22         switch (option)
23         {
24             case 0:
25                 break;
26             case 1:
27                 return;
28             case 2:
29                 PickFolderAndConvertScripts();
30                 return;
31             default:
32                 return;
33         }
34
35         //REAAAALY?
36         bool result = EditorUtility.DisplayDialog("Conversion", "Disclaimer: The code conversion feature is quite crude, but should do it's job well (see the sourcecode). A backup is therefore strongly recommended!", "Yes, I've made a backup: GO", "Abort");
37         if (!result)
38         {
39             return;
40         }
41         Output(EditorApplication.timeSinceStartup + " Started conversion of Unity networking -> Photon");
42
43         //Ask to save current scene (optional)
44         EditorApplication.SaveCurrentSceneIfUserWantsTo();
45
46         EditorUtility.DisplayProgressBar("Converting..", "Starting.", 0);
47
48         //Convert NetworkViews to PhotonViews in Project prefabs
49         //Ask the user if we can move all prefabs to a resources folder
50         bool movePrefabs = EditorUtility.DisplayDialog("Conversion", "Can all prefabs that use a PhotonView be moved to a Resources/ folder? You need this if you use Network.Instantiate.", "Yes", "No");
51
52
53         string[] prefabs = Directory.GetFiles("Assets/", "*.prefab", SearchOption.AllDirectories);
54         foreach (string prefab in prefabs)
55         {
56             EditorUtility.DisplayProgressBar("Converting..", "Object:" + prefab, 0.6f);
57
58             Object[] objs = (Object[])AssetDatabase.LoadAllAssetsAtPath(prefab);
59             int converted = 0;
60             foreach (Object obj in objs)
61             {
62                 if (obj != null && obj.GetType() == typeof(GameObject))
63                     converted += ConvertNetworkView(((GameObject)obj).GetComponents(), false);
64             }
65             if (movePrefabs && converted > 0)
66             {
67                 //This prefab needs to be under the root of a Resources folder!
68                 string path = prefab.Replace("\\", "/");
69                 int lastSlash = path.LastIndexOf("/");
70                 int resourcesIndex = path.LastIndexOf("/Resources/");
71                 if (resourcesIndex != lastSlash - 10)
72                 {
73                     if (path.Contains("/Resources/"))
74                     {
75                         Debug.LogWarning("Warning, prefab [" + prefab + "] was already in a resources folder. But has been placed in the root of another one!");
76                     }
77                     //This prefab NEEDS to be placed under a resources folder
78                     string resourcesFolder = path.Substring(0, lastSlash) + "/Resources/";
79                     EnsureFolder(resourcesFolder);
80                     string newPath = resourcesFolder + path.Substring(lastSlash + 1);
81                     string error = AssetDatabase.MoveAsset(prefab, newPath);
82                     if (error != "")
83                         Debug.LogError(error);
84                     Output("Fixed prefab [" + prefab + "] by moving it into a resources folder.");
85                 }
86             }
87         }
88
89         //Convert NetworkViews to PhotonViews in scenes
90         string[] sceneFiles = Directory.GetFiles("Assets/", "*.unity", SearchOption.AllDirectories);
91         foreach (string sceneName in sceneFiles)
92         {
93             EditorApplication.OpenScene(sceneName);
94             EditorUtility.DisplayProgressBar("Converting..", "Scene:" + sceneName, 0.2f);
95
96             int converted2 = ConvertNetworkView((NetworkView[])GameObject.FindObjectsOfType(typeof(NetworkView)), true);
97             if (converted2 > 0)
98             {
99                 //This will correct all prefabs: The prefabs have gotten new components, but the correct ID's were lost in this case
100                 PhotonViewHandler.HierarchyChange(); //TODO: most likely this is triggered on change or on save
101
102                 Output("Replaced " + converted2 + " NetworkViews with PhotonViews in scene: " + sceneName);
103                 EditorApplication.SaveScene(EditorApplication.currentScene);
104             }
105
106         }
107
108         //Convert C#/JS scripts (API stuff)
109         List scripts = GetScriptsInFolder("Assets");
110
111         EditorUtility.DisplayProgressBar("Converting..", "Scripts..", 0.9f);
112         ConvertScripts(scripts);
113
114         Output(EditorApplication.timeSinceStartup + " Completed conversion!");
115         EditorUtility.ClearProgressBar();
116
117         EditorUtility.DisplayDialog("Completed the conversion", "Don't forget to add \"PhotonNetwork.ConnectWithDefaultSettings();\" to connect to the Photon server before using any multiplayer functionality.", "OK");
118     }
File name: PhotonConverter.cs Copy
120     public static void PickFolderAndConvertScripts()
121     {
122         string folderPath = EditorUtility.OpenFolderPanel("Pick source folder to convert", Directory.GetCurrentDirectory(), "");
123         if (string.IsNullOrEmpty(folderPath))
124         {
125             EditorUtility.DisplayDialog("Script Conversion", "No folder was selected. No files were changed. Please start over.", "Ok.");
126             return;
127         }
128
129         bool result = EditorUtility.DisplayDialog("Script Conversion", "Scripts in this folder will be modified:\n\n" + folderPath + "\n\nMake sure you have backups of these scripts.\nConversion is not guaranteed to work!", "Backup done. Go!", "Abort");
130         if (!result)
131         {
132             return;
133         }
134
135         List scripts = GetScriptsInFolder(folderPath);
136         ConvertScripts(scripts);
137
138         EditorUtility.DisplayDialog("Script Conversion", "Scripts are now converted to PUN.\n\nYou will need to update\n- scenes\n- components\n- prefabs and\n- add \"PhotonNetwork.ConnectWithDefaultSettings();\"", "Ok");
139     }
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
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     }
File name: PhotonEditor.cs Copy
909     public static void UpdateRpcList()
910     {
911         List additionalRpcs = new List();
912         HashSet currentRpcs = new HashSet();
913
914         var types = GetAllSubTypesInScripts(typeof(MonoBehaviour));
915
916         foreach (var mono in types)
917         {
918             MethodInfo[] methods = mono.GetMethods(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
919
920             foreach (MethodInfo method in methods)
921             {
922                 if (method.IsDefined(typeof(UnityEngine.RPC), false))
923                 {
924                     currentRpcs.Add(method.Name);
925
926                     if (!additionalRpcs.Contains(method.Name) && !PhotonEditor.Current.RpcList.Contains(method.Name))
927                     {
928                         additionalRpcs.Add(method.Name);
929                     }
930                 }
931             }
932         }
933
934         if (additionalRpcs.Count > 0)
935         {
936             // LIMITS RPC COUNT
937             if (additionalRpcs.Count + PhotonEditor.Current.RpcList.Count >= byte.MaxValue)
938             {
939                 if (currentRpcs.Count <= byte.MaxValue)
940                 {
941                     bool clearList = EditorUtility.DisplayDialog(CurrentLang.IncorrectRPCListTitle, CurrentLang.IncorrectRPCListLabel, CurrentLang.RemoveOutdatedRPCsLabel, CurrentLang.CancelButton);
942                     if (clearList)
943                     {
944                         PhotonEditor.Current.RpcList.Clear();
945                         PhotonEditor.Current.RpcList.AddRange(currentRpcs);
946                     }
947                     else
948                     {
949                         return;
950                     }
951                 }
952                 else
953                 {
954                     EditorUtility.DisplayDialog(CurrentLang.FullRPCListTitle, CurrentLang.FullRPCListLabel, CurrentLang.SkipRPCListUpdateLabel);
955                     return;
956                 }
957             }
958
959             additionalRpcs.Sort();
960             PhotonEditor.Current.RpcList.AddRange(additionalRpcs);
961             EditorUtility.SetDirty(PhotonEditor.Current);
962         }
963     }
File name: PhotonEditor.cs Copy
965     public static void ClearRpcList()
966     {
967         bool clearList = EditorUtility.DisplayDialog(CurrentLang.PUNNameReplaceTitle, CurrentLang.PUNNameReplaceLabel, CurrentLang.RPCListCleared, CurrentLang.CancelButton);
968         if (clearList)
969         {
970             PhotonEditor.Current.RpcList.Clear();
971             Debug.LogWarning(CurrentLang.ServerSettingsCleanedWarning);
972         }
973     }

DisplayDialog 123 lượt xem

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