屏幕截图覆盖问题和文件夹存储失败



我已经让屏幕截图功能在最简单的层面上工作。但是,一旦我尝试将文件夹附加到它或分配目录,它每次都无法存储。几个月来我一直在寻找解决方案。我最终尝试了很多东西,我终于回到了基础,并在这里结束了:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.IO;
public class BasicScreenShot: MonoBehaviour 
{
public string title="screencap";
public int count=0;
public void CapScrn() 
{
Application.CaptureScreenshot(title + count++ + ".png");
}
}

这有效,但每次我再次启动游戏时,它都会节省自己。我还想添加一个文件夹目标以供保存,但我也无法使其工作。我已经尝试过Directory.createDirectory,但这不起作用。我尝试了Application.dataPath + "/.../.../"但没有用 - 即使有Path.Combine.

问题是第一次调用此函数将使用 0 作为计数,因此您可以执行以下操作以确保始终使用最新值:

public class BasicScreenShot: MonoBehaviour 
{
public string title="screencap";
public int count;
public BasicScreenShot()
{
// this gets the last value stored on the device
count = PlayerPrefs.GetInt("screencapCount");
}
public void CapScrn() 
{
count++;
Application.CaptureScreenshot(title + count + ".png");
// ensure this value is saved onto the device
PlayerPrefs.SetInt("screencapCount", count);
}
}

最新更新