美文网首页
通过UnityWebRequest 判断 Application

通过UnityWebRequest 判断 Application

作者: CERI_CHANNEL | 来源:发表于2023-08-06 18:55 被阅读0次

如果只是通过 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;

相关文章

网友评论

      本文标题:通过UnityWebRequest 判断 Application

      本文链接:https://www.haomeiwen.com/subject/wvjwpdtx.html