Unity saves the resources to the desktop path. If the pc desktop path does not exist, it will be saved to streamingAssetsPath;

Unity chooses the appropriate save path based on your actual needs and target platform

string Name = DateTime.Now.ToString("yyyyMMddHHmmss");
string streamingAssetsPath = Application.streamingAssetsPath;
string filePath = Path.Combine(streamingAssetsPath, Name + ".png");

#if UNITY_EDITOR || UNITY_STANDALONE
// 如果是在Unity编辑器或Standalone平台上运行,将StreamingAssets路径更改为应用程序的可写入路径
filePath = Path.Combine(Application.persistentDataPath, Name + ".png");
#endif

File.WriteAllBytes(filePath, bytes);
Debug.Log("截图已保存至:" + filePath);

To change the save path to the path on your desktop;

string Name = DateTime.Now.ToString("yyyyMMddHHmmss");
string desktopPath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
string filePath = Path.Combine(desktopPath, Name + ".png");
File.WriteAllBytes(filePath, bytes);
Debug.Log("截图已保存至:" + filePath);

To determine if the desktop path exists and select a save path based on the result, use the following code example

string desktopPath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
string filePath;

if (Directory.Exists(desktopPath))
{
    
    
    filePath = Path.Combine(desktopPath, Name + ".png");
}
else
{
    
    
    string streamingAssetsPath = Application.streamingAssetsPath;
    filePath = Path.Combine(streamingAssetsPath, Name + ".png");
}

File.WriteAllBytes(filePath, bytes);
Debug.Log("截图已保存至:" + filePath);

The application code scene is in the screenshot save. If you don’t understand, please go to the previous screenshot to view it.

Guess you like

Origin blog.csdn.net/weixin_44047050/article/details/130924021
Recommended