Search Unity

How does EditorUtility.DisplayDialog pause the editor?

Discussion in 'Editor & General Support' started by MattDahEpic, Jun 26, 2017.

  1. MattDahEpic

    MattDahEpic

    Joined:
    Apr 22, 2014
    Posts:
    11
    I am trying to make a ScriptableWizard that pauses the editor like EditorUtility.ShowDialog does: the wizard itself can be interacted with while the editor behind cannot, and blocks execution of subsequent statements from whereever it was called from (a MenuItem attributed function in my case). Using a while loop that doesn't end until the Wizard finishes doesn't work since it sticks there and doesn't render or take input to the wizard.

    However the way the Editor functions do this is ideal. Currently the ScriptableWizard shows up but doesn't render until all the subsequent dialogs have finished, at which point I'm already building the player. If it matters, the involved code is as follows:
    Code (csharp):
    1.  
    2.     [MenuItem("Tools/Compile Build",priority = 51)]
    3.     private static void DoBuild () {
    4.         try {
    5.             SimpleStringWizard.DisplayWizard("Version String", "Please enter the version string.", (string s) => {
    6.                 GameRuntimeHelper.version = s;
    7.                 PlayerSettings.bundleVersion = s;
    8.             });
    9.             GameRuntimeHelper.developerBuild = EditorUtility.DisplayDialog("Developer Build?", "Should this build be a developer build?", "Yes", "No");
    10.             GameRuntimeHelper.demoVersion = EditorUtility.DisplayDialog("Demo Build?", "Should this build be limited to demo functionality?", "Yes", "No");
    11.            //...
    12.             BuildPipeline.BuildPlayer(options);
    13.         } catch (System.Exception ex) {
    14.             Debug.LogException(ex);
    15.         }
    16.     }
    17.  
    and
    Code (csharp):
    1.  
    2. public class SimpleStringWizard : ScriptableWizard {
    3.     string value;
    4.     string instructions;
    5.     System.Action<string> returnHandler;
    6.  
    7.     public static void DisplayWizard (string windowTitle, string windowInstructions, System.Action<string> valueHandler) {
    8.         SimpleStringWizard wizard = ScriptableWizard.DisplayWizard<SimpleStringWizard>(windowTitle, "Done");
    9.         wizard.returnHandler = valueHandler;
    10.         wizard.instructions = windowInstructions;
    11.     }
    12.  
    13.     protected override bool DrawWizardGUI() {
    14.         EditorGUILayout.LabelField(instructions);
    15.         value = EditorGUILayout.TextField("Value");
    16.         return true;
    17.     }
    18.  
    19.     private void OnWizardCreate() {
    20.         returnHandler(value);
    21.     }
    22. }
    23.