在 Unity 中,可以通过使用 EditorUtility.DisplayDialog 函数来显示一个模态对话框,并阻止用户在对话框出现时与 Unity 编辑器中的其他窗口交互。可以在打开子窗口时在父窗口中调用此函数,然后在子窗口关闭时再次调用此函数以恢复编辑器窗口的常规操作。以下是示例代码:

using UnityEditor;

public class MyEditorWindow : EditorWindow
{
    private bool isChildWindowOpen = false;

    private void OnGUI()
    {
        if (GUILayout.Button('Open Child Window'))
        {
            isChildWindowOpen = true;
            EditorUtility.DisplayDialog('Child Window', 'This is a child window', 'OK');
            isChildWindowOpen = false;
        }
    }

    private void Update()
    {
        if (isChildWindowOpen)
        {
            // Disable interaction with other windows
            GUI.enabled = false;
        }
        else
        {
            // Enable interaction with other windows
            GUI.enabled = true;
        }
    }
}

在此示例中,当用户单击'Open Child Window'按钮时,将调用 EditorUtility.DisplayDialog 函数并显示一个对话框。此时,窗口将被禁用,直到用户关闭子窗口并调用此函数以启用窗口。

Unity 编辑器窗口:禁用父窗口交互的子窗口实现

原文地址: https://www.cveoy.top/t/topic/lK89 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录