using System.Collections;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.Networking;
public class LoadWebTexture : MonoBehaviour
{
MeshRenderer meshRender;
void Start()
{
meshRender = GetComponent<MeshRenderer>();
StartCoroutine(TextureReader("01.png",LoadMatPic));
}
void LoadMatPic(Texture texture)
{
meshRender.material.mainTexture = texture;
}
public static IEnumerator TextureReader(string name, UnityAction<Texture> action)
{
string path = "http://localhost/pic/" + name;
UnityWebRequest unityWebRequest = UnityWebRequestTexture.GetTexture(path);
yield return unityWebRequest.SendWebRequest();
if (unityWebRequest.error != null)
{
Debug.Log(unityWebRequest.error);
}
else
{
if (action != null)
{
action(DownloadHandlerTexture.GetContent(unityWebRequest));
}
}
}
}
|