检测GUI窗口关闭统一

时间:2015-06-11 02:37:53

标签: unity3d

有没有办法检测GUI窗口何时关闭?我正在构建一个编辑器工具,我需要在窗口关闭后执行一些操作。理想情况下,如果有回调或事件通知我那么那将是完美的。我搜索了很多,但我没有找到任何东西。我也许有可能使用错误的关键字进行搜索。有没有工作?任何帮助是极大的赞赏。谢谢!

1 个答案:

答案 0 :(得分:3)

可以找到完整的源代码和原始帖子here

你可以尝试使用布尔属性伪造窗口关闭/打开效果,每当调用 setter 时,会调用某个函数 OnWindowClosed()

在Mac OSX上测试: enter image description here

bool _bWindowActive;
public bool bWindowActive {
    get { return _bWindowActive;}
    set { 
        _bWindowActive = value;
        if (!bWindowActive) {
            //This is called everytime, when bWindowActive = false;
            OnWindowClosed ();  
        }
    }
}

public void OnWindowClosed ()
{
    Debug.Log ("Windows Closed");
}

public void OnGUI() {

    if (GUI.Button (new Rect (10, 20, 100, 20), "Show Window"))
        bWindowActive = true;
    if (GUI.Button (new Rect (10,60,100,20), "Close Window"))
        bWindowActive = false;

    if (bWindowActive) {
        GUI.Window (0, new Rect(200, 10, 200, 200), DoMyWindow, "My Window");
    }
}

public void DoMyWindow(int windowID) {
    if (GUI.Button (new Rect (10,20,100,20), "Hello World"))
        print ("Got a click");
}
相关问题