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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM