Unity3d截图功能
void Update () {
    if (Input.GetKeyDown(KeyCode.C))
    {
        string fileName = DateTime.Now.Ticks.ToString();
        string tagerFolder = DateTime.Now.ToString("yyyy-MM-dd");
        string pathName = Path.Combine(Application.persistentDataPath, tagerFolder);
        if (!Directory.Exists(pathName))
        {
            Directory.CreateDirectory(pathName);
        }

        string path = Path.Combine(pathName, fileName + ".png");
        //Application.CaptureScreenshot(path);Unity2017弃用了
        ScreenCapture.CaptureScreenshot(path);
        Debug.Log(path);
    }
}

如果不写路径只写文件名时,截图就会在保存在Unity工程的根目录中。


首页 我的博客
粤ICP备17103704号