码迷,mamicode.com
首页 > 其他好文 > 详细

设置texture

时间:2017-04-15 13:50:54      阅读:227      评论:0      收藏:0      [点我收藏+]

标签:缓冲区   files   out   xtu   长度   tin   access   tor   mod   

//获取内部资源贴图
    public void setInsideTexture()
    {
        Texture2D texture = Resources.Load(texture_url) as Texture2D;
        Renderer renderer = GetComponent<Renderer>();
        renderer.material.mainTexture = texture;
    }

    //获取外部资源贴图(本地路径)
    public void setExternalTextureByIO()
    {
        //创建文件读取流
        FileStream fileStream = new FileStream(texture_url, FileMode.Open,
            FileAccess.Read);
        fileStream.Seek(0, SeekOrigin.Begin);
        //创建文件长度缓冲区
        byte[] bytes = new byte[fileStream.Length];
        //读取文件
        fileStream.Read(bytes, 0, (int) fileStream.Length);
        //释放文件读取流
        fileStream.Close();
        fileStream.Dispose();
        fileStream = null;

        //创建Texture
        int width = 800;
        int height = 640;
        Texture2D texture = new Texture2D(width, height);
        texture.LoadImage(bytes);
        Renderer renderer = GetComponent<Renderer>();
        renderer.material.mainTexture = texture;

    }

    /// <summary>
    /// 以WWW方式进行加载
    /// </summary>
    private void setExternalTextureByWWW()
    {
        StartCoroutine(LoadWWW());
    }
IEnumerator LoadWWW() {
//请求WWW WWW www = new WWW(texture_url); yield return www; Renderer renderer = GetComponent<Renderer>(); renderer.material.mainTexture = www.texture; Debug.Log(www.ToString()); Stream outStream = File.Create(ExportClass.prePath + "test.png"); byte[] buffer = www.bytes; outStream.Write(buffer, 0, buffer.Length); outStream.Close(); }

 

设置texture

标签:缓冲区   files   out   xtu   长度   tin   access   tor   mod   

原文地址:http://www.cnblogs.com/leeplogs/p/6713759.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!