YouTube 遊戲角落 SDK 是網頁 SDK,可將網頁遊戲連結至 YouTube 環境。這個 SDK 提供強大的 API,支援各種遊戲,在 YouTube 上打造優質的遊戲體驗。
在遊戲中加入 Playables SDK
遊戲的根目錄應包含 index.html 檔案。在任何遊戲程式碼之前加入這行程式碼,匯入 YouTube Playables SDK:
<script src="https://www.youtube.com/game_api/v1"></script>
如果遊戲是在本機放送,SDK 會以無運算元的形式執行。如要驗證 SDK 整合是否正確,請參閱測試套件指南。
與 Playables SDK 整合
Playables SDK 包含多項必要和選用的整合功能。
必要整合項目
請詳閱發布規定,特別是整合規定。如需實作詳情,請參閱 Playables SDK 參考資料。
例如:
ytgame.game.firstFrameReady()ytgame.game.gameReady()ytgame.IN_PLAYABLES_ENVytgame.system.isAudioEnabled()ytgame.system.onAudioEnabledChange((isAudioEnabled) => {})ytgame.system.onPause(() => {})ytgame.system.onResume(() => {})ytgame.game.loadData()ytgame.game.saveData(data)
建議的整合項目
除了必要整合功能外,您還可以使用其他功能,打造高度吸引人的體驗。例如:
ytgame.system.getLanguage()- 使用這項函式擷取使用者目前的語言代碼設定。請勿使用其他函式或將語言儲存在雲端儲存空間,因為這項設定隨時可能變更。ytgame.engagement.sendScore({ value: newScore })- 將最高得分傳送至 YouTube 顯示。ytgame.engagement.openYTContent({ id: videoID }):開啟 YouTube 影片。ytgame.health.logError()和ytgame.health.logWarning()- 將問題記錄到 YouTube。ytgame.ads.requestInterstitialAd()和requestRewardedAd(rewardId: string)- 將廣告功能整合至遊戲。
如要瞭解實作詳情和其他函式,請參閱 Playables SDK 參考資料。
TypeScript 型別定義
如果是使用 TypeScript 的遊戲,請下載型別定義。
範例遊戲
我們提供範例,說明如何整合 YouTube Playables SDK,包括純 JavaScript、Flutter 網頁、Godot 和 Unity。
使用測試套件測試遊戲
準備就緒後,即可使用測試套件驗證整合服務。如要瞭解如何操作,請參閱測試套件指南。