A fast 2D and 3D game engine — TypeScript SDK, C++/WebAssembly core, visual editor. Ship one project to web, desktop, WeChat MiniGames, playable ads, and native Android / iOS.
TypeScript 2d-game-engine3d3d-game-engineandroidcppecsgame-editorgame-enginegamedeviostypescriptwebassemblywebglwebgpuwechat-minigame
docs: add v0.4.2 changelog and update UI/assets guides
esengine07e24962c79b
diff --git a/docs/astro/astro.config.mjs b/docs/astro/astro.config.mjsindex 566b08e66..e4918f60d 100644--- a/docs/astro/astro.config.mjs+++ b/docs/astro/astro.config.mjs@@ -88,6 +88,7 @@ export default defineConfig({label: 'Changelog',translations: { 'zh-CN': '更新日志' },items: [+ { label: 'v0.4.2', slug: 'changelog-v042' },{ label: 'v0.4.1', slug: 'changelog-v041' },{ label: 'v0.4.0', slug: 'changelog-v040' },{ label: 'v0.3.0', slug: 'changelog' },diff --git a/docs/astro/src/content/docs/changelog-v042.mdx b/docs/astro/src/content/docs/changelog-v042.mdxnew file mode 100644index 000000000..d84dd03d6--- /dev/null+++ b/docs/astro/src/content/docs/changelog-v042.mdx@@ -0,0 +1,52 @@+---+title: v0.4.2+description: ESEngine v0.4.2 release notes+---++import { Aside } from '@astrojs/starlight/components';++## UI Interaction System++- Added `Interactable` component to mark UI entities as interactive+- Added `Button` component with state machine (Normal, Hovered, Pressed, Disabled) and color transitions+- Added `UIInteraction` component tracking hover/press state (`hovered`, `pressed`, `justPressed`, `justReleased`)+- Added `UIEvents` resource with event queue — supports `click`, `press`, `release`, `hover_enter`, `hover_exit` events+- Added `UIInteractionPlugin` with hit testing against world-space `UIRect` bounds and layer-based ordering+- `createWebApp()` automatically registers the interaction plugin++## UIRect Anchor Layout++- Replaced single `anchor` field with full anchor-offset layout: `anchorMin`, `anchorMax`, `offsetMin`, `offsetMax`, `size`, `pivot`+- Added `UILayoutPlugin` that computes layout from camera bounds for `ScreenSpace` root entities and propagates through children+- Added `ScreenSpace` tag component for root UI entities that should be laid out relative to the camera+- Existing scenes automatically migrated to the new layout fields++## Addressable Assets++- Added `AddressableManifest` format with groups, addresses, labels, and asset metadata+- `AssetServer.loadByAddress(address)` — load a single asset by its address+- `AssetServer.loadByLabel(label)` — load all assets matching a label, returned as `AssetBundle`+- `AssetServer.loadGroup(groupName)` — load all assets in a group, returned as `AssetBundle`+- `AssetServer.setAddressableManifest(manifest)` — set the manifest and build address/label/group indexes+- Editor: added Addressable panel with group management, label editing, drag-move, and dependency analysis++## Asset Import Pipeline++- Added `ImporterRegistry` with type-specific import settings+- Added `TextureImporter` and `AudioImporter`+- `.meta` file format upgraded to v2.0 with automatic migration from v1++## Builder Refactoring++- Refactored build pipeline into two-stage architecture: `ArtifactBuilder` (shared build logic) + `PlatformEmitter` (platform-specific output)+- Shared build flow across all targets, platform logic cleanly separated++## Editor Improvements++- UIRect anchor preset editor with 9-point grid and 3 stretch presets+- Entity creation, deletion, and component changes now instantly sync to the running scene via Store-to-SceneManager events+- Compound commands for batched property changes++## Bug Fixes++- Batch renderer now binds white texture to all unused texture slots, fixing rendering artifacts on some GPUsdiff --git a/docs/astro/src/content/docs/guides/assets.mdx b/docs/astro/src/content/docs/guides/assets.mdxindex 69973a853..03d228ab4 100644--- a/docs/astro/src/content/docs/guides/assets.mdx+++ b/docs/astro/src/content/docs/guides/assets.mdx@@ -186,6 +186,50 @@ Absolute paths and full URLs are not affected by `baseUrl`.For Playable Ad builds, the editor's build pipeline automatically embeds all referenced assets as data URIs into the output bundle. At runtime, `assets.loadTexture()` / `assets.loadJson()` and other load calls resolve from the embedded data instead of fetching over the network — no code changes are needed.+## Addressable Assets++Addressable assets let you load resources by logical address, label, or group instead of raw file paths. The editor builds an `AddressableManifest` during the build process, which maps addresses and labels to asset paths.++### Loading by Address++```typescript+const texture = await assets.loadByAddress('player-idle');+```++### Loading by Label++Load all assets tagged with a label. Returns an `AssetBundle`:++```typescript+const bundle = await assets.loadByLabel('ui-sprites');+for (const [path, tex] of bundle.textures) {+ console.log(`Loaded ${path}: ${tex.width}x${tex.height}`);+}+```++### Loading by Group++Load all assets in a named group:++```typescript+const bundle = await assets.loadGroup('level-1');+```++### Setting the Manifest++The manifest is generated by the editor during build. At runtime, set it before loading:++```typescript+import { Assets } from 'esengine';++const manifest = await assets.loadJson('assets/addressable-manifest.json');+assets.setAddressableManifest(manifest);+```++<Aside type="note">+ Addressable addresses, labels, and groups are configured in the editor's Addressable panel. The manifest is generated automatically during build.+</Aside>+## Next Steps- [Materials & Shaders](/microes/guides/materials/) — custom shaders and blend modesdiff --git a/docs/astro/src/content/docs/guides/ui.mdx b/docs/astro/src/content/docs/guides/ui.mdxindex 09d252f5b..8b008d0ff 100644--- a/docs/astro/src/content/docs/guides/ui.mdx+++ b/docs/astro/src/content/docs/guides/ui.mdx@@ -37,10 +37,15 @@ In the scene editor: create an entity → add `LocalTransform`, `Sprite`, `Text`| Property | Type | Default | Description ||----------|------|---------|-------------|-| `size` | Vec2 | `{100, 100}` | Width and height of the UI rectangle |-| `anchor` | Vec2 | `{0.5, 0.5}` | Anchor point (0–1 range) |+| `anchorMin` | Vec2 | `{0.5, 0.5}` | Bottom-left anchor relative to parent (0–1 range) |+| `anchorMax` | Vec2 | `{0.5, 0.5}` | Top-right anchor relative to parent (0–1 range) |+| `offsetMin` | Vec2 | `{0, 0}` | Pixel offset from anchorMin |+| `offsetMax` | Vec2 | `{0, 0}` | Pixel offset from anchorMax |+| `size` | Vec2 | `{100, 100}` | Width and height (used when anchorMin equals anchorMax) || `pivot` | Vec2 | `{0.5, 0.5}` | Pivot point for rotation and scaling |+When `anchorMin` equals `anchorMax`, the element has a fixed `size` positioned at the anchor point. When they differ, the element stretches between the two anchors and `size` is computed automatically by `UILayoutPlugin`.+## Enums### TextAlign@@ -167,6 +172,102 @@ addSystem(defineSystem());```+## UI Interaction++ESEngine provides a built-in UI interaction system for handling hover, press, and click events on UI elements.++### Setup++Add the `Interactable` component to any UI entity with `UIRect` and `LocalTransform`. The `UIInteractionPlugin` (registered automatically by `createWebApp()`) performs hit testing each frame and manages interaction state.++### Interactable++Marks an entity as interactive.++| Property | Type | Default | Description |+|----------|------|---------|-------------|+| `enabled` | boolean | `true` | Whether interaction is enabled |++### Button++Adds a state machine on top of `Interactable` with optional color transitions.++| Property | Type | Default | Description |+|----------|------|---------|-------------|+| `state` | ButtonState | `Normal` | Current button state (read-only at runtime) |+| `transition` | ButtonTransition \| null | `null` | Color transition configuration |++**ButtonState:** `Normal` (0), `Hovered` (1), `Pressed` (2), `Disabled` (3)++When `transition` is set, the `Sprite` color is automatically updated on state change:++```typescript+import { Button, Interactable } from 'esengine';++world.insert(entity, Button, {+ state: 0,+ transition: {+ normalColor: { r: 1, g: 1, b: 1, a: 1 },+ hoveredColor: { r: 0.9, g: 0.9, b: 0.9, a: 1 },+ pressedColor: { r: 0.7, g: 0.7, b: 0.7, a: 1 },+ disabledColor: { r: 0.5, g: 0.5, b: 0.5, a: 0.5 },+ },+});+```++### UIInteraction++Automatically added by the plugin to entities with `Interactable`. Provides per-entity state:++| Property | Type | Description |+|----------|------|-------------|+| `hovered` | boolean | Pointer is over this entity |+| `pressed` | boolean | Entity is being pressed |+| `justPressed` | boolean | Press started this frame |+| `justReleased` | boolean | Press released this frame |++### UIEvents++The `UIEvents` resource collects interaction events each frame. Query it in systems:++```typescript+import { defineSystem, addSystem, Res } from 'esengine';+import { UIEvents } from 'esengine';++addSystem(defineSystem(+ [Res(UIEvents)],+ (events) => {+ for (const e of events.query('click')) {+ console.log('Clicked entity:', e.entity);+ }+ }+));+```++**Event types:** `click`, `press`, `release`, `hover_enter`, `hover_exit`++### ScreenSpace++A tag component for root UI entities. Entities with `ScreenSpace`, `UIRect`, and `LocalTransform` are laid out relative to the camera bounds by `UILayoutPlugin`.++```typescript+import { ScreenSpace, UIRect, LocalTransform } from 'esengine';++world.insert(entity, ScreenSpace);+world.insert(entity, UIRect, {+ anchorMin: { x: 0, y: 0 },+ anchorMax: { x: 1, y: 1 },+ offsetMin: { x: 0, y: 0 },+ offsetMax: { x: 0, y: 0 },+ size: { x: 100, y: 100 },+ pivot: { x: 0.5, y: 0.5 },+});+```++<Aside type="note">+ Both `UILayoutPlugin` and `UIInteractionPlugin` are registered automatically by `createWebApp()`. No manual setup is needed.+</Aside>+## Next Steps- [Components](/microes/core-concepts/components/) — all builtin componentsdiff --git a/docs/astro/src/content/docs/zh/changelog-v042.mdx b/docs/astro/src/content/docs/zh/changelog-v042.mdxnew file mode 100644index 000000000..0f3af43d0--- /dev/null+++ b/docs/astro/src/content/docs/zh/changelog-v042.mdx@@ -0,0 +1,52 @@+---+title: v0.4.2+description: ESEngine v0.4.2 更新日志+---++import { Aside } from '@astrojs/starlight/components';++## UI 交互系统++- 新增 `Interactable` 组件,标记 UI 实体为可交互+- 新增 `Button` 组件,包含状态机(Normal、Hovered、Pressed、Disabled)和颜色过渡+- 新增 `UIInteraction` 组件,追踪悬停/按压状态(`hovered`、`pressed`、`justPressed`、`justReleased`)+- 新增 `UIEvents` 资源和事件队列 — 支持 `click`、`press`、`release`、`hover_enter`、`hover_exit` 事件+- 新增 `UIInteractionPlugin`,基于世界空间 `UIRect` 边界进行命中检测,支持层级排序+- `createWebApp()` 自动注册交互插件++## UIRect 锚点布局++- 单一 `anchor` 字段替换为完整的锚点-偏移布局:`anchorMin`、`anchorMax`、`offsetMin`、`offsetMax`、`size`、`pivot`+- 新增 `UILayoutPlugin`,从相机边界计算 `ScreenSpace` 根实体布局并向子实体传播+- 新增 `ScreenSpace` 标签组件,用于标记相对相机布局的根 UI 实体+- 现有场景自动迁移至新布局字段++## Addressable 资产++- 新增 `AddressableManifest` 格式,包含分组、地址、标签和资产元数据+- `AssetServer.loadByAddress(address)` — 按地址加载单个资产+- `AssetServer.loadByLabel(label)` — 按标签加载所有匹配资产,返回 `AssetBundle`+- `AssetServer.loadGroup(groupName)` — 按分组加载所有资产,返回 `AssetBundle`+- `AssetServer.setAddressableManifest(manifest)` — 设置清单并构建地址/标签/分组索引+- 编辑器:新增 Addressable 面板,支持分组管理、标签编辑、拖拽移动和依赖分析++## 资产导入管线++- 新增 `ImporterRegistry`,支持按类型的导入设置+- 新增 `TextureImporter` 和 `AudioImporter`+- `.meta` 文件格式升级至 v2.0,自动从 v1 迁移++## Builder 重构++- 构建管线重构为两阶段架构:`ArtifactBuilder`(共享构建逻辑)+ `PlatformEmitter`(平台特定输出)+- 所有目标共享构建流程,平台逻辑清晰分离++## 编辑器改进++- UIRect 锚点预设编辑器,包含 9 点网格和 3 种拉伸预设+- 实体创建、删除和组件变更通过 Store-to-SceneManager 事件即时同步到运行中的场景+- 批量属性变更支持组合命令++## Bug 修复++- 批处理渲染器现在为所有未使用的纹理槽绑定白色纹理,修复部分 GPU 上的渲染伪影diff --git a/docs/astro/src/content/docs/zh/guides/assets.mdx b/docs/astro/src/content/docs/zh/guides/assets.mdxindex d549d30f3..ac5221193 100644--- a/docs/astro/src/content/docs/zh/guides/assets.mdx+++ b/docs/astro/src/content/docs/zh/guides/assets.mdx@@ -186,6 +186,50 @@ const tex = await assets.loadTexture('sprites/player.png');对于 Playable Ad 构建,编辑器的构建流程会自动将所有引用的资源以 data URI 形式嵌入输出包中。运行时 `assets.loadTexture()` / `assets.loadJson()` 等加载调用会直接从嵌入数据解析,无需网络请求,也无需修改任何代码。+## Addressable 资产++Addressable 资产允许通过逻辑地址、标签或分组加载资源,而非直接使用文件路径。编辑器在构建过程中生成 `AddressableManifest`,将地址和标签映射到资产路径。++### 按地址加载++```typescript+const texture = await assets.loadByAddress('player-idle');+```++### 按标签加载++加载标记了某个标签的所有资产,返回 `AssetBundle`:++```typescript+const bundle = await assets.loadByLabel('ui-sprites');+for (const [path, tex] of bundle.textures) {+ console.log(`已加载 ${path}: ${tex.width}x${tex.height}`);+}+```++### 按分组加载++加载某个命名分组中的所有资产:++```typescript+const bundle = await assets.loadGroup('level-1');+```++### 设置清单++清单由编辑器在构建时生成。运行时在加载前设置:++```typescript+import { Assets } from 'esengine';++const manifest = await assets.loadJson('assets/addressable-manifest.json');+assets.setAddressableManifest(manifest);+```++<Aside type="note">+ Addressable 的地址、标签和分组在编辑器的 Addressable 面板中配置。清单在构建时自动生成。+</Aside>+## 下一步- [材质与着色器](/microes/zh/guides/materials/) — 自定义着色器和混合模式diff --git a/docs/astro/src/content/docs/zh/guides/ui.mdx b/docs/astro/src/content/docs/zh/guides/ui.mdxindex ef38e73aa..932f819f3 100644--- a/docs/astro/src/content/docs/zh/guides/ui.mdx+++ b/docs/astro/src/content/docs/zh/guides/ui.mdx@@ -37,10 +37,15 @@ import { Aside } from '@astrojs/starlight/components';| 属性 | 类型 | 默认值 | 说明 ||------|------|--------|------|-| `size` | Vec2 | `{100, 100}` | UI 矩形的宽高 |-| `anchor` | Vec2 | `{0.5, 0.5}` | 锚点(0–1 范围) |+| `anchorMin` | Vec2 | `{0.5, 0.5}` | 相对于父级的左下角锚点(0–1 范围) |+| `anchorMax` | Vec2 | `{0.5, 0.5}` | 相对于父级的右上角锚点(0–1 范围) |+| `offsetMin` | Vec2 | `{0, 0}` | 从 anchorMin 的像素偏移 |+| `offsetMax` | Vec2 | `{0, 0}` | 从 anchorMax 的像素偏移 |+| `size` | Vec2 | `{100, 100}` | 宽高(anchorMin 等于 anchorMax 时使用) || `pivot` | Vec2 | `{0.5, 0.5}` | 旋转和缩放的中心点 |+当 `anchorMin` 等于 `anchorMax` 时,元素具有固定 `size`,定位在锚点位置。当两者不同时,元素在两个锚点之间拉伸,`size` 由 `UILayoutPlugin` 自动计算。+## 枚举类型### TextAlign@@ -167,6 +172,102 @@ addSystem(defineSystem());```+## UI 交互++ESEngine 提供了内置的 UI 交互系统,用于处理 UI 元素的悬停、按压和点击事件。++### 设置++在任何拥有 `UIRect` 和 `LocalTransform` 的 UI 实体上添加 `Interactable` 组件。`UIInteractionPlugin`(由 `createWebApp()` 自动注册)每帧执行命中检测并管理交互状态。++### Interactable++标记实体为可交互。++| 属性 | 类型 | 默认值 | 说明 |+|------|------|--------|------|+| `enabled` | boolean | `true` | 是否启用交互 |++### Button++在 `Interactable` 基础上添加状态机,支持可选的颜色过渡。++| 属性 | 类型 | 默认值 | 说明 |+|------|------|--------|------|+| `state` | ButtonState | `Normal` | 当前按钮状态(运行时只读) |+| `transition` | ButtonTransition \| null | `null` | 颜色过渡配置 |++**ButtonState:** `Normal` (0)、`Hovered` (1)、`Pressed` (2)、`Disabled` (3)++设置 `transition` 后,状态变化时 `Sprite` 颜色会自动更新:++```typescript+import { Button, Interactable } from 'esengine';++world.insert(entity, Button, {+ state: 0,+ transition: {+ normalColor: { r: 1, g: 1, b: 1, a: 1 },+ hoveredColor: { r: 0.9, g: 0.9, b: 0.9, a: 1 },+ pressedColor: { r: 0.7, g: 0.7, b: 0.7, a: 1 },+ disabledColor: { r: 0.5, g: 0.5, b: 0.5, a: 0.5 },+ },+});+```++### UIInteraction++由插件自动添加到拥有 `Interactable` 的实体上,提供逐实体状态:++| 属性 | 类型 | 说明 |+|------|------|------|+| `hovered` | boolean | 指针悬停在该实体上 |+| `pressed` | boolean | 实体正在被按压 |+| `justPressed` | boolean | 本帧开始按压 |+| `justReleased` | boolean | 本帧释放按压 |++### UIEvents++`UIEvents` 资源在每帧收集交互事件。在系统中查询:++```typescript+import { defineSystem, addSystem, Res } from 'esengine';+import { UIEvents } from 'esengine';++addSystem(defineSystem(+ [Res(UIEvents)],+ (events) => {+ for (const e of events.query('click')) {+ console.log('点击了实体:', e.entity);+ }+ }+));+```++**事件类型:** `click`、`press`、`release`、`hover_enter`、`hover_exit`++### ScreenSpace++用于根 UI 实体的标签组件。拥有 `ScreenSpace`、`UIRect` 和 `LocalTransform` 的实体会由 `UILayoutPlugin` 相对于相机边界进行布局。++```typescript+import { ScreenSpace, UIRect, LocalTransform } from 'esengine';++world.insert(entity, ScreenSpace);+world.insert(entity, UIRect, {+ anchorMin: { x: 0, y: 0 },+ anchorMax: { x: 1, y: 1 },+ offsetMin: { x: 0, y: 0 },+ offsetMax: { x: 0, y: 0 },+ size: { x: 100, y: 100 },+ pivot: { x: 0.5, y: 0.5 },+});+```++<Aside type="note">+ `UILayoutPlugin` 和 `UIInteractionPlugin` 均由 `createWebApp()` 自动注册,无需手动设置。+</Aside>+## 下一步- [组件](/microes/zh/core-concepts/components/) — 所有内置组件