赞
踩
①减少DrawCall:在Unity中,通常渲染一个纹理会调用一次DrawCall。一个项目中包含大量的纹理,如果绘制每个纹理都调用一次DrawCall,这会占用过多的资源,从而影响整个游戏的性能。
②减少内存占用:比如你有一张宽高为90x90和一张宽高为9x9的图片,如果不合成大贴图,那么需要使用128x128和16x16的两张图片(分别是2的7次方和2的4次方)。但如果使用一张大图的话,可以把90x90和9x9的图片放到128x128的大图中,这样就用一张图片。
官方链接:
https://docs.unity3d.com/cn/current/Manual/class-SpriteAtlas.html
public Image img;
void Start()
{
//加载图集,这里用了AssetDatabase加载,实际项目中根据自己的代码来加载
string path = "assets/atlas/main/main.spriteatlas";
Object asset = AssetDatabase.LoadAssetAtPath(path, typeof(SpriteAtlas));
SpriteAtlas atlas = asset as SpriteAtlas;
//替换图片
img.sprite = atlas.GetSprite("icon_shop");
}
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。