Mini Dapp SDK 整合
在本節中,我們將確保在遊戲中載入 Mini Dapp SDK。 要做到這一點,Cocos Creator 的 build-templates 目錄允許自訂網頁平台的遊戲建置方式,使其成為遊戲開始前預先載入 SDK 的必要工具。
透過在 build-templates/web-desktop 中建立自訂範本,我們可以在每次建立時自動包含 SDK,簡化開發與部署。
步驟 1:建立 build-templates 目錄
在 VS Code 中開啟您的專案,並在終端執行下列指令:
mkdir -p build-templates/web-desktop
步驟 2:在 Cocos Creator 中執行初始建置
- 移至 功能表 → 專案 → 建立。
-
將 Platform 設為 Web Desktop。
-
按一下 ** 建立**。
步驟 3:從建立目錄複製 index.html 檔案
建立完成後,將 index.html 檔案複製到 build-templates 目錄:
cp build/web-desktop/index.html build-templates/web-desktop/
步驟 4:修改 index.html 以包含 Mini Dapp SDK
編輯 build-templates/web-desktop/index.html
並在 <head> </head>
區段內加入下列 Mini Dapp SDK 程式碼標籤:
<script src="https://static.kaiawallet.io/js/dapp-portal-sdk.js"></script>