【unity】精灵图集(Sprite Atlas)快速上手

Sprite Atlas(精灵图集)是一种将多个小图(精灵)打包成一个大图的技术。它的主要目的是优化游戏或应用程序的性能,减少内存占用和渲染开销。

  1. 创建:
    • 右键直接创建;
    • 存放精灵的文件夹拖入
  2. 使用:
    • 通过精灵名字获取:
private SpriteAtlas _animalAtlas;
   
    public void Init()
    {
    
    
        _animalAtlas = Resources.Load<SpriteAtlas>(SpritePath.AtlasPath + SpritePath.AnimalAtlasPath);
    }

    public Sprite GetAnimalSpriteById(int id)
    {
    
    
        return _animalAtlas.GetSprite($"{
      
      id}");
    }```

猜你喜欢

转载自blog.csdn.net/Xz616/article/details/135444785