zoukankan      html  css  js  c++  java
  • www改变GUITexture的贴图

    1.从网页加载

    using UnityEngine;
    using System.Collections;
    using System.IO;
    public class WWWLoadGUITex: MonoBehaviour {

    void Update () {

    }

    IEnumerator Start()
    {
    GUITexture guiTexture = gameObject.GetComponent<GUITexture > ();
    string filePath = "http://mp3.zhuqu.com/static/images/water/86/867b534c61bc1c0d34667cbd92372c01.jpg";
    WWW www = new WWW(filePath);
    yield return www ;
    this.gameObject.GetComponent<GUITexture >().texture = www.texture;
    }

    2.从本地加载

    public class NewBehaviourScript : MonoBehaviour {

    // Use this for initialization
    void Start()
    {
    this.gameObject.GetComponent<GUITexture>().texture = GetPic(Application.dataPath + @"/Pictures/1.jpg");
    }

    Texture GetPic(string filePath)
    {
    Texture temp = new Texture();
    FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.Read);
    byte[] array = new byte[fs.Length];
    fs.Read(array, 0, (int)fs.Length);
    Texture2D _tex2 = new Texture2D(128, 128);
    _tex2.LoadImage(array);
    temp = _tex2 as Texture;
    return temp;
    }
    // Update is called once per frame
    void Update () {

    }
    }

  • 相关阅读:
    字符串本质
    常用类
    异常处理
    最终类object 和内部类
    接口
    Java多态
    NIO之五Selector
    NIO之四Buffer
    NIO之三Socket通道
    JAVA NIO(二)Channel通道
  • 原文地址:https://www.cnblogs.com/xwwFrank/p/4460125.html
Copyright © 2011-2022 走看看