- Home /
Custom dialog in editor
How can I show a custom dialog in the editor?
I have a dialog I want to make, that contains some checkboxes and some other random controls. I want to show it to the user when they click on a button (in a custom inspector I have already made) in order to choose what to do.
How would I go about doing this in Unity? I can only find dialog calls that are simple message boxes...
Answer by turbanov · Dec 27, 2017 at 11:09 AM
I would strongly recommend using a custom EditorWindow
for that purpose. The suggested ScriptableWizard is kinda ugly and gimmicky. It doesn't provide any substantial benefit, including no modality support.
Create your own window like this, and it will do just fine:
var window = GetWindow<MyWizardWindow>(utility: true, title: "Create New Object", focus: true);
window.ShowUtility();
Your GUI logic then has to be like this:
protected virtual void OnGUI()
{
_Error = null;
EditorGUILayout.PrefixLabel("Name");
_Name = EditorGUILayout.TextField(_Name);
if (!IsValid(this._Name))
_Error = "The name is invalid";
if (!string.IsNullOrEmpty(_Error))
EditorGUILayout.HelpBox(_Error, MessageType.Error);
GUILayout.FlexibleSpace();
EditorGUILayout.BeginHorizontal();
if (GUILayout.Button("Cancel"))
{
Cancel();
}
EditorGUI.BeginDisabledGroup(!string.IsNullOrEmpty(_Error));
if (GUILayout.Button("Create"))
{
Create();
}
EditorGUI.EndDisabledGroup();
EditorGUILayout.EndHorizontal();
}
Answer by jahroy · Oct 19, 2011 at 12:58 AM
Are you looking for ScriptableWizards?
They're like popup windows that you can add controls to.
They allow you to set a bunch of values (even drag and drop game objects) and then execute code when different buttons are pressed.
I think I can do what I need with a one-pane wizard. Thanks!
This seems to be the same as window.ShowUtility();
, really, with some quirks and specialties. Unfortunately it still has no modality status.
Answer by Bunny83 · Oct 18, 2011 at 11:50 PM
Unfortunately (AFAIK) there's no way to display an editor window as a modal window. The only thing that comes with Unity are the simple dialg boxes you've already found (EditorUtility.DisplayDialogComplex).
Well, in a multitasking environment modal windows are evil, Just in some rare cases they would be helpful. Just check if you really need it modal. The user would be pleased when he still can select other things to look up some settings or whatever...
A more or less related question:
http://answers.unity3d.com/questions/139677/how-to-make-a-modal-dialog.html
Asset$$anonymous$$odificationProcess.OnWillSaveAssets is a good example of a time when you might need a modal dialog. I want to present the user with various options for what to do (overwrite, skip, skip remaining, get SVN lock, etc.) and it needs to be modal because the method has to return an array of strings immediately.
Saying they are evil is rather false. There's many situation where the user wants to perform complex operation that are done steps by steps and where changing the scene it is performed on can corrupt it. Unity was never designed with real productivity in $$anonymous$$d. Any time I try to code tools or editors that would automatize the most redundant actions a user has to perform, I hit myself with this kind of retarded shortco$$anonymous$$g. If you want my opinion, drag and drop is evil, but Unity is built that almost anything is made using it at some point.
Your answer
Follow this Question
Related Questions
Editor Input Dialog 2 Answers
Editor Window with List input of Texture2D 0 Answers
MCF dialogs won't open in unity 0 Answers
Adding To Array From Editor 3 Answers
How do I bring up a dialog to let the user choose an asset? 2 Answers