跳转到内容

12. 运行示例(Samples~)

该包在 Samples~/ 中包含 3 个独立示例。

导入

WindowPackage Manager → 选择 SusCore → 在 Samples 区域点击 Import 按钮。 导入后:Assets/Samples/SusCore/<version>/

场景搭建

  1. 创建空 GameObject → Add Component → UIDocument
  2. Add Component → 示例脚本(SusBootstrapExampleSusKeepAliveExampleCompExample
  3. [RequireComponent(typeof(UIDocument))] 保证 UIDocument 一定存在
  4. 场景中必须有 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 缓存移除后重新安装