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在哪一個圖集,在需要顯示的時候動態指定圖集就可以了~