2015-06-11 64 views
1

有沒有辦法來檢測GUI窗口已關閉?我正在構建一個編輯器工具,我需要在窗口關閉後執行一些操作。理想情況下,如果有回調或事件通知我,那麼這將是完美的。我搜查了很多,但我沒有找到任何東西。我也可能使用錯誤的關鍵字進行搜索。有沒有解決辦法?任何幫助是極大的讚賞。謝謝!檢測GUI窗口關閉在團結

回答

3

完整的源代碼和原來的職位,可以發現here

您可以嘗試使用一個布爾屬性僞造的窗口關閉/打開的效果,每當二傳手被調用時,一些功能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"); 
} 
+0

嗨,該SOLU重刑看起來不錯。但在這種情況下,您已經創建了一個自定義按鈕。但任何想法如何將其鏈接到出現在編輯器窗口右上角的傳統(x)按鈕。我正在爲藝術家開發這個工具。所以我想盡可能保持簡單。否則,我將不得不創建一個自定義按鈕並將其用於關閉。 – Aadithya

+0

我實際上發現了一個EditorWindow.OnDestory(),在昨天整個過程中我都無法使用它。但我真的很喜歡你的解決方案 - 這是一個有趣的方式。謝謝! – Aadithya