WebGL Demo GitHub
WebGL Demo Gitee
原理
其实就是用上了 Github Action
自动构建和 Github Pages
首先手动确保自己的项目可以构建出 WebGL 项目并运行
- 在工程根目录新建
docs
, 并建立一个名为.nojekyll
文件
docs
└── .nojekyll
其中
.nojekyll
作用是告诉Github Pages
不是jekyll
项目
-
构建之前确保自己项目中的发布压缩格式选择为
已禁用
-
在
Unity Editor
中构建并运行, 目录选择docs
得到下列目录结构
docs
├── Build
│ ├── docs.data
│ ├── docs.framework.js
│ ├── docs.loader.js
│ └── docs.wasm
├── index.html
└── TemplateData
├── favicon.ico
├── fullscreen-button.png
├── progress-bar-empty-dark.png
├── progress-bar-empty-light.png
├── progress-bar-full-dark.png
├── progress-bar-full-light.png
├── style.css
├── unity-logo-dark.png
├── unity-logo-light.png
└── webgl-logo.png
- 推送项目, 并且启用,
Github Pages
- 在仓库页面点击
Settings
- 左侧倒数第二点击
Pages
- 看到一个
None
的下拉框, 选中gh-pages
主分支, (当然可以是任意分支, 类似master
或者main
) - 修改后面的
/(root)
为docs
- 点击
save
保存即可 - 等待片刻可以看到自己的在线游戏页面
- 在仓库页面点击
以上就算是完成了如何发布 WebGL 游戏到 Github Pages
利用 Github Pages
完成以上复杂的种种操作
首先在根目录创建以下内容
.github
└── workflows
├── getManualLicenseFile.yml
└── main.yml
在 main.yml
内填入
name: 构建🍳 → 发布🍻
on:
workflow_dispatch: {
}
push:
branches:
- main
paths:
- "Assets/**"
- "Packages/**"
- "ProjectSettings/**"
jobs:
buildWithLinux:
name: 为 ${
{
matrix.targetPlatform }} 平台构建 🍳
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
targetPlatform:
# - Android
- WebGL
outputs:
targetPlatform: $