溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

UGUI中將圖片轉換成精靈Sprite

發(fā)布時間:2020-07-08 10:47:29 來源:網(wǎng)絡 閱讀:14731 作者:速度速度撒 欄目:開發(fā)技術

上一篇中講述了NGUI動態(tài)打圖集的功能,提到UGUI將圖片轉換長Sprite格式,其實網(wǎng)上也有好多,那我在這簡單的說一下,

using UnityEngine;
using System.Collections;
using UnityEngine.UI;

public class CreateTexture : MonoBehaviour {


    private Image p_w_picpath;

    void Awake()
    {
        p_w_picpath = GameObject.FindWithTag("Image").GetComponent<Image>();
    }

	// Use this for initialization
	void Start () {
        CreateSprite();
	
	}
	//將Resources中得到圖片Pic_01轉成精靈Sprite
    public void CreateSprite()
    {
        Texture2D img = Resources.Load("Pic_01") as Texture2D;
        Sprite pic = Sprite.Create(img, new Rect(0, 0, img.width, img.height), new Vector2(0.5f, 0.5f));//后面Vector2就是你Anchors的Pivot的x/y屬性值
        p_w_picpath.sprite = pic;
 
    }

}

大家可以簡單了看一下。。。也許會有幫助


向AI問一下細節(jié)

免責聲明:本站發(fā)布的內容(圖片、視頻和文字)以原創(chuàng)、轉載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權內容。

AI