Unity中的文件拷贝
在项目中经常遇到需要将streamingAssetsPath中的文件拷贝至persistentDataPath中,记录一下自己的实现方式:
public static void CopyFile(string fileName, int imageType)
{
if (Application.platform == RuntimePlatform.Android)
{
using (UnityWebRequest request = UnityWebRequest.Get(Application.streamingAssetsPath + "/" + fileName))
{
request.timeout = 3;
request.downloadHandler = new DownloadHandlerFile(Application.persistentDataPath + "/" + fileName);
request.SendWebRequest();
float time = Time.time;
while (!request.isDone)
{
}
request.Abort();
request.disposeDownloadHandlerOnDispose = true;
request.Dispose();
}
}
else
{
File.Copy(Application.streamingAssetsPath + "/" + fileName, Application.persistentDataPath + "/" + fileName, true);
}
}
|