123 lines
4.8 KiB
Markdown
123 lines
4.8 KiB
Markdown
# ShrinkSDK Workspace
|
||
|
||
ShrinkSDK 是一组可独立组合的 Unity / Godot C# 运行时模块。共享内核以 `netstandard2.1` 为最低目标;Unity 侧支持 Unity 2022.3,Godot 侧首期支持 Godot 4.6.3 Mono 和桌面平台。
|
||
|
||
Workspace 用于跨包集成、Unity 场景验证、Godot 消费者验证和 CodeGen 织入测试。每个 `Assets/Modules/<Module>` 是独立公开仓库的 Git submodule;根仓库保留相邻 `.meta`,不要删除或重新生成这些文件。
|
||
|
||
## 获取 Workspace
|
||
|
||
```text
|
||
git clone --recurse-submodules https://git.crash.work/ShrinkSDK/Workspace.git
|
||
cd Workspace
|
||
git submodule update --init --recursive
|
||
```
|
||
|
||
所有 Unity 模块都可以独立打开其 `Development~/UnityProject`。根 Workspace 用于跨包组合与验收;Godot 综合示例位于 `Godot/Samples/ShrinkSDK.Godot.Sample`。
|
||
|
||
## Unity 安装与使用
|
||
|
||
### 通过 Installer 安装
|
||
|
||
在 Unity Package Manager 中选择 **Add package from git URL**,添加:
|
||
|
||
```text
|
||
https://git.crash.work/ShrinkSDK/Installer.git#main
|
||
```
|
||
|
||
正式项目应在对应版本发布后把 `main` 换成固定 tag。安装完成后打开 `ShrinkSDK/包管理`,选择单个模块或推荐组合。Installer 会合并 ShrinkSDK scoped registry、安装精确版本依赖,并分别显示未安装、可升级、已安装和已安装较新版本;不会把较新版本降级到目录版本。
|
||
|
||
### 手工安装
|
||
|
||
也可以在消费者项目的 `Packages/manifest.json` 中保留原有内容并加入 registry:
|
||
|
||
```json
|
||
{
|
||
"scopedRegistries": [
|
||
{
|
||
"name": "ShrinkSDK",
|
||
"url": "https://git.crash.work/api/packages/ShrinkSDK/npm/",
|
||
"scopes": ["com.cneicy"]
|
||
}
|
||
],
|
||
"dependencies": {
|
||
"com.cneicy.shrink-app-starter-basic": "0.3.0"
|
||
}
|
||
}
|
||
```
|
||
|
||
如果项目已经有 `scopedRegistries` 或 `dependencies`,只合并对应条目,不要覆盖原有配置。Git 安装同样建议固定 tag,例如:
|
||
|
||
```text
|
||
https://git.crash.work/ShrinkSDK/ShrinkEventBus.git#v2.1.0
|
||
```
|
||
|
||
### 快速开始
|
||
|
||
安装 `ShrinkApp.Starter.Basic` 后,执行 `ShrinkSDK/应用/基础起步/创建默认 Context 组合`。菜单会生成默认配置和入口场景;打开 `Assets/Scenes/ShrinkAppEntry.unity` 即可运行 Command、DataSaver、Network 和 App 的基础组合。
|
||
|
||
EventBus、Command、Network 和 App 的特性注册由 Unity ILPostProcessor 在编译期织入,不需要运行时反射扫描或手工维护注册表。修改带 ShrinkSDK 特性的代码后,等待 Unity 完成重新编译,再进入 Play Mode。
|
||
|
||
## Godot 4.6 C# 安装与使用
|
||
|
||
Godot 项目需要 Godot 4.6.3 Mono 和 .NET 8 SDK。使用现有 Workspace 验证时,直接用 Godot 打开:
|
||
|
||
```text
|
||
Godot/Samples/ShrinkSDK.Godot.Sample/project.godot
|
||
```
|
||
|
||
外部 Godot C# 项目通过 NuGet 使用 ShrinkSDK。先在项目级 `NuGet.Config` 中加入软件源:
|
||
|
||
```xml
|
||
<?xml version="1.0" encoding="utf-8"?>
|
||
<configuration>
|
||
<packageSources>
|
||
<add key="ShrinkSDK" value="https://git.crash.work/api/packages/ShrinkSDK/nuget/index.json" />
|
||
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
|
||
</packageSources>
|
||
</configuration>
|
||
```
|
||
|
||
然后为 Godot 的 `.csproj` 安装宿主和需要的模块,例如:
|
||
|
||
```powershell
|
||
dotnet add package ShrinkSDK.Godot --version 0.1.0
|
||
dotnet add package ShrinkSDK.App.Starter.Basic --version 0.3.0
|
||
dotnet add package ShrinkSDK.EventBus --version 2.1.0
|
||
dotnet restore
|
||
dotnet build
|
||
```
|
||
|
||
需要自动注册的包会传递引入 `ShrinkSDK.CodeGen`。CodeGen 默认在 `CoreCompile` 后织入当前项目程序集;构建日志应出现 `[ShrinkSDK.CodeGen]`,无需额外添加 Source Generator、反射扫描或手工注册表。
|
||
|
||
主场景根节点可继承 `ShrinkGodotHost`:
|
||
|
||
```csharp
|
||
using Cysharp.Threading.Tasks;
|
||
using ShrinkSDK.Godot;
|
||
|
||
public partial class GameRoot : ShrinkGodotHost
|
||
{
|
||
public override void _Ready()
|
||
{
|
||
base._Ready();
|
||
StartAsync().Forget();
|
||
}
|
||
|
||
private async UniTaskVoid StartAsync()
|
||
{
|
||
RequireWoven(GetType().Assembly);
|
||
await StartAppAsync();
|
||
}
|
||
}
|
||
```
|
||
|
||
`ShrinkGodotHost` 在 `_Ready` 中安装平台服务,在 `_Process` 中泵送主线程和网络队列,并转发暂停、恢复与退出生命周期。Godot Installer 插件的安装、包管理面板、CodeGen 状态和命令行验证方式见 [Godot/README.md](Godot/README.md)。
|
||
|
||
## 开发与发布
|
||
|
||
发布、子模块迁移和独立开发宿主生成规则位于 [Tools/RepositoryMigration/Initialize-ShrinkSdkPackageRepositories.ps1](Tools/RepositoryMigration/Initialize-ShrinkSdkPackageRepositories.ps1)。架构约束与跨包验证要求见 [DESIGN.md](DESIGN.md)。
|
||
|
||
## 第三方与合规
|
||
|
||
概念参考(NeoForge / Minecraft Forge、MessagePipe)与随仓库分发的第三方二进制(Kcp-CSharp.dll 等)的许可证遵从情况见 [THIRD-PARTY-NOTICES.md](THIRD-PARTY-NOTICES.md)。
|