(NGUI)UISprite 切换图集

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在哪一个图集,在需要显示的时候动态指定图集就可以了~

原文地址:https://www.cnblogs.com/wonderKK/p/4060572.html