Unity - 创建具有编辑器块功能的 EditorWindow(如 EditorUtility.DisplayDialog)

Unity - Create EditorWindow with editor block functionality (like EditorUtility.DisplayDialog)

如标题所说,我想创建一个自定义的 EditorWindow,它将以与 EditorUtility.DisplayDialog 相同的方式阻止 Unity 编辑器。我知道如何创建一个 EditorWindow,但我不知道该怎么做,就是如何阻止编辑器,直到用户在我的自定义 EditorWindow 中按下按钮或 window 关闭。

如果有人知道如何解决这个问题,我将不胜感激。谢谢

目前 afaik 似乎无法使用自定义 EditorWindow.

来存档它

可以 可以使用 ShowModalUtility 来实现(在 2019.1 中介绍)。

只需在您通常会做的行中,例如

yourWindow.Show();

用 instead 替换它

yourWindow.ShowModalUtility();

Show the EditorWindow as a floating modal window.

The utility window does not allow interaction with the editor while running. This means the EditorWindow.ShowModalUtility window is never hidden by the Unity editor. It is, however, notdockable to the editor.

Utility windows will always be in front of normal Unity windows. It will be hidden whenthe user switches from Unity to another application.

Note: You do not need to use EditorWindow.GetWindow before using this function to show the window.


BUT 刚刚注意到:通常这应该可以解决问题,但不幸的是,似乎 bug 仍然存在,因为 Unity 2019.1 处于 alpha 状态 .. 显然直到现在才修复 ...

正如您在链接的错误报告中看到的那样,他们说它的优先级太低,并将可能的修复推送到 Unity 2019.3 .. 目前仍在 alpha状态 .. 所以 ... 谁知道这是否以及何时会真正修复


小趣事:在链接的示例代码中,Unity 有它 错误的 并使用 ShowUtility 而不是 ShowModalUtility