上一篇中讲述了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();
}
// 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;
}
}
大家可以简单了看一下。。。也许会有帮助 另外有需要云服务器可以了解下创新互联scvps.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。