Open Bian-Sh opened 1 year ago
It makes sense, need to investigate how better to make it. Current problem which I see that is DownloadHandlerTexture
is not able to handle that, there is literally no API by Unity. Looks like to implement this feature need to download a raw image in another way and then create Texture2D
from the bytes array.
Another problem that could be resolved separately is the delay in loading already cached images. But that is a solution to add an optional argument at the loading function, that will allow a user to choose the loading option (with/without verification)
UnityWebRequest has a Head Function which can set head request , the add header "Last-Modified" to get modified date. for example
using System.Collections;
using UnityEngine;
using UnityEngine.Networking;
public class LastModified : MonoBehaviour
{
public string url = "https://example.com";
IEnumerator Start()
{
using (UnityWebRequest request = UnityWebRequest.Head(url))
{
yield return request.SendWebRequest();
if (request.result == UnityWebRequest.Result.Success)
{
string lastModified = request.GetResponseHeader("Last-Modified");
Debug.Log("Last-Modified: " + lastModified);
}
else
{
Debug.LogError(request.error);
}
}
}
}
I have no idea if this could make scene, i ask newbing ,but its worth to have a try.
I don't see how to make it right. @Bian-Sh You can implement it and create a pull request in this repository.
I don't see how to make it right. @Bian-Sh You can implement it and create a pull request in this repository.
等什么时候我有时间了会去看的,这个功能应该需要服务器API 也支持,我会去做更多的了解,确认这个 if modified 是否可以通过 Head 方法直接请求。
I will take a look when I have time. This feature should require server API support. I will try to understand more and confirm if the "if modified" can be requested directly through the Head method.
could you pls add a feature for auto overwrite cached image by check response-header :If-Modified-Since . chat with me if you dont understand wht i say.
reference : https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/If-Modified-Since