1, 将所有要打入目标图集的图片设置为 "Sprite (2D and UI)" , 如下图所示
2, 新建一个SpriteAtlas对象
3, 在Objects for Packing 添加小图片 (注意是sprite类型的), 如下图
4, 制作成功,如下图所示
1, 代码 , 先上
登录后复制
using UnityEditor;
using UnityEngine;
using UnityEngine.U2D;
using UnityEngine.UI;
/// <summary>
/// 对于Unity图集的测试
/// </summary>
public class AtlasDemo : MonoBehaviour
{
[SerializeReference]
private SpriteRenderer starRender;//sprite的渲染
[SerializeReference]
private Image imgPopularity;//Image的渲染
// Start is called before the first frame update
void Start()
{
SpriteAtlas atlas = AssetDatabase.LoadAssetAtPath<SpriteAtlas>("Assets/Res/OffPrintComeback/OffPrintComeback.spriteatlas");
#region 关于2D的Sprite
Sprite sprite = atlas.GetSprite("star");
this.starRender.sprite = sprite;
#endregion
#region 关于UI的Image
Sprite img = atlas.GetSprite("人气");
this.imgPopularity.sprite = img;
this.imgPopularity.SetNativeSize();
#endregion
}
// Update is called once per frame
void Update()
{
}
}
2, scene介绍
代码既是分别对Sp 和 Image 赋值图集中的纹理
免责声明:本文系网络转载或改编,未找到原创作者,版权归原作者所有。如涉及版权,请联系删