UISprite是可以使用代码动态切换图集的
using UnityEngine; using System.Collections; public class SpriteAtlasTest : MonoBehaviour { private UISprite _sprite; public UIAtlas atlas; public UIAtlas atlas2; // Use this for initialization void Start () { _sprite = GetComponent<UISprite>(); } // Update is called once per frame void Update () { if(Input.GetMouseButtonDown(0)) { _sprite.atlas = atlas; _sprite.spriteName = "GoodDirt"; } if(Input.GetMouseButtonDown(1)) { _sprite.atlas = atlas2; _sprite.spriteName = "NGUI"; } } }


这样就是使用UISprite来制作图标了,比如物品图标,可以分别存在不同的图集里面,根据配置物品icon在哪一个图集,在需要显示的时候动态指定图集就可以了~
本文介绍如何利用UISprite实现图标动态切换功能,通过代码控制不同图集的应用,适用于物品图标等场景。
3622

被折叠的 条评论
为什么被折叠?



