Video from Web Part II
LitJson
因為等等抓下來的東西會是個JSON,要用LitJson做parsing,所以先把它抓下來
使用教學參考該影片
HTTP GET
開一個新的C# Script,attach在一個GameObejct -> UI -> Event System裡
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.Video;
using System.IO;
using LitJson;
public class YTVideo : MonoBehaviour {
private string url = "https://www.googleapis.com/youtube/v3/search?part=snippet&maxResults=50&q=VR&type=video&key=不讓你看我的key";
private JsonData resultData;
private Renderer render;
private int page = 0;
IEnumerator Start() {
WWW www = new WWW(url);
yield return www;
resultData = JsonMapper.ToObject(www.text);
}
}
可以把www.text LOG出來看看它長啥樣子
幾個可能會用到的資料位置
| 資料 | 位置 |
|---|---|
| 影片標題 | ["items"][(第幾支影片)]["snippet"]["title"] |
| 影片縮圖URL(解析度自行替換: high / medium / default) | ["items"][(第幾支影片)]["snippet"]["thumbnails"]["high"]["url"] |
| 影片ID | ["items"][(第幾支影片)]["id"]["videoId"] |
試試thumbnail
![]()
然而還找不到播放的方法QWQ
https://www.assetstore.unity3d.com/cn/#!/content/29704
幹超貴!!