and*_*er1 7 c# screenshot unity-game-engine
如何在没有像 Snipping Tool 或 Lightshot 这样的外部来源的情况下截取游戏视图的屏幕截图,例如使用我在游戏视图窗口中配置的分辨率截取屏幕截图。就像我想为我的桌面、商店页面截取 4k 屏幕截图或与朋友分享一样。
这非常简单,最后您可以截取您在游戏视图中看到的所有内容的屏幕截图,如果您不想显示用户界面,只需禁用它的画布即可。
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
}
}
Run Code Online (Sandbox Code Playgroud)