使用astc优化网络图片;workouts链接修改

This commit is contained in:
Caiyanpeng committed 2021-11-18 09:15:19 +08:00
1 parent 5480de5c6d
commit 42e23e2f84
4 files changed
+35 -25

No files matched your search

+31 -14
View File
@@ -332,10 +332,10 @@ namespace Assets.Scripts
}
}
UIManager.Instance.StartCoroutine(DownloadImage(img, url,(texture)=> {
//if (cache && !propTextureCache.ContainsKey(url))
//{
// propTextureCache.Add(url, texture);
//}
if (cache && !propTextureCache.ContainsKey(url))
{
propTextureCache.Add(url, texture);
}
}));
}
@@ -375,36 +375,53 @@ namespace Assets.Scripts
static IEnumerator DownloadImage(RawImage img,string MediaUrl, Action<Texture> action = null)
{
UnityWebRequest request = UnityWebRequestTexture.GetTexture(MediaUrl,true);
UnityWebRequest request = UnityWebRequest.Get(MediaUrl);
yield return request.SendWebRequest();
if (request.isNetworkError || request.isHttpError)
Debug.Log(request.error);
else if(img!=null)
else if (img != null)
{
var _t = ((DownloadHandlerTexture)request.downloadHandler).texture;
_t.name = MediaUrl;
img.texture = _t;
if (action != null)
var data = request.downloadHandler.data;
img.texture = Utils.GetDownloadTexture(MediaUrl, data);
if (action != null)
{
action.Invoke(img.texture);
}
}
}
public static Texture GetDownloadTexture(string MediaUrl, byte[] data)
{
#if UNITY_EDITOR
var _t = new Texture2D(4, 4, TextureFormat.DXT5, false);
#else
#if UNITY_IOS
var _t = new Texture2D(4, 4, TextureFormat.ASTC_RGB_4x4,false);
Debug.Log("使用了壓縮");
#elif UNITY_ANDROID
var _t = new Texture2D(4, 4, TextureFormat.ASTC_RGB_4x4,false);
Debug.Log("使用了壓縮");
#else //pc
var _t = new Texture2D(4, 4, TextureFormat.DXT5,false);
#endif
#endif
_t.LoadImage(data,true);
_t.name = MediaUrl;
return _t;
}
static IEnumerator DownloadImageCallBack(RawImage img, string MediaUrl,Action<string> action)
{
UnityWebRequest request = UnityWebRequestTexture.GetTexture(MediaUrl, true);
UnityWebRequest request = UnityWebRequest.Get(MediaUrl);
yield return request.SendWebRequest();
if (request.isNetworkError || request.isHttpError)
Debug.Log(request.error);
else
{
img.texture = ((DownloadHandlerTexture)request.downloadHandler).texture;
var data = request.downloadHandler.data;
img.texture = Utils.GetDownloadTexture(MediaUrl, data);
action.Invoke(MediaUrl);
}
}
/*显示网络图片*/
/*获取最顶层对象*/
public static Transform FindUpParent(Transform zi)
{