【问题标题】:In unity editor script, when focus my editorwindow, how to make editor window don't focus any textfield在统一编辑器脚本中,当聚焦我的编辑器窗口时,如何使编辑器窗口不聚焦任何文本字段
【发布时间】:2018-09-30 14:32:59
【问题描述】:

查看我的 gif,如果在最后一个编辑器窗口焦点中我聚焦一个文本字段,下一个焦点,编辑器窗口将自动聚焦这个文本字段

我发现unity editor官方“Hierarchy”没有这个bug,当我聚焦他们的搜索栏并且失去焦点并重新聚焦时,“Hierarchy”搜索栏不会获得焦点

我认为它必须存在方法来做到这一点,我应该怎么做?

我确定我在编辑器窗口类中使用了正确的移除焦点代码

private void OnFocus()
{
    RemoveInputFocus();
}

private void OnLostFocus()
{
    RemoveInputFocus();
}

private static void RemoveInputFocus()
{
    // EditorGUI.FocusTextInControl(null);
    GUIUtility.keyboardControl = 0;
}

【问题讨论】:

    标签: c# unity3d


    【解决方案1】:

    我修复它,在 OnGUI 块中运行 GUIUtility.keyboardControl = 0,OnGUI 块很重要,如果我将 GUIUtility.keyboardControl = 0 放在 OnFocus 中,它将不起作用,我想在 OnFocus 统一之后做一些事情来接收最后一个焦点

    private void OnGUI()
    {
        // on OnGUI start
        if (firstEnterAfterFocus)
        {
            RemoveInputFocus();
            firstEnterAfterFocus = false;
        }
    }
    
    
    private bool firstEnterAfterFocus;
    
    private void OnFocus()
    {
        firstEnterAfterFocus = true;
        // RemoveInputFocus();
    }
    
    private static void RemoveInputFocus()
    {
        // EditorGUI.FocusTextInControl(null);
        GUIUtility.keyboardControl = 0;
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-09-10
      • 1970-01-01
      • 1970-01-01
      • 2012-10-03
      • 1970-01-01
      相关资源
      最近更新 更多