如果只是通过 UnityWebRequest.Get
会将文件下载在内存,对于一下低端机器很容易会被内存撑闪退。
其实只需要判断下 downloadedBytes
大小就行
var www = UnityWebRequest.Get(path);
var tempFilePath = Util.CombinePath(Application.streamingAssetsPath, $"streaming_assets_check_{Path.GetFileNameWithoutExtension(path)}.bytes");
www.downloadHandler = new DownloadHandlerFile(tempFilePath);
www.SendWebRequest();
bool isExist = false;
while (!www.isDone)
{
if (www.downloadedBytes > 0)
{
www.downloadHandler.Dispose();
www.Dispose();
Debug.Log($"[CheckStreamingAssetsFileExist] 存在: {path}");
isExist = true;
break;
}
}
if (File.Exists(tempFilePath))
{
File.Delete(tempFilePath);
}
if (false == isExist)
{
Debug.Log($"[CheckStreamingAssetsFileExist] 不存在({www.error}): {path}");
}
return isExist;