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

This commit is contained in:
CaiYanPeng 2021-11-17 18:10:20 +08:00
parent 5480de5c6d
commit 42e23e2f84
4 changed files with 35 additions and 25 deletions

View File

@ -1,8 +0,0 @@
fileFormatVersion: 2
guid: f134d222725933a4a8aa79fee0ebc10c
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@ -111,7 +111,7 @@ public static class App
Host = "https://wx.powerfun.com.cn/"; Host = "https://wx.powerfun.com.cn/";
UdpAddress = new IPEndPoint(IPAddress.Parse("47.97.84.8"), 11000); UdpAddress = new IPEndPoint(IPAddress.Parse("47.97.84.8"), 11000);
TcpAddress = new IPEndPoint(IPAddress.Parse("47.97.84.8"), 11001); TcpAddress = new IPEndPoint(IPAddress.Parse("47.97.84.8"), 11001);
//Debug.unityLogger.logEnabled = false; Debug.unityLogger.logEnabled = false;
#endif #endif
var isRower = PlayerPrefs.GetString("IsRowerMode"); var isRower = PlayerPrefs.GetString("IsRowerMode");
if (!string.IsNullOrEmpty(isRower)) if (!string.IsNullOrEmpty(isRower))

View File

@ -66,7 +66,7 @@ public class LoginControllerMobile : MonoBehaviour, INativeOnMobileWxLoginResp
transform.Find("Version").gameObject.SetActive(false); transform.Find("Version").gameObject.SetActive(false);
UIManager.ShowAndroidUpdate(info); UIManager.ShowAndroidUpdate(info);
} }
App.WorkoutsUrl = r.data.Value<JObject>("Apk").Value<string>("Url");
#elif UNITY_IOS #elif UNITY_IOS
var sw = r.data.Value<string>("ThirdPartSwitch"); var sw = r.data.Value<string>("ThirdPartSwitch");
transform.Find("Panel/LoginContainer/LoginScrollView/Viewport/Content/FormContainer-Login/Mask/FormContainer/BtnThirdLogin") transform.Find("Panel/LoginContainer/LoginScrollView/Viewport/Content/FormContainer-Login/Mask/FormContainer/BtnThirdLogin")
@ -77,8 +77,9 @@ public class LoginControllerMobile : MonoBehaviour, INativeOnMobileWxLoginResp
Application.OpenURL(info.Value<string>("Url")); Application.OpenURL(info.Value<string>("Url"));
Application.Quit(); Application.Quit();
} }
App.WorkoutsUrl = r.data.Value<JObject>("Ios").Value<string>("Url");
#endif #endif
App.WorkoutsUrl = info.Value<string>("Url");
#endif #endif
} }
//if (r.result) //if (r.result)

View File

@ -332,10 +332,10 @@ namespace Assets.Scripts
} }
} }
UIManager.Instance.StartCoroutine(DownloadImage(img, url,(texture)=> { UIManager.Instance.StartCoroutine(DownloadImage(img, url,(texture)=> {
//if (cache && !propTextureCache.ContainsKey(url)) if (cache && !propTextureCache.ContainsKey(url))
//{ {
// propTextureCache.Add(url, texture); propTextureCache.Add(url, texture);
//} }
})); }));
} }
@ -375,36 +375,53 @@ namespace Assets.Scripts
static IEnumerator DownloadImage(RawImage img,string MediaUrl, Action<Texture> action = null) 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(); yield return request.SendWebRequest();
if (request.isNetworkError || request.isHttpError) if (request.isNetworkError || request.isHttpError)
Debug.Log(request.error); Debug.Log(request.error);
else if(img!=null) else if (img != null)
{ {
var _t = ((DownloadHandlerTexture)request.downloadHandler).texture; var data = request.downloadHandler.data;
_t.name = MediaUrl; img.texture = Utils.GetDownloadTexture(MediaUrl, data);
img.texture = _t;
if (action != null) if (action != null)
{ {
action.Invoke(img.texture); 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) 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(); yield return request.SendWebRequest();
if (request.isNetworkError || request.isHttpError) if (request.isNetworkError || request.isHttpError)
Debug.Log(request.error); Debug.Log(request.error);
else else
{ {
img.texture = ((DownloadHandlerTexture)request.downloadHandler).texture; var data = request.downloadHandler.data;
img.texture = Utils.GetDownloadTexture(MediaUrl, data);
action.Invoke(MediaUrl); action.Invoke(MediaUrl);
} }
} }
/*显示网络图片*/ /*显示网络图片*/
/*获取最顶层对象*/ /*获取最顶层对象*/
public static Transform FindUpParent(Transform zi) public static Transform FindUpParent(Transform zi)
{ {