UGUI——创建精灵图集(SpriteAtlas)

作者:追风剑情 发布于:2021-8-17 10:15 分类:Unity3d

一、菜单

3333.png

二、工程截图

2222.png

111111.png

生成图集的工具类 AssetsToolEditor

三、写测试脚本

  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5.  
  6. public class Test : MonoBehaviour
  7. {
  8. public Image image;
  9.  
  10. void Start()
  11. {
  12. StartCoroutine(LoadAtlas());
  13. }
  14.  
  15. IEnumerator LoadAtlas()
  16. {
  17. string url = string.Format("{0}/atlas/emoji.atlas", Application.streamingAssetsPath);
  18. WWW www = new WWW(url);
  19. while (!www.isDone)
  20. yield return www;
  21. AssetBundle ab = www.assetBundle;
  22. Sprite[] sprites = ab.LoadAllAssets<Sprite>();
  23. for (int i = 0; i < sprites.Length; i++)
  24. Debug.Log(sprites[i].name);
  25.  
  26. image.sprite = sprites[0];
  27. }
  28. }

标签: Unity3d

Powered by emlog  蜀ICP备18021003号-1   sitemap

川公网安备 51019002001593号