Stride CLI
中级
Stride CLI 是一个允许通过命令行使用 Stride 的工具。制作游戏并非必须使用它,但对于喜欢终端的开发者来说,它是一个实用的工具。
Stride CLI 功能:
- 管理已安装的引擎版本
- 创建新项目
- 更新项目
- 启动 Game Studio
- 运行资产编译器
- 可替代 Stride 启动器
Warning
尽管 CLI 工具可以替代启动器,但仍建议安装启动器,因为其中还包含引擎所需的前置组件。
安装 Stride CLI
CLI 工具可通过 nuget 在所有平台上使用,可以直接通过命令行安装。
dotnet tool install -g stride.cli
安装后,可能需要重新打开终端才能使 stride 命令生效。可以通过运行以下命令检查是否正常工作:
stride --version
Warning
如果命令仍然无法使用,可能需要将 dotnet 工具所在的目录添加到系统的 Path 环境变量中。
使用 Stride CLI
CLI 包含多个提供不同功能的命令。不带任何参数运行 stride 可以查看所有命令。
stride
| 命令 | 说明 |
|---|---|
stride sdk |
管理已安装的 Stride 版本(列出、可用版本、安装、卸载、更新)。更多信息请参阅版本管理章节。 |
stride new |
使用已安装 Stride 版本的模板创建项目。更多信息请参阅创建新项目章节。 |
stride upgrade |
将项目升级到更新的已安装 Stride 版本。更多信息请参阅更新 Stride — 使用 Stride CLI 更新项目。 |
stride studio |
打开 Game Studio。 |
stride crash |
列出、查看和发送 Stride 无头工具保存的崩溃报告。 |
stride legacy |
列出旧版(4.4 之前)Stride 项目保留的命令。 |
stride self |
管理 Stride CLI 本身。 |
stride version |
显示 Stride CLI 版本和解析到的 Stride 版本。 |
stride asset |
直接运行 Stride 资产编译器(高级用法;参数将被转发)。 |
如需了解某个命令的详细用法,请使用 --help 标志。例如:
stride sdk --help
创建新项目
以下是使用 CLI 在最新版引擎上创建新项目的示例。
stride sdk install # 安装最新版本
stride new game -n ProjectX && cd ProjectX # 创建新项目并进入其目录
dotnet run --project ProjectX.Windows # 构建并运行项目
stride studio # 打开 Game Studio
All Stride templates can take additional parameters to change how they are created. Here's a list of the most commonly used ones:
| Parameter | Values | Description |
|---|---|---|
-n |
text | Name of the project. |
--platform |
host (the current os), window, linux, macos, android, ios |
Platform(s) the project should target, separated by the | character. |
--HDR |
true, false |
Determines if the project uses HDR (required graphics profile >= 10.0). |
--graphics-profile |
9.0, 10.0, 11.0, ... |
The graphics profile to use. This can be changed later. |
--orientation |
Default, LandscapeLeft, LandscapeRight, Portrait |
The game's orientation on mobile devices. This can be changed later. |
For a list of all available parameters in a template, use the --help flag.
Example command:
stride new game -n ProjectX --HDR true --platform windows`|linux
更详细的说明请参阅创建项目 — 使用 Stride CLI 创建项目。
版本管理
如前所述,Stride CLI 允许您直接通过命令行完成启动器的所有操作。
stride sdk available --prerelease # List all available versions, including betas
stride sdk install # Install the latest version
stride sdk update # Update all installed versions to the latest patch.
stride sdk uninstall 4.3 # Unintall Stride 4.3
| Command | Description |
|---|---|
stride sdk install |
Install the latest version of the engine or the resolved project's version located in the current directory. |
stride sdk install VERSION |
Install a specific version of the engine. Version patch number is optional. |
stride sdk available |
List available versions of the engine. |
stride sdk list |
List all installed versions. |
stride sdk update |
Update all installed versions of the engine to the latest patch. |
stride sdk update VERSION |
Update a specific installed version of the engine to the latest patch. Version patch number is optional. |
stride sdk uninstall VERSION |
Uninstall a specific version of the engine. |
Note
For many commands, the patch version can be skipped (e.g. 4.3).
Tip
The CLI will ignore beta versions of the engine, unless you pass the --prerelease flag.
将项目升级到新版本
CLI 可以像 Game Studio 一样升级项目。除了更改引擎版本外,它还会使用额外的工具修改资产和代码,确保一切正常工作。
stride upgrade # 将项目升级到最新版本
stride upgrade --prerelease # 包含 beta 版本
stride upgrade 4.3 # 将项目升级到 4.3
更多信息请参阅更新 Stride — 使用 Stride CLI 更新项目。