如何在Unity中截取游戏视图的屏幕截图

问题描述 投票:0回答:3

如何在没有像 Snipping Tool 或 Lightshot 这样的外部来源的情况下截取游戏视图的屏幕截图,例如使用我在游戏视图窗口中配置的分辨率截取屏幕截图。 就像我想为我的桌面、商店页面或与朋友分享 4k 屏幕截图一样。

c# unity-game-engine screenshot
3个回答
5
投票

Unity已经有截图工具了。它称为 Recorder,不需要任何编码。

  1. 在 Unity 中,转到“窗口”菜单,然后单击“包管理器”
  2. 默认情况下,包可能设置为“在项目中”。选择“Unity注册表”
  3. 在搜索框中输入“录音机”
  4. 选择Recorder并点击窗口右下角的Install
  5. 这就是设置所有内容所需的全部内容,希望这些选项有意义。主要要注意的是,将“录制模式”设置为“单次”将截取单个屏幕截图(使用 F10)

4
投票

这非常简单,最后你可以截取你在游戏视图中看到的所有内容的屏幕截图,如果你不想显示用户界面,只需禁用它的画布即可。

    private void Update(){
        if(Input.GetMouseButtonDown(0)){ // capture screen shot on left mouse button down

            string folderPath = "Assets/Screenshots/"; // the path of your project folder

            if (!System.IO.Directory.Exists(folderPath)) // if this path does not exist yet
                System.IO.Directory.CreateDirectory(folderPath);  // it will get created
            
            var screenshotName =
                                    "Screenshot_" +
                                    System.DateTime.Now.ToString("dd-MM-yyyy-HH-mm-ss") + // puts the current time right into the screenshot name
                                    ".png"; // put youre favorite data format here
            ScreenCapture.CaptureScreenshot(System.IO.Path.Combine(folderPath, screenshotName),2); // takes the sceenshot, the "2" is for the scaled resolution, you can put this to 600 but it will take really long to scale the image up
            Debug.Log(folderPath + screenshotName); // You get instant feedback in the console
        }
    }

0
投票

这里(页面底部)是一个脚本,它将在多个特定的屏幕尺寸下截取屏幕截图,还有一个有关使用它的视频。将其放在场景中的游戏对象上,确保脚本的类名和文件名相同

© www.soinside.com 2019 - 2024. All rights reserved.