hol*_*bts 2 c# desktop-application unity-game-engine
我有一个在 Unity 上制作的桌面应用程序,我想使用附加到主摄像头的 C# 脚本截取应用程序中当前视图的屏幕截图。请帮忙。
我浏览了在这个平台上找到的其他代码片段,但似乎没有任何帮助。
您可以使用CaptureScreenshot。
public class ScreenCapture : MonoBehaviour
{
//here you can set the folder you want to use,
//IMPORTANT - use "@" before the string, because this is a verbatim string
//IMPORTANT - the folder must exists
string pathToYourFile = @"C:\Screenshots\";
//this is the name of the file
string fileName = "filename";
//this is the file type
string fileType = ".png";
private int CurrentScreenshot { get => PlayerPrefs.GetInt("ScreenShot"); set => PlayerPrefs.SetInt("ScreenShot", value); }
private void Update()
{
if (Input.GetKeyDown(KeyCode.Space))
{
UnityEngine.ScreenCapture.CaptureScreenshot(pathToYourFile + fileName + CurrentScreenshot + fileType);
CurrentScreenshot++;
}
}
}
Run Code Online (Sandbox Code Playgroud)
一些笔记。