【问题标题】:Unity How do I capture GameView in my EditorWindowUnity 如何在我的 EditorWindow 中捕获 GameView
【发布时间】:2019-03-19 00:29:49
【问题描述】:

我正在为我的游戏制作一个简单的关卡编辑器窗口,我想将 GameView 图像捕获到该关卡编辑器窗口。我正在使用 ScreenCapture.CaptureScreenshotAsTexture() 但它给出了 leveleditor 窗口的图像,我也尝试了 Texture2d.ReadPixels 但它给出了相同的结果。

【问题讨论】:

    标签: unity3d


    【解决方案1】:

    你可以看看my answer here。我编写了一个脚本,可以捕获当前聚焦的任何窗口。

    您可以轻松地采用它来始终使GameView 成为捕获的窗口。例如使用这样的反射 (source)

    public static EditorWindow GetMainGameView()
    {
        var assembly = typeof(EditorWindow).Assembly;
        var type = assembly.GetType("UnityEditor.GameView");
        var gameview = EditorWindow.GetWindow(type);
        return gameview;
    }
    

    替换

    var activeWindow = EditorWindow.focusedWindow;
    

    var activeWindow = EditorWindow.GetMainGameView();
    

    请注意,如果还没有GameView 窗口,这将打开一个新窗口。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-08-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多