test material
The test materials are one in tga format and one in png format. Their image sizes are the same 8K images.
The two pictures in AssetBundles show that
the Tga format picture is obviously much larger. Let's package it into an ab package and take a look.
on PC
After packaging, it is obvious that the sizes are the same. Let's load the ab package and check the time.
The loading times of the two are basically the same.
on Android
Packaging Android's ASTC6x6 format, we see that the size is also the same, half smaller than the default format under PC.
The loading time is tested on PC, as shown in the figure below:
The loading test is carried out on Xiaomi 12, as shown in the figure:
We see that tga loads quickly to prevent interference, so we load it three times in a row to see.
Load test multiple times
On PC:
On Xiaomi:
This time we see that it is sometimes faster and sometimes slower. It should be the internal reading cycle problem of Android (this is not sure). The
approximate reading time is the same.
Load script:
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Runtime.CompilerServices;
using System.Threading.Tasks;
using UnityEngine;
using UnityEngine.Networking;
public static class AsyncExtensionTask
{
public static TaskAwaiter GetAwaiter(this AsyncOperation asyncOp)
{
var tcs = new TaskCompletionSource<object>();
if (asyncOp != null) asyncOp.completed += obj => tcs?.SetResult(null); //报空处理
return ((Task)tcs.Task).GetAwaiter();
}
}
public class loadtest : MonoBehaviour
{
// Start is called before the first frame update
async void Start()
{
await Task.Delay(3000);
await picLoadAsync(1,"pngbig.p");
await picLoadAsync(1,"tgabig.p");
await picLoadAsync(2,"pngbig.p");
await picLoadAsync(2,"tgabig.p");
await picLoadAsync(3,"pngbig.p");
await picLoadAsync(3,"tgabig.p");
}
private async Task picLoadAsync(int no,string path)
{
float btime = Time.realtimeSinceStartup;
string localurl = Application.streamingAssetsPath;
string url = string.Format("{0}/{1}", localurl, path);
UnityWebRequest www;
www = UnityWebRequest.Get(url);
await www.SendWebRequest();
if (www.result == UnityWebRequest.Result.Success)
{
#if DEBUG
Debug.Log("<color=#6780AB>taskloader本地下载成功:</color>" + url);
#endif
AssetBundleCreateRequest abRequest = AssetBundle.LoadFromMemoryAsync(www.downloadHandler.data);
while (!abRequest.isDone)
{
await Task.Delay(100);
}
AssetBundle ab = abRequest.assetBundle;
float sub = Time.realtimeSinceStartup - btime;
Debug.Log("加载文件,第"+ no+"次," + path + ",time:" + sub);
ab.Unload(true);
www.Dispose();
}
else
{
#if DEBUG
Debug.Log("TaskLoader 本地下载asset错误:" + www.error + "," + url);
#endif
}
}
}
Summarize
The image packaging format packaged under Unity initially seems to have nothing to do with the format, but is closely related to the resolution of the image.
I don't know if it's rigorous.
Discussions are welcome.