12. 运行示例(Samples~)
该包在 Samples~/ 中包含 3 个独立示例。
导入
Window → Package Manager → 选择 SusCore → 在 Samples 区域点击 Import 按钮。 导入后:Assets/Samples/SusCore/<version>/。
场景搭建
- 创建空
GameObject→ Add Component →UIDocument - Add Component → 示例脚本(
SusBootstrapExample、SusKeepAliveExample或CompExample) [RequireComponent(typeof(UIDocument))]保证 UIDocument 一定存在- 场景中必须有
EventSystem
Comp Example(v1.0.49+)
目标:
SetChildProp—— 传递字面量 prop(不区分大小写,会修改.Value)BindChildProp—— 响应式 prop(.sharq中的:variant="expr")- 检查子级
Prop<T>不会被新的副本替换
在代码中: 父组件(CompScreen)创建子组件 MockChild 并发送 props。 在 .sharq 中等价于 <sus:SusButton variant="secondary" :label="LabelProp" />。
SusBootstrap Example
目标:
SusBootstrap.Mount<T>()—— 类似于createApp().mount('#app')GetOrCreateOverlay()—— portal 渲染SusThemeService.Instance.SetTheme(root, theme)—— 在级联根节点上设置 dark/light 主题类
控制方式: 按键 D(Dark)、L(Light)、T(显示 Tooltip)、O(切换 Overlay)。
SusKeepAlive Example
目标:
SusKeepAlive.Wrap(element)—— DOM 缓存Active开关 —— 通过display:none隐藏
无需操作 —— 自动运行。每秒输出:
[KeepAlive] Active=True (visible)
[KeepAlive] Active=False (hidden — DOM preserved)诊断
| 现象 | 原因 | 解决方法 |
|---|---|---|
| 按键不起作用 | 焦点不在 Game 视图 | 点击 Game 视图 |
| 什么都没显示 | UIDocument 没有 PanelSettings | 脚本会自行提示 |
| 示例未被导入 | Package Manager 缓存 | 移除后重新安装 |