我正在尝试从我的“Json”文件中获取视频,我将其上传到 azure 服务器上的统一原始图像组件,但看起来像这样: 在此处输入图像描述
要获得一张效果很好的图片,但对于视频 mp4 却不行,这是代码:
using UnityEngine ;
using UnityEngine.Networking ;
using UnityEngine.UI ;
using System.Collections ;
// Json data format
/*
{
"Name" : "..." ,
"VideoURL" : "..."
}
*/
public struct Data {
public string Name ;
public string VideoURL ;
}
public class Demo : MonoBehaviour {
[SerializeField] Text uiNameText ;
[SerializeField] RawImage uiRawImage ;
string jsonURL = "https://myserver..." ;
void Start () {
StartCoroutine (GetData (jsonURL)) ;
}
IEnumerator GetData (string url) {
UnityWebRequest request = UnityWebRequest.Get (url) ;
yield return request.SendWebRequest() ;
if (request.isNetworkError || request.isHttpError) {
// error ...
} else {
// success...
Data data = JsonUtility.FromJson<Data> (request.downloadHandler.text) ;
// print data in UI
uiNameText.text = data.Name ;
// Load video:
StartCoroutine (GetVideo (data.VideoURL)) ;
}
// Clean up any resources it is using.
request.Dispose () ;
}
IEnumerator GetVideo (string url) {
UnityWebRequest request = UnityWebRequest.GetTexture (url) ;
yield return request.SendWebRequest() ;
if (request.isNetworkError || request.isHttpError) {
// error ...
} else {
//success...
uiRawImage.texture = ((DownloadHandlerTexture)request.downloadHandler).texture ;
}
// Clean up any resources it is using.
request.Dispose () ;
}
}
所以这段代码很好地将图像加载到我的统一中,但对于视频却没有,我试图获得统一支持但同样内容的所有类型的视频。因此,在原始图像组件中,我添加了视频播放器组件,我为其添加了渲染纹理,并为原始图像添加了相同的东西。我的统一版本是 2019.4.26f1。可能是因为统一的版本?我希望有人能真正帮助我。