網路圖片加載
較低版本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
end
end
較高版本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
end
end
目前使用之上兩個辦法,后續有更新再更改,
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/287699.html
標籤:其他
上一篇:2021-06-14
