Unity下tga和png格式图片打包成AB包大小和加载速度测试

测试素材

测试素材,一张tga格式,一张png格式,他们的图像尺寸一样都是8K图。

两张图在AssetBundles里显示

Tga格式的图明显大很多,我们打包成ab包看看。

在PC

打包后看,明显大小一样,我们进行ab包加载,看下时间。

两次加载时间也是基本一样的。

在Android

打包android的ASTC6x6格式,我们看到大小也是一样的,比PC下的默认格式小一半。

加载时间在PC上测试,如下图:

在小米12上加载测试,如图:

我们看到tga的加载快,防止干扰,我们连续加载3次看看。

多次加载测试

在PC上:

在小米上:

这次我们看到有时快有时慢,应该是安卓内部的读取周期问题(这个不确定)

大致的读取时间是一样的。

加载脚本:

csharp 复制代码
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
        }
        
    }
}

总结

Unity下打包的图片打包格式,初步看来和格式已经没关系了,和图的分辨率大小密切相关。

不知道是否严谨。

欢迎讨论。

相关推荐
_ZHOURUI_H_13 小时前
MyFramework: 同样是 Unity 游戏开发框架,和 HTFramework 的设计取向有什么不同?(下)
unity·游戏引擎·游戏开发·游戏ui·手游开发
丁小未2 天前
基于MVVM框架的XUUI 扩展的UI管理系统教程
unity·mvvm·ui框架·xuui·ui管理器
丁小未3 天前
基于MVVM框架的XUUI HelloWorld 新手教程
unity·性能优化·c#·游戏引擎
丁小未3 天前
基于MVVM框架的XUUI MoreComplex案例
unity·c#
EQ-雪梨蛋花汤3 天前
【Unity笔记】VR 一体机画面锯齿、模型边缘闪烁、接缝抖动排查:MSAA、Mipmap、Render Scale、Z-Fighting 全流程记录
笔记·unity·vr
YigAin3 天前
Unity Spine 资源出现白边的解决办法
unity·游戏引擎·spine
郝学胜-神的一滴4 天前
中级OpenGL教程 013:渲染器类架构设计与逐帧渲染流程详解
开发语言·c++·unity·游戏引擎·图形渲染·opengl·unreal
真鬼1235 天前
【Unity WebGL】内嵌网页与双向通信
unity·游戏引擎·webgl
zyh______6 天前
C#语法糖(按照实用性排序)
unity·c#
avi91116 天前
[AI教做人]CinemachineCamera 各项调整配置参数入门 + Profiler
unity·游戏开发·camera·cinemachine·visual camera·镜头配置