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

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

一、菜单

3333.png

二、工程截图

2222.png

111111.png

生成图集的工具类 AssetsToolEditor

三、写测试脚本

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class Test : MonoBehaviour
{
    public Image image;

    void Start()
    {
        StartCoroutine(LoadAtlas());
    }

    IEnumerator LoadAtlas()
    {
        string url = string.Format("{0}/atlas/emoji.atlas", Application.streamingAssetsPath);
        WWW www = new WWW(url);
        while (!www.isDone)
            yield return www;
        AssetBundle ab = www.assetBundle;
        Sprite[] sprites = ab.LoadAllAssets<Sprite>();
        for (int i = 0; i < sprites.Length; i++)
            Debug.Log(sprites[i].name);

        image.sprite = sprites[0];
    }
}

标签: Unity3d

Powered by emlog  蜀ICP备18021003号-1   sitemap

川公网安备 51019002001593号