update 0.6.7-preview
This commit is contained in:
@@ -0,0 +1,236 @@
|
||||
# Xeric Pawn V3 使用手册
|
||||
|
||||
## 1. 适用版本与代码位置
|
||||
|
||||
- Unity 2021.3.2f1 及以上;`Release/Runtime/XericLibrary.dll` 与 `Release/Editor/XericLibraryEditor.dll`。
|
||||
- 运行时代码:`Developer/XericLibrary/Player/`、`Developer/XericLibrary/Parameter/`。
|
||||
- 编辑器代码:`Developer/XericLibraryEditor/Player/`、`Developer/XericLibraryEditor/Parameter/`。
|
||||
- 新输入系统适配器只存在于 `Release/Runtime/Player/Input/PawnInputSource_InputSystem.cs`,核心输入框架不引用 Input System。
|
||||
|
||||
## 2. 快速创建
|
||||
|
||||
Hierarchy 右键:
|
||||
|
||||
- `GameObject/Xeric Library/Player/Create Controller`:新建角色根节点并创建控制器。
|
||||
- `GameObject/Xeric Library/Player/Attach Controller To Selection`:把控制器附加到当前选中物体。
|
||||
|
||||
创建流程会:
|
||||
|
||||
1. 从自身、直接子级、后代中查找可用相机;找不到时创建 `CameraPivot/Camera`。
|
||||
2. 查找 `CharacterController`,没有则补一个,并按模型包围盒拟合半径/高度/中心。
|
||||
3. 添加 `XericPawnController` 与 `XericParameterHub`。
|
||||
4. 写入默认四种移动模式:`Grounded`、`Fly`、`Swim`、`GodView`。
|
||||
5. 若存在 Animator,添加 `XericAnimatorEventRelay` 与 `XericAnimatorStateRelay`,并建立 `Pawn/Speed`、`Pawn/Grounded`、`Pawn/VerticalSpeed`、`Pawn/ModeId` 参数绑定和 `Pawn/ModeState` 状态绑定。
|
||||
6. 在相机上添加 `PawnCameraRig`,绑定控制 pivot 与相机根节点。
|
||||
|
||||
## 3. 组件清单与必要性
|
||||
|
||||
| 组件 | 是否必要 | 说明 |
|
||||
| --- | --- | --- |
|
||||
| `XericPawnController` | 必要 | 运动、输入采样、模式、黑板键与事件的核心。 |
|
||||
| `CharacterController` | 条件必要 | 默认后端需要;运行时缺失会自动补。切到 `CapsuleSweep` 后会禁用同物体上的它,并创建隐藏代理。 |
|
||||
| `XericParameterHub` | 可选 | 只有需要把黑板推给 Animator / 材质 / XSSS / 组件 / UnityEvent 时才需要。没有 Hub 时控件仍会写黑板。 |
|
||||
| `PawnCameraRig` | 玩家可选 | 玩家视角需要;AI 角色可以没有相机和该组件。 |
|
||||
| `XericAnimatorEventRelay` | 可选 | 需要动画事件回写黑板时才需要。 |
|
||||
| `XericAnimatorStateRelay` | 可选 | 需要把当前动画状态写回黑板时才需要。 |
|
||||
| `PawnMediumTrigger` | 可选 | 区域介质(水、草、低重力区)切换 `Medium`。需要 Trigger Collider。 |
|
||||
| `Camera` / `CameraPivot` | 玩家可选 | 玩家视角需要;纯 AI 或逻辑角色可以没有。 |
|
||||
|
||||
### 动态补齐行为
|
||||
|
||||
- 编辑器创建菜单会一次性补齐上述组件,方便直接运行。
|
||||
- 运行时 `Awake` 只创建纯 C# 工具对象、输入解析器、输入源与运动后端,不会自动添加 `XericParameterHub`、相机或 Relay。
|
||||
- `PawnMotorFactory` 在 `CharacterController` 后端发现同物体没有 `CharacterController` 时,会在运行期自动 `AddComponent` 并输出警告。
|
||||
- `CapsuleSweepPawnMotor` 在运行期创建 `__PawnCapsuleProxy`(`HideAndDontSave`)并添加 `CapsuleCollider`,因此该后端不要求场景物体自带胶囊碰撞体。
|
||||
- `PawnRig.AutoBind` 会补齐空引用:身体根、相机、pivot、Animator、主 Renderer。显式赋值优先。
|
||||
|
||||
## 4. 输入体系
|
||||
|
||||
### 4.1 绑定表
|
||||
|
||||
`PawnInputBindingTable` 是内联序列化对象,`Bindings` 中每一项是动作:
|
||||
|
||||
- `ActionId`:动作名,见 `PawnInputActions`。
|
||||
- `ValueKind`:`Axis` 或 `Button`。
|
||||
- `Channels`:同一动作的多条来源通道,可混合旧输入、新输入、程序与自定义源。
|
||||
- `DeadZone`、`EnableTap`、`EnableDoubleClick`、`EnableLongPress`、`DoubleClickTime`、`LongPressTime`。
|
||||
|
||||
默认动作:`MoveX/MoveY/LookX/LookY/Jump/Sprint/Crouch/Fly/Swim/Interact/GodView`。
|
||||
|
||||
### 4.2 输入源与合并规则
|
||||
|
||||
| 来源 | 说明 |
|
||||
| --- | --- |
|
||||
| `Legacy` | 唯一直接调用 `UnityEngine.Input` 的源。Active Input Handling 为 New only 时自动判定不可用。 |
|
||||
| `InputSystem` | Release 侧适配器,通过 `PawnInputSourceRegistry` 注册;Action 值为 0 时回退单控件/activeControl。 |
|
||||
| `Program` | 代码/AI 写入轴、按钮与脉冲;脉冲到帧末清空。 |
|
||||
| `Custom` | 由外部 `IPawnInputSourceProvider` / `IPawnInputSource` 提供。 |
|
||||
|
||||
`PawnInputResolver` 对同一动作的多条通道逐帧采样:轴取绝对值最大者,按钮取任意通道按下。`Program` 源对某个动作存在覆盖时,只允许该动作的 `Program` 通道参与,其他通道被抑制;没有覆盖的动作仍会读取旧输入。
|
||||
|
||||
### 4.3 输入配置资产
|
||||
|
||||
`PawnInputProfile` 是可创建的 ScriptableObject(菜单 `Create/Xeric Library/Player/Input Profile`):
|
||||
|
||||
- `Bindings`:该配置使用的绑定表;为空表示不产生任何输入。
|
||||
- `AllowLegacy`:是否创建旧输入源。
|
||||
- `AllowInputSystem`:是否创建新输入系统适配器。
|
||||
- `AllowProgram`:是否允许程序/AI 写入。
|
||||
|
||||
把资产赋给 `XericPawnController.InputProfile` 后,控制器使用该资产覆盖内联 `InputBindings` 与输入源开关。AI 角色可以创建空绑定表并关闭 `AllowLegacy`/`AllowInputSystem`,只通过 `ProgramInput` 写入动作;这样不会读取玩家键盘鼠标。
|
||||
|
||||
Inspector 提供“使用默认绑定”“清空绑定”和通道统计;关闭某个来源但绑定表仍有该来源通道时,会提示这些通道将被忽略。
|
||||
|
||||
当前仍没有按玩家编号自动分配设备;`AllowLegacy`/`AllowInputSystem` 只控制来源开关,不区分设备。设备分派与脑插槽见 `PawnPluginRoadmap.md`。
|
||||
|
||||
### 4.4 多 Pawn 与 AI
|
||||
|
||||
`Scope` 只隔离黑板键,例如 `pawn/1001/Pawn/Speed` 与 `pawn/1002/Pawn/Speed`;它不会隔离设备输入。
|
||||
|
||||
当前限制:
|
||||
|
||||
- 两个都使用默认绑定表的 Pawn 会同时读取同一套键盘/鼠标。
|
||||
- 程序源可以覆盖它显式设置的动作,但不会自动屏蔽未覆盖动作的旧输入。
|
||||
|
||||
AI 或本地多人的安全做法:
|
||||
|
||||
- 给 AI Pawn 使用只包含 `Program` / `Custom` 通道的绑定表,并关闭 `PawnInputProfile.AllowLegacy` / `AllowInputSystem`。
|
||||
- 玩家 Pawn 使用玩家输入配置;每个 Pawn 的 `ProgramInput.SetAxis/SetButton/Pulse` 独立。
|
||||
- 需要按玩家编号分配设备时,等待完整输入配置(见 `PawnPluginRoadmap.md`);当前没有内置设备分派。
|
||||
|
||||
## 5. 移动模式与零代码切换
|
||||
|
||||
### 5.1 模式对象
|
||||
|
||||
`PawnMovementMode` 是 `[Serializable]` 纯数据对象,通过 `[SerializeReference]` 存在控制器上。每个模式有:
|
||||
|
||||
- `ModeId`、`DisplayName`、`AnimatorStateName`、`AnimatorModeValue`。
|
||||
- `OnEnter/OnExit/CanEnter/Evaluate`。
|
||||
- `Evaluate` 只产出 `PawnMoveIntent`,不直接写 Transform 或碰撞后端。
|
||||
|
||||
内置模式:`PawnGroundedMoveMode`、`PawnFlyMoveMode`、`PawnSwimMoveMode`、`PawnGodViewMode`。
|
||||
|
||||
`PawnModePresetAsset` 是 ScriptableObject 预设,可从一个控制器抓取模式配置并克隆到另一个控制器。
|
||||
|
||||
### 5.2 当前零代码能力
|
||||
|
||||
`PawnModeSwitchTool.Rules` 可在 Inspector 配置:
|
||||
|
||||
- `ActionId`:输入动作。
|
||||
- `Kind`:`Press`、`DoubleClick`、`LongPress`、`Hold`。
|
||||
- `TargetModeId`:目标模式。
|
||||
|
||||
这是无代码的“按键 → 模式”切换。Animator 参数与状态也通过 `XericParameterHub` 的绑定表配置,无需写代码。
|
||||
|
||||
### 5.3 尚未零代码的部分
|
||||
|
||||
当前模式切换规则只支持输入触发,不支持“黑板键比较 / 是否着地 / 介质 / 速度阈值”等条件组合。完整的条件转移表设计见 `PawnPluginRoadmap.md` 的“零代码状态切换”。
|
||||
|
||||
## 6. 参数中枢
|
||||
|
||||
### 6.1 绑定表
|
||||
|
||||
`XericParameterHub` 在 Inspector 中维护绑定行:
|
||||
|
||||
- `RelativeKey`:相对黑板键,最终键为 `Scope + "/" + RelativeKey`。
|
||||
- `ValueKind`:Float / Int / Bool / String / Vector2/3/4 / Color / Enum。
|
||||
- `Direction`:Push / Pull / Both。
|
||||
- `Target`:AnimatorParameter / AnimatorState / Material / StyleSheet / ComponentMember / UnityEvent。
|
||||
- `TargetName`、`TargetSubName`、`AxisMask`、`Scale`、`Offset`、`Enabled`、`TriggerOnWrite`、`CrossFadeState`。
|
||||
|
||||
运行时 Hub 会注册键、生产者、消费者并订阅变更;Push 成功后标记消费,Pull 从目标读回黑板。`BroadcastChanges` 开启时会向 `XericEventBus` 发布 `bb/{path}`。
|
||||
|
||||
### 6.2 Pawn 键
|
||||
|
||||
每个 Pawn 在 `Scope` 下注册:
|
||||
|
||||
| 键 | 类型 | 说明 |
|
||||
| --- | --- | --- |
|
||||
| `Input/MoveX`、`Input/MoveY` | Float | 移动轴。 |
|
||||
| `Input/LookX`、`Input/LookY` | Float | 视角轴。 |
|
||||
| `Input/Jump` 等按钮 | Bool | 动作按下状态。 |
|
||||
| `Pawn/Speed` | Float | 水平速度。 |
|
||||
| `Pawn/VerticalSpeed` | Float | 垂直速度。 |
|
||||
| `Pawn/Grounded` | Bool | 是否着地。 |
|
||||
| `Pawn/ModeState` | String | 当前模式动画状态名。 |
|
||||
| `Pawn/ModeId` | Int | 当前模式编号。 |
|
||||
|
||||
### 6.3 XSSS 导入与播种
|
||||
|
||||
`XericParameterHub` Inspector 支持:
|
||||
|
||||
- `Seed From XSSS`:把命名空间下的参数写入黑板初值,写入者为 `XSSS.Seed`。
|
||||
- `Import Bindings`:读取 `@Target`、`@Name`、`@Key`、`@Kind`、`@Direction`、`@Slot`、`@Layer`、`@Type` 注解生成绑定行。
|
||||
- 样例:`Release/Samples~/PlayerParameters/PlayerParameters.xsss`。
|
||||
|
||||
XSSS 是静态配置源,不作为多实例每帧状态存储;多实例运行时值写在黑板。
|
||||
|
||||
### 6.4 监视与调试
|
||||
|
||||
- 菜单:`XericLibrary/Blackboard Monitor`。
|
||||
- 列:Path、Layer、存在、只读、Kind、暂存值、Rev、删除Rev、最后写入、消费、生产者、消费者、目标。
|
||||
- 过滤:路径包含、仅未消费、仅已注册、仅运行时层;支持清空筛选、复制行、自动刷新。
|
||||
- Hub Inspector 的“调试”折叠区可查看运行时绑定,并用“写入探针”直接测试只读/冻结/成功/失败结果。
|
||||
|
||||
### 6.5 层与作用域
|
||||
|
||||
- 键身份是 `(Layer, Key)`;`$env.activeHost` 与 `$bb.activeHost` 是两个不同键。
|
||||
- 运行时状态默认写 Runtime 层;静态配置可写 Environment 层。
|
||||
- 读取默认精确层;`$bb` 回退 Environment 需要显式开启。
|
||||
- `Remove` 会把 `Exists` 置 false、记录 `RemovedRevision` 并归零消费版本;`Clear` 按层推进 epoch,Hub 收到后停止推送旧值。
|
||||
|
||||
## 7. Animator 事件与状态回写
|
||||
|
||||
`XericAnimatorEventRelay` 挂在 Animator 同物体,Animation 窗口添加同名事件:
|
||||
|
||||
- `XericEventString(string)`
|
||||
- `XericEventInt(int)`
|
||||
- `XericEventFloat(float)`
|
||||
- `XericEvent()`
|
||||
|
||||
`Rows` 可配置 payload → 键/值/层;未配置时使用 `KeyPrefix + payload`。写入者为 `Animator.Event`。
|
||||
|
||||
`XericAnimatorStateRelay` 按 `PollInterval` 轮询当前动画剪辑名,写到 `Anim/State/{layer}`,写入者为 `Animator.State`。
|
||||
|
||||
## 8. 相机与外部 Rig
|
||||
|
||||
`PawnCameraRig` 支持:
|
||||
|
||||
- 自身驱动 pivot/相机。
|
||||
- `ExternalRigTypeNames` 类型名探测(Cinemachine、HDRP 电影机、摇臂等)。
|
||||
- `DriveMode = ExternalRig` 强制外部接管。
|
||||
|
||||
外部 Rig 激活时,`XericPawnController` 停止写视角,避免与电影机/摇臂抢控制。控制器只保留移动与 pivot 数据。
|
||||
|
||||
## 9. 扩展方式
|
||||
|
||||
- **新模式**:继承 `PawnMovementMode`,实现 `Evaluate`,在控制器 `Modes` 列表中添加;只产出意图,不写 Transform。
|
||||
- **新输入源**:实现 `IPawnInputSource` 与 `PawnInputSourceProvider`,调用 `PawnInputSourceRegistry.Register`。
|
||||
- **新目标适配器**:实现 `IParameterTargetAdapter`,调用 `ParameterTargetRegistry` 注册。
|
||||
- **自定义黑板根**:通过 `XericBlackboardPath.RegisterRoot` 提供 `$anim/$mat/$xsss/$comp` 之外的只读根。
|
||||
- **行为树接入**:当前可通过 `XericPawnController.ProgramInput` 写入动作;完整 Brain 插件与输入配置资产见设计文档。
|
||||
|
||||
## 10. 故障排查
|
||||
|
||||
| 现象 | 检查 |
|
||||
| --- | --- |
|
||||
| 角色不动 | 是否有 `CharacterController`;是否被禁用;`Tuning.CollisionMask` 是否包含地面;输入源是否可用。 |
|
||||
| 两个角色一起动 | 两个 Pawn 是否都保留 Legacy 通道;为 AI 改用仅 Program/Custom 的绑定表。 |
|
||||
| Animator 参数不动 | Hub 是否有绑定;Animator 是否有同名参数;Monitor 中键是否 Exists 且被消费。 |
|
||||
| 动画状态不切换 | `CrossFadeState` 是否开启;目标状态是否存在;先用 `Animator.Play` 验证。 |
|
||||
| 黑板键没有消费者 | Hub 是否启用;绑定 `Enabled` 是否为 true;目标是否解析成功。 |
|
||||
| 写入失败 | 是否只读、Environment 是否冻结、键是否注册;用 Hub Inspector 写入探针确认 Failure。 |
|
||||
| 相机被电影机抢写 | `PawnCameraRig` 是否识别到外部 Rig;必要时切换 `DriveMode = ExternalRig`。 |
|
||||
|
||||
## 11. 验证命令
|
||||
|
||||
```bash
|
||||
dotnet run --project "Developer/XericLibrary/Type/Blackboard/Tests~/BlackboardHarness/BlackboardHarness.csproj"
|
||||
dotnet run --project "Developer/XericLibrary/Player/Tests~/PlayerHarness/PlayerHarness.csproj"
|
||||
```
|
||||
|
||||
完整黑板门禁:`bash "Developer/XericLibrary/Type/Blackboard/Tests~/BlackboardHarness/run.sh"`。
|
||||
|
||||
## 12. 相关设计
|
||||
|
||||
- 插件化控制器、输入配置资产、零代码条件转移、阵营与伤害、行为树/状态树接入:`PawnPluginRoadmap.md`。
|
||||
Reference in New Issue
Block a user