上一篇中讲述了NGUI动态打图集的功能,提到UGUI将图片转换长Sprite格式,其实网上也有好多,那我在这简单的说一下,
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;
}
}
大家可以简单了看一下。。。也许会有帮助
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。