Unity3D——關於EditorWindow的OnGUI方法在非激活狀況下不執行

如圖: html

我建立了一個EditorWindow,在OnGUI方法中進行繪製界面。

private static void ShowWindow() 
{
    var window = GetWindow<I18nKeyComponentShowWindow>(false, "展現選中的UI對象");
    window.autoRepaintOnSceneChange = true;
    window.Show();
}

void OnGUI() 
{
    GUILayout.Label("按住Ctrl,在激活Unity Game窗口的狀況下,鼠標移過UI");
    UpdateList();
}
複製代碼

OnGUI在此窗口激活(被選中)的狀況下,是會一直被調用的。然而在非激活狀況下,就不生效了,這個時候須要加一個處理:api

void OnInspectorUpdate()
{
    //開啓窗口的重繪,否則窗口信息不會刷新
    Repaint();
}
複製代碼

附上OnInspectorUpdate方法的官方api: docs.unity3d.com/ScriptRefer…bash

OnInspectorUpdate is called at 10 frames per second to give the inspector a chance to update.spa

相關文章
相關標籤/搜索