您的位置:首页 > 移动开发 > Unity3D

Unity中 测试从服务器获取的图片

2018-01-25 10:15 441 查看
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Http : MonoBehaviour {

// Use this for initialization
void Start () {

StartCoroutine("RequestServer");
}

public IEnumerator RequestServer()
{
string url = "http://127.0.0.1:8090";
WWW www = new WWW (url);
yield return www;
if (string.IsNullOrEmpty (www.error)) {

string resultData = www.text;
Debug.Log (resultData);

Texture texture = www.texture;
Debug.Log (texture.name);
if (texture != null) {
Debug.Log("texture不为空");

GameObject subObj = GameObject.CreatePrimitive (PrimitiveType.Quad);
Material mat = new Material (Shader.Find("Transparent/Diffuse"));
mat.mainTexture = texture;
subObj.GetComponent<Renderer> ().material = mat;

} else {
Debug.Log ("texture 是空的");
}
}else{
Debug.Log (www.error);
}
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: