Sprite Atlas(精灵图集)是一种将多个小图(精灵)打包成一个大图的技术。它的主要目的是优化游戏或应用程序的性能,减少内存占用和渲染开销。
- 创建:
- 右键直接创建;
- 存放精灵的文件夹拖入
- 使用:
- 通过精灵名字获取:
private SpriteAtlas _animalAtlas;
public void Init()
{
_animalAtlas = Resources.Load<SpriteAtlas>(SpritePath.AtlasPath + SpritePath.AnimalAtlasPath);
}
public Sprite GetAnimalSpriteById(int id)
{
return _animalAtlas.GetSprite($"{
id}");
}```