.sharq 格式
.sharq 文件是面向 Unity UI Toolkit 的类 Vue SFC — 一个文件包含三个部分:
| 部分 | 作用 |
|---|---|
<template> | 标记 + 指令(v-if、:text、@click 等) |
<script> | C# 逻辑、Prop<T>、方法 |
<style> | USS 样式(可选 <style scoped>) |
xml
<template>
<ui:VisualElement $MainElement class="hello">
<ui:Label :text="Title.Value" class="hello__label" />
</ui:VisualElement>
</template>
<script>
public Prop<string> Title = new("Hello");
</script>
<style>
/* Prefer USS classes here — not element.style.* in C# */
.hello__label {
font-size: 16px;
color: white;
padding: 8px;
}
</style>为什么 <style> 很重要
- 样式随组件一起发布(与 Vue SFC 的心智模型相同)。
- 编译器从这一部分生成
.g.uss/ scoped USS。 - 使用类 + 修饰符;通过
:class/AddToClassList切换。 - Root 自身选择器规则(
.hello { … })需要小心处理 — 参见 CSS scoping。
完整指南: .sharq 格式 · CSS scoping