本文共 1003 字,大约阅读时间需要 3 分钟。
较低版本unity加载网络图片,unity5.x及以下
function loadWebImage(url) -- 获取imageView对象,imageView对象包含了RawImage组件 local imageView = GameObject.Find(“ImageView”) local texture local www www = CS.UnityEngine.WWW(url) while (true) do if www.isDone==true then texture = www.texture imageView:GetComponent("RawImage").texture = texture break end endend
较高版本unity加载网络图片,unity2017以及之上
function loadWebImage(url) -- 获取imageView对象,imageView对象包含了RawImage组件 local imageView = GameObject.Find("ImageView") local texture = CS.UnityEngine.Texture2D(200, 100) local www www = CS.UnityEngine.Networking.UnityWebRequest.Get(url) www:SendWebRequest() while (true) do if www.isDone==true then local result = www.downloadHandler.data CS.UnityEngine.ImageConversion.LoadImage(texture, result) imageView:GetComponent("RawImage").texture = texture break end endend
目前使用之上两个办法,后续有更新再更改。
转载地址:http://tdktn.baihongyu.com/