Search Unity

Code halting EditorWindow with return value?

Discussion in 'Editor & General Support' started by Deleted User, Sep 30, 2019.

  1. Deleted User

    Deleted User

    Guest

    I need an equivalent to
    Code (CSharp):
    1. EditorUtility.DisplayDialog
    except that I want to have customizable values in the dialogue (content of a ScriptableObject), like an EditorWindow, or a ScriptableWizard have, but want to keep the ability to halt the editor code execution and resume it depending on the button choice.
    This is for checking the configuration of a ScriptableObject on the fly, while the user chose a build menu.

    Is this possible?
     
  2. Deleted User

    Deleted User

    Guest

    I found a way, this is how I did it:

    Code (CSharp):
    1. public class CustomScriptableWizard : ScriptableWizard
    2. {
    3.     CustomScriptableObject customScriptableObject;
    4.     Editor customScriptableObjectEditor;
    5.     [NonSerialized] public Action SuccessAction;
    6.  
    7.     private void OnEnable()
    8.     {
    9.         customScriptableObject= Resources.Load<CustomScriptableObject>(<ResourcesPathToCustomScriptableObject>);
    10.     }
    11.  
    12.     private void OnGUI()
    13.     {
    14.         if (!customScriptableObjectEditor)
    15.             Editor.CreateCachedEditor(customScriptableObject, null, ref customScriptableObjectEditor);
    16.         customScriptableObjectEditor.OnInspectorGUI();
    17.  
    18.         if (GUILayout.Button(createButtonName))
    19.             SuccessAction?.Invoke();
    20.     }
    21. }
    calling it like this:
    Code (CSharp):
    1. CustomScriptableWizard debugSettingsBuildWindow = ScriptableWizard.DisplayWizard<CustomScriptableWizard>(<Header>, <createButtonName>);
    2.         debugSettingsBuildWindow.SuccessAction = () => Debug.Log("Works");