Skip to content

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.

docs: add v0.11.0 changelog and update guides for new features

esengine410d72100c6c
diff --git a/docs/astro/astro.config.mjs b/docs/astro/astro.config.mjs
index b11c40e97..4c2088b72 100644
--- a/docs/astro/astro.config.mjs
+++ b/docs/astro/astro.config.mjs
@@ -76,6 +76,7 @@ export default defineConfig({
{ label: 'Tween Animation', translations: { 'zh-CN': '补间动画' }, slug: 'guides/tween' },
{ label: 'Spine Animation', translations: { 'zh-CN': 'Spine 动画' }, slug: 'guides/spine' },
{ label: 'Timeline', translations: { 'zh-CN': '时间轴' }, slug: 'guides/timeline' },
+ { label: 'State Machine', translations: { 'zh-CN': '状态机' }, slug: 'guides/state-machine' },
{ label: 'Bitmap Text', translations: { 'zh-CN': '位图文本' }, slug: 'guides/bitmap-text' },
{ label: 'Custom Draw', translations: { 'zh-CN': '自定义绘制' }, slug: 'guides/custom-draw' },
{ label: 'Post-Processing', translations: { 'zh-CN': '后处理效果' }, slug: 'guides/post-processing' },
@@ -154,6 +155,7 @@ export default defineConfig({
label: 'Changelog',
translations: { 'zh-CN': '更新日志' },
items: [
+ { label: 'v0.11.0', slug: 'changelog-v0110' },
{ label: 'v0.10.0', slug: 'changelog-v0100' },
{ label: 'v0.9.2', slug: 'changelog-v092' },
{ label: 'v0.9.1', slug: 'changelog-v091' },
diff --git a/docs/astro/src/content/docs/changelog-v0110.mdx b/docs/astro/src/content/docs/changelog-v0110.mdx
new file mode 100644
index 000000000..e32770ba0
--- /dev/null
+++ b/docs/astro/src/content/docs/changelog-v0110.mdx
@@ -0,0 +1,98 @@
+---
+title: v0.11.0
+description: Estella v0.11.0 release notes
+---
+
+import { Aside } from '@astrojs/starlight/components';
+
+<Aside type="tip">
+v0.11.0 introduces a full visual StateMachine system, replaces the layout engine with Yoga, ships a custom dock system, and delivers numerous editor UX improvements.
+</Aside>
+
+## StateMachine: Visual State Management
+
+A complete state machine system for driving animations and game logic, with a visual node-graph editor inspired by Rive and Unity Animator.
+
+### Component & Asset
+
+The new `StateMachine` component references a `.statemachine` asset and supports `autoPlay`. Define named states (Idle, Run, Attack…), each linked to a timeline clip, and connect them with condition-based transitions using user-defined parameters (float, int, bool, trigger).
+
+### Node Graph Editor
+
+A dedicated panel provides a full node-graph editing experience:
+
+- Drag between state nodes to create transitions
+- Click transitions to configure conditions (parameter comparisons, exit time)
+- Right-click canvas to add states or set the default state
+- Multi-layer tabs for switching between layers
+
+### Multi-Layer, Blend State & Exit State
+
+- **Multiple layers**: each layer runs its own state graph independently with configurable weight (0.0–1.0) and blend mode (Override / Additive)
+- **Blend State**: blends between multiple timeline clips via a 1D blend tree — define motion entries at threshold values and the runtime interpolates between the two nearest motions
+- **Exit State**: a special node that signals a layer has finished, useful for one-shot animations
+
+### Timeline Integration
+
+Selecting a state in the graph opens its timeline clip in the Timeline panel for direct editing. StateMachine timeline handles are managed independently from regular timeline handles. Timeline assets are preloaded when entering Play Mode to prevent missing animation data.
+
+### Inspector
+
+Collapsible parameter and layer editors with persistent collapse state. Add, remove, and rename parameters; configure layer weights and blend modes — all inline in the Inspector.
+
+## Yoga Layout Engine
+
+The hand-written CSS Flexbox implementation has been replaced with **Yoga**, Facebook's battle-tested cross-platform layout engine (used by React Native). This brings more correct handling of edge cases in flex layout.
+
+- `FlexContainer`: flexDirection, justifyContent, alignItems, alignContent, flexWrap, gap, padding, overflow
+- `FlexItem`: flexGrow, flexShrink, flexBasis, alignSelf, width/height, min/max dimensions, margin, aspectRatio, position (relative/absolute), positionInsets
+
+Properties are now organized into groups (Layout, Alignment, Spacing, Sizing, Position) with human-readable display names in the Inspector.
+
+## Custom Dock System
+
+The third-party dockview library has been replaced with a fully custom dock system:
+
+- **Drag-and-drop tabs**: reorder within a dock area or move panels between areas
+- **Split layouts**: drop tabs on edge indicators to split horizontally or vertically
+- **Resizable splitters**: drag borders between dock areas
+- **Floating panels**: pop out any panel as a floating window
+- **Persistent layout**: saved to localStorage and restored on reload, with a menu option to reset to defaults
+
+## Add Component Popup
+
+The "Add Component" button now opens a redesigned anchored panel:
+
+- **Fuzzy search**: type to filter components with fuzzy matching
+- **Categorized list**: components organized by category (Rendering, UI, Physics, Audio, Layout, Animation, etc.)
+- **Keyboard navigation**: arrow keys to navigate, Enter to select
+
+## spawn(name) API
+
+- `world.spawn(name?)` creates a new entity with an optional name
+- `world.getEntityByName(name)` provides O(1) name-based entity lookup via an internal name index
+- The Hierarchy panel displays tag badges next to entity names for quick visual identification
+
+## Enhanced Selection & Gizmo Cursors
+
+- **Context-aware cursors**: move arrows show directional cursor, scale handles show resize cursor, rotate ring shows rotation cursor
+- **Hover highlighting**: gizmo handles highlight on hover with color feedback
+- **Click-through prevention**: gizmos take priority over entity selection when overlapping
+
+## Multiple Output Handlers
+
+`OutputService` now supports registering multiple output handlers via `addOutputHandler()` / `removeOutputHandler()`. Handlers are called in sequence, enabling scenarios like writing to file, sending to preview, and logging to console simultaneously.
+
+## MCP Enhancements
+
+- UI template instantiation route for creating UI hierarchies from templates
+- Improved screenshot capture with timeout, panel content selector, and html2canvas integration
+- MCP server extracted to a standalone repository as a git submodule
+
+## Bug Fixes
+
+- Fixed preview server port binding failure on Windows
+- Fixed MCP bridge file not created on Windows
+- Fixed popup and dropdown menus overflowing viewport bounds — positions are now clamped
+- Fixed padding editor style inconsistency with vec editor
+- Fixed Canvas missing UIRect when creating a new scene
diff --git a/docs/astro/src/content/docs/core-concepts/systems.mdx b/docs/astro/src/content/docs/core-concepts/systems.mdx
index 57986281f..e9da1769a 100644
--- a/docs/astro/src/content/docs/core-concepts/systems.mdx
+++ b/docs/astro/src/content/docs/core-concepts/systems.mdx
@@ -130,7 +130,7 @@ defineSystem([Commands()], (cmds) => {
| Method | Returns | Description |
|--------|---------|-------------|
-| `cmds.spawn()` | `EntityCommands` | Create a new entity, returns a builder |
+| `cmds.spawn(name?)` | `EntityCommands` | Create a new entity with an optional name, returns a builder |
| `cmds.entity(entity)` | `EntityCommands` | Get a builder for an existing entity |
| `cmds.despawn(entity)` | `this` | Queue entity for destruction |
| `cmds.insertResource(res, value)` | `this` | Insert or overwrite a resource |
diff --git a/docs/astro/src/content/docs/guides/mcp.mdx b/docs/astro/src/content/docs/guides/mcp.mdx
index b1659a4e9..849636096 100644
--- a/docs/astro/src/content/docs/guides/mcp.mdx
+++ b/docs/astro/src/content/docs/guides/mcp.mdx
@@ -13,7 +13,7 @@ The Estella editor includes a built-in **MCP (Model Context Protocol)** bridge t
## Prerequisites
-- Estella editor v0.10.0 or later
+- Estella editor v0.11.0 or later
- Node.js 18+
- An MCP-compatible AI client (e.g., Claude Desktop, Claude Code, Cursor)
@@ -136,12 +136,40 @@ AI Client ←→ MCP Server (stdio) ←→ HTTP Bridge ←→ Estella Editor
| `pause` | Pause/resume play mode |
| `set_play_speed` | Adjust playback speed |
+### UI Creation
+
+Create fully configured UI widget hierarchies with a single tool call. Entities are auto-parented under the Canvas.
+
+| Tool | Description |
+|------|-------------|
+| `create_text` | Create a text label with content, fontSize, color, and alignment |
+| `create_image` | Create an image element with tint color and size |
+| `create_panel` | Create a panel with background and mask |
+| `create_button` | Create a button with background and interactable |
+| `create_input_field` | Create a text input field with placeholder and initial value |
+| `create_toggle` | Create a toggle/checkbox |
+| `create_slider` | Create a slider with fill bar and handle |
+| `create_progress_bar` | Create a progress bar with fill |
+| `create_scroll_view` | Create a scrollable container |
+| `create_dropdown` | Create a dropdown/select with options |
+
+### Editor State
+
+| Tool | Description |
+|------|-------------|
+| `get_console_logs` | Get recent console logs, optionally filtered by level |
+| `get_panel_layout` | Get editor panel positions |
+| `get_project_settings` | Get project settings |
+| `get_build_status` | Get recent build history |
+| `get_render_stats` | Get frame timing and performance data |
+| `get_asset_info` | Get detailed info about an asset by UUID or path |
+
### Visual
| Tool | Description |
|------|-------------|
-| `screenshot` | Capture a screenshot of the current viewport |
-| `screenshot_diff` | Compare two screenshots pixel-by-pixel |
+| `capture_editor` | Capture a screenshot of the editor (whole window or specific panel) |
+| `capture_diff` | Compare two screenshots pixel-by-pixel |
## Example Prompts
diff --git a/docs/astro/src/content/docs/guides/scenes.mdx b/docs/astro/src/content/docs/guides/scenes.mdx
index b1b0374a1..ad9509709 100644
--- a/docs/astro/src/content/docs/guides/scenes.mdx
+++ b/docs/astro/src/content/docs/guides/scenes.mdx
@@ -48,7 +48,18 @@ After building your project, the engine automatically loads the scene, resolves
### By Name
-Every entity loaded from a scene receives a built-in `Name` component with the name assigned in the editor. Query `Name` to find entities:
+Use `findEntityByName()` for O(1) name-based lookup:
+
+```typescript
+import { findEntityByName } from 'esengine';
+
+const player = findEntityByName(world, 'Player');
+if (player) {
+ // found the player entity
+}
+```
+
+Alternatively, query the `Name` component to iterate over named entities:
```typescript
import { defineSystem, addStartupSystem, Query, Name, Transform } from 'esengine';
diff --git a/docs/astro/src/content/docs/guides/state-machine.mdx b/docs/astro/src/content/docs/guides/state-machine.mdx
new file mode 100644
index 000000000..8627a3898
--- /dev/null
+++ b/docs/astro/src/content/docs/guides/state-machine.mdx
@@ -0,0 +1,505 @@
+---
+title: State Machine
+description: Visual state machine system for animations and interactive UI in Estella
+---
+
+import { Aside } from '@astrojs/starlight/components';
+
+The **StateMachine** component drives animations and interactive behavior through a visual state graph. Define states, connect them with conditional transitions, and let the engine handle the rest — no scripting required for common patterns like button hover effects, character animation controllers, or multi-step UI flows.
+
+<Aside type="note">
+ The StateMachine plugin is included by default — no manual setup is needed.
+</Aside>
+
+## Tutorial: Hover Button
+
+Let's build a button that changes opacity on hover, step by step.
+
+### Step 1: Add the Component
+
+Select a UI entity (e.g., a Button) in the Hierarchy. Click **Add Component** → **StateMachine**.
+
+### Step 2: Define Inputs
+
+In the Inspector, expand the StateMachine component. Click the **+** button next to **Inputs** to add a parameter:
+
+- **Name**: `hovered`
+- **Type**: `bool`
+- **Default**: `false`
+
+This parameter will track whether the pointer is over the button.
+
+### Step 3: Define Listeners
+
+Click **+** next to **Listeners** to add two event bindings:
+
+1. **Event**: `pointerEnter` → **Input**: `hovered` → **Action**: `set` → **Value**: `true`
+2. **Event**: `pointerExit` → **Input**: `hovered` → **Action**: `reset` → **Value**: `false`
+
+Now pointer events automatically update the `hovered` input.
+
+<Aside type="tip">
+ The entity needs a `UIInteraction` component for listeners to work. Buttons and other UI widgets include this automatically.
+</Aside>
+
+### Step 4: Create States in the Graph
+
+Open the **StateMachine** panel (find it in the panel menu if not visible). You'll see an empty canvas with an Entry node.
+
+1. **Right-click** the canvas → **Add State** → name it `idle`
+2. **Right-click** again → **Add State** → name it `hover`
+3. The Entry node automatically connects to the first state. Right-click `idle` → **Set as Default** if needed.
+
+### Step 5: Configure State Properties
+
+Click the `idle` state node. In the detail panel on the right:
+
+1. Click **+ Add Property**
+2. Enter path: `Sprite.color.a`
+3. Set value: `1.0`
+
+Click the `hover` state node and add:
+
+- Path: `Sprite.color.a`, Value: `0.7`
+
+### Step 6: Create Transitions
+
+1. Hover over the `idle` node until you see a connection handle on its edge
+2. **Drag** from `idle` to `hover` — this creates a transition arrow
+3. Click the arrow to configure it in the detail panel:
+ - **Duration**: `0.15` (seconds for the opacity tween)
+ - Click **+ Add Condition**: Input `hovered`, Comparator `eq`, Value `true`
+
+4. Create a second transition from `hover` back to `idle`:
+ - **Duration**: `0.15`
+ - Condition: `hovered` `eq` `false`
+
+### Step 7: Test
+
+Press **F5** or click Play. Hover over the button — its opacity smoothly fades to 0.7 and back.
+
+### The Same Thing from Code
+
+```typescript
+import { Commands, StateMachine, UIInteraction } from 'esengine';
+
+cmds.spawn('my-button')
+ .insert(StateMachine, {
+ inputs: [
+ { name: 'hovered', type: 'bool', defaultValue: false },
+ ],
+ listeners: [
+ { event: 'pointerEnter', inputName: 'hovered', action: 'set', value: true },
+ { event: 'pointerExit', inputName: 'hovered', action: 'reset', value: false },
+ ],
+ initialState: 'idle',
+ states: {
+ idle: {
+ properties: { 'Sprite.color.a': 1.0 },
+ transitions: [
+ {
+ target: 'hover',
+ duration: 0.15,
+ conditions: [{ inputName: 'hovered', comparator: 'eq', value: true }],
+ },
+ ],
+ },
+ hover: {
+ properties: { 'Sprite.color.a': 0.7 },
+ transitions: [
+ {
+ target: 'idle',
+ duration: 0.15,
+ conditions: [{ inputName: 'hovered', comparator: 'eq', value: false }],
+ },
+ ],
+ },
+ },
+ });
+```
+
+## Controlling Inputs
+
+### Via Listeners (Recommended)
+
+Listeners are the primary way to drive state changes. They map pointer events to input changes without any code:
+
+```typescript
+listeners: [
+ { event: 'pointerEnter', inputName: 'hovered', action: 'set', value: true },
+ { event: 'pointerExit', inputName: 'hovered', action: 'reset', value: false },
+ { event: 'pointerDown', inputName: 'click', action: 'set', value: true },
+ { event: 'pointerDown', inputName: 'selected', action: 'toggle' },
+]
+```
+
+In the editor, add listeners in the Inspector under the StateMachine component's **Listeners** section.
+
+### Via Initial Values
+
+Input `defaultValue` determines the starting value when playback begins. Set these in the Inspector or in code when spawning:
+
+```typescript
+cmds.spawn('character')
+ .insert(StateMachine, {
+ inputs: [
+ { name: 'speed', type: 'number', defaultValue: 5 },
+ { name: 'grounded', type: 'bool', defaultValue: true },
+ ],
+ // ...states and transitions
+ });
+```
+
+<Aside type="caution">
+ Input values are managed by an internal runtime that initializes once when Play Mode starts. The `defaultValue` on each input definition sets the **initial** value only. Changing `defaultValue` after the state machine has started running has no effect — the runtime uses its own internal copy of input values.
+</Aside>
+
+### Design Patterns for Dynamic Control
+
+Since inputs cannot be directly modified from user systems at runtime, use these patterns instead:
+
+**Pattern 1: Listener-driven** — Map game events to pointer events on invisible UI elements. For example, place a hidden `UIInteraction` entity that receives pointer events to toggle states.
+
+**Pattern 2: Component-driven transitions** — Instead of changing inputs, have transitions respond to other component values. For example, a transition can use `exitTime` to auto-advance after a timeline finishes, without needing input changes.
+
+**Pattern 3: Multiple StateMachines** — For complex behavior, use separate StateMachine components on different entities, each driven by its own listeners.
+
+## States in Depth
+
+Each state represents a visual/behavioral configuration. There are three state types:
+
+### Standard State (Properties)
+
+The default type. Assigns values to entity properties when the state is entered:
+
+```typescript
+idle: {
+ properties: {
+ 'Sprite.color.a': 1.0, // set opacity
+ 'Transform.scale.x': 1.0, // set scale
+ 'Transform.scale.y': 1.0,
+ },
+ transitions: [/* ... */],
+}
+```
+
+**Property paths** use dot notation: `ComponentName.field.subField`. Examples:
+- `Sprite.color.r` / `.g` / `.b` / `.a` — sprite color channels
+- `Transform.position.x` / `.y` — position
+- `Transform.scale.x` / `.y` — scale
+- `Transform.rotation` — rotation in radians
+- `UIRect.size.x` / `.y` — UI element size
+
+When transitioning, all numeric properties **tween together** over the transition's `duration` with an optional `easing` curve. A single transition shares one duration and one easing for all properties — you cannot set different durations per property within the same transition. Non-numeric values (like asset paths) are applied instantly at the start of the transition.
+
+### Timeline State
+
+References a `.estl` timeline asset. When the state is entered, the timeline plays from the beginning:
+
+```typescript
+attack: {
+ timeline: 'animations/attack.estl',
+ timelineWrapMode: 'once', // 'once' or 'loop'
+ transitions: [
+ {
+ target: 'idle',
+ conditions: [], // no conditions — uses exitTime
+ duration: 0.1,
+ exitTime: 0.9, // transition allowed after 90% of timeline played
+ },
+ ],
+}
+```
+
+`exitTime` is a 0–1 ratio. The transition won't fire until the timeline has played past this point, even if all conditions are met. An empty `conditions` array with `exitTime` means "transition automatically after the animation finishes".
+
+### Blend State
+
+See the [Blend States](#blend-states) section below.
+
+## Transitions
+
+A transition fires when **all** its conditions are true simultaneously:
+
+```typescript
+{
+ target: 'run', // destination state name
+ duration: 0.2, // tween duration (seconds, default: 0)
+ easing: 'easeOutQuad', // easing curve (default: 'linear')
+ exitTime: 0.8, // optional: wait for timeline progress
+ conditions: [
+ { inputName: 'speed', comparator: 'gt', value: 3 },
+ { inputName: 'grounded', comparator: 'eq', value: true },
+ ],
+}
+```
+
+| Comparator | Meaning |
+|------------|---------|
+| `eq` | Equal |
+| `neq` | Not equal |
+| `gt` | Greater than |
+| `lt` | Less than |
+| `gte` | Greater than or equal |
+| `lte` | Less than or equal |
+
+Available easing values: `linear`, `easeInQuad`, `easeOutQuad`, `easeInOutQuad`, `easeInCubic`, `easeOutCubic`, `easeInOutCubic`, `easeInBack`, `easeOutBack`, `easeInOutBack`, `easeInElastic`, `easeOutElastic`, `easeInOutElastic`, `easeOutBounce`
+
+Transitions are evaluated **in order** — the first one whose conditions are all met fires, and the rest are skipped for that frame.
+
+## Inputs
+
+Three input types to drive transitions:
+
+| Type | Behavior | Use for |
+|------|----------|---------|
+| `bool` | Stays at its value until changed | Toggle states: hovered, selected, grounded |
+| `number` | Continuous, can use `gt`/`lt` comparators | Speed, health, blend parameters |
+| `trigger` | Set to `true`, **auto-resets to `false` next frame** | One-shot events: jump, attack, death |
+
+## Listeners
+
+Map pointer events to input changes without code:
+
+```typescript
+listeners: [
+ // When pointer enters → set hovered to true
+ { event: 'pointerEnter', inputName: 'hovered', action: 'set', value: true },
+ // When pointer exits → set hovered to false
+ { event: 'pointerExit', inputName: 'hovered', action: 'reset', value: false },
+ // When clicked → fire the 'click' trigger
+ { event: 'pointerDown', inputName: 'click', action: 'set', value: true },
+ // Toggle selection on click
+ { event: 'pointerDown', inputName: 'selected', action: 'toggle' },
+]
+```
+
+| Action | Effect |
+|--------|--------|
+| `set` | Set input to `value` (default: `true`) |
+| `reset` | Set input to `value` (default: `false`) |
+| `toggle` | Flip a boolean input |
+
+## Multi-Layer
+
+A single StateMachine can contain multiple **layers**, each running its own state graph independently. All layers share the same inputs but evaluate their own transitions separately.
+
+```typescript
+{
+ inputs: [
+ { name: 'speed', type: 'number', defaultValue: 0 },
+ { name: 'attack', type: 'trigger' },
+ ],
+ listeners: [],
+ initialState: '', // ignored when layers is set
+ states: {}, // ignored when layers is set
+ layers: [
+ {
+ name: 'Locomotion',
+ initialState: 'idle',
+ states: {
+ idle: {
+ properties: { 'Transform.position.y': 0 },
+ transitions: [
+ { target: 'run', duration: 0.2, conditions: [{ inputName: 'speed', comparator: 'gt', value: 1 }] },
+ ],
+ },
+ run: {
+ timeline: 'animations/run.estl',
+ timelineWrapMode: 'loop',
+ transitions: [
+ { target: 'idle', duration: 0.2, conditions: [{ inputName: 'speed', comparator: 'lte', value: 1 }] },
+ ],
+ },
+ },
+ },
+ {
+ name: 'Action',
+ initialState: 'none',
+ states: {
+ none: {
+ transitions: [
+ { target: 'attack', duration: 0, conditions: [{ inputName: 'attack', comparator: 'eq', value: true }] },
+ ],
+ },
+ attack: {
+ timeline: 'animations/attack.estl',
+ timelineWrapMode: 'once',
+ transitions: [
+ { target: 'none', duration: 0.1, exitTime: 0.9, conditions: [] },
+ ],
+ },
+ },
+ },
+ ],
+}
+```
+
+In this example, the Locomotion layer handles movement animation while the Action layer handles attack — both run simultaneously and can affect different properties on the same entity.
+
+### Any State
+
+A state named `__any__` acts as a wildcard: its transitions are evaluated **in addition to** the current state's transitions, regardless of which state the layer is in. Use this for global transitions like "if health reaches 0, go to death state from any state".
+
+### Exit State
+
+A layer can transition to the special `__exit__` state, which stops the layer from processing entirely. Useful for one-shot overlay layers (play an attack animation, then the layer goes dormant).
+
+## Blend States
+
+Blend states continuously interpolate properties based on input values **every frame**, unlike standard states which apply properties once on entry. Use blend states when you need smooth, parameter-driven animation — for example, tinting a character based on speed, or mixing multiple visual effects with independent weights.
+
+<Aside type="tip">
+ **When to use blend vs standard states:** Use standard states for discrete visual configurations (idle, hover, pressed). Use blend states when a property should vary smoothly along a continuous parameter (speed → color, health → size).
+</Aside>
+
+### 1D Blend
+
+Interpolates properties along a single numeric input axis. Define multiple **threshold** entries — the engine blends between the two nearest thresholds based on the input value.
+
+```typescript
+locomotion: {
+ type: 'blend1d',
+ blendInput: 'speed', // which number input drives the blend
+ blendStates: [
+ { threshold: 0, properties: { 'Sprite.color.g': 0.5 } },
+ { threshold: 5, properties: { 'Sprite.color.g': 0.8 } },
+ { threshold: 10, properties: { 'Sprite.color.g': 1.0 } },
+ ],
+ transitions: [],
+}
+```
+
+When `speed` is 2.5 (halfway between thresholds 0 and 5), `Sprite.color.g` is linearly interpolated to 0.65. Values below the lowest threshold clamp to the first entry; values above the highest clamp to the last.
+
+Asset-type properties (like textures) cannot be interpolated — they snap to the nearest threshold instead.
+
+Blend entries can also reference timelines instead of properties:
+
+```typescript
+blendStates: [
+ { threshold: 0, timeline: 'animations/idle.estl', timelineWrapMode: 'loop' },
+ { threshold: 5, timeline: 'animations/walk.estl', timelineWrapMode: 'loop' },
+ { threshold: 10, timeline: 'animations/run.estl', timelineWrapMode: 'loop' },
+]
+```
+
+### Direct Blend
+
+Each entry contributes independently with its own weight. Unlike 1D blend which uses a single input axis, direct blend lets you control multiple effects separately:
+
+```typescript
+overlay: {
+ type: 'blendDirect',
+ blendStates: [
+ { mixInput: 'damageFlash', properties: { 'Sprite.color.r': 1.0 } },
+ { mixInput: 'freezeEffect', properties: { 'Sprite.color.b': 1.0 } },
+ { mixValue: 0.3, properties: { 'Sprite.color.g': 0.5 } },
+ ],
+ transitions: [],
+}
+```
+
+- **`mixInput`**: weight comes from a named number input (0.0–1.0). Change the input value to control how strongly this entry affects the result.
+- **`mixValue`**: weight is a fixed constant. The entry always contributes this fraction.
+
+Direct blend is ideal for layering independent visual effects — damage flash, freeze tint, poison glow — each controlled by its own input without interfering with the others.
+
+### BlendEntry Reference
+
+| Property | Type | Description |
+|----------|------|-------------|
+| `properties` | `Record<string, unknown>` | Property path → target value map (same as standard states) |
+| `timeline` | `string` | Path to `.estl` timeline asset (alternative to properties) |
+| `timelineWrapMode` | `'once' \| 'loop'` | Timeline playback mode (default: `'once'`) |
+| `threshold` | `number` | Position on the 1D blend axis (required for `blend1d`) |
+| `mixInput` | `string` | Input name whose value is used as the blend weight (for `blendDirect`) |
+| `mixValue` | `number` | Fixed blend weight (for `blendDirect`, alternative to `mixInput`) |
+
+## Node Graph Editor
+
+The **StateMachine** panel provides the visual editing experience. Open it from **View** → **StateMachine** or the panel menu.
+
+### Canvas
+
+- **State nodes** appear as rounded rectangles. The initial state has a green Entry arrow pointing to it.
+- **Transition arrows** connect states. Click an arrow to select and edit it.
+- **Right-click** the canvas background to add a new state or paste.
+- **Right-click** a state node to set it as default, delete it, or add transitions.
+- **Double-click** a state to rename it.
+- **Drag** the canvas to pan, **scroll** to zoom.
+
+### Special Nodes
+
+| Node | Color | Purpose |
+|------|-------|---------|
+| Entry | Green arrow | Marks the initial state |
+| Any State | Purple | Transitions from here apply regardless of current state |
+| Exit | Red | Transitioning here stops the layer |
+
+### Detail Panel
+
+Click a **state** or **transition** in the graph to open the detail panel:
+
+**For states:**
+- Choose between Properties mode or Timeline mode
+- In Properties mode: add property path → value pairs
+- In Timeline mode: select a `.estl` asset and wrap mode
+- For Blend states: configure blend type, input, and threshold entries
+
+**For transitions:**
+- Set duration and easing curve
+- Set exitTime (for timeline states)
+- Add/remove conditions with input, comparator, and value
+
+### Layer Tabs
+
+When using multi-layer, tabs at the top of the panel let you switch between layers. Each layer has its own graph.
+
+## Component Reference
+
+### StateMachine
+
+| Property | Type | Default | Description |
+|----------|------|---------|-------------|
+| `states` | `Record<string, StateNode>` | `{}` | State definitions (single-layer mode) |
+| `inputs` | `InputDef[]` | `[]` | Parameter definitions shared across all layers |
+| `listeners` | `ListenerDef[]` | `[]` | Event-to-input bindings |
+| `initialState` | `string` | `''` | Default state name (single-layer mode) |
+| `layers` | `LayerData[]` | — | Multi-layer definitions (when set, overrides `states` and `initialState`) |
+
+### StateNode
+
+| Property | Type | Default | Description |
+|----------|------|---------|-------------|
+| `properties` | `Record<string, unknown>` | — | Property path → target value map |
+| `timeline` | `string` | — | Path to `.estl` timeline asset |
+| `timelineWrapMode` | `'once' \| 'loop'` | `'once'` | Timeline playback mode |
+| `transitions` | `Transition[]` | `[]` | Outgoing transitions |
+| `type` | `'standard' \| 'blend1d' \| 'blendDirect'` | `'standard'` | State type |
+| `blendInput` | `string` | — | Input name for 1D blending |
+| `blendStates` | `BlendEntry[]` | — | Blend tree entries |
+
+### Transition
+
+| Property | Type | Default | Description |
+|----------|------|---------|-------------|
+| `target` | `string` | — | Destination state name |
+| `conditions` | `Condition[]` | — | All must be true to fire |
+| `duration` | `number` | `0` | Tween duration in seconds |
+| `exitTime` | `number` | — | Timeline progress ratio (0–1) required before checking conditions |
+| `easing` | `string` | `'linear'` | Easing curve for property tweens |
+
+### Condition
+
+| Property | Type | Description |
+|----------|------|-------------|
+| `inputName` | `string` | Name of the input to compare |
+| `comparator` | `'eq' \| 'neq' \| 'gt' \| 'lt' \| 'gte' \| 'lte'` | Comparison operator |
+| `value` | `boolean \| number` | Value to compare against |
+
+## Next Steps
+
+- [Timeline](/docs/guides/timeline/) — multi-track animation system used by timeline states
+- [Tween Animation](/docs/guides/tween/) — code-driven property animation
+- [UI Interaction](/docs/guides/ui-interaction/) — pointer events and focus
diff --git a/docs/astro/src/content/docs/guides/timeline.mdx b/docs/astro/src/content/docs/guides/timeline.mdx
index 6919392bb..278d28ae1 100644
--- a/docs/astro/src/content/docs/guides/timeline.mdx
+++ b/docs/astro/src/content/docs/guides/timeline.mdx
@@ -11,26 +11,135 @@ The **Timeline** system drives multi-track animations that coordinate property c
The timeline plugin is included by default — no manual setup is needed.
</Aside>
-## Editor Workflow
-
-1. Select an entity in the Hierarchy
-2. Open the **Timeline** panel
-3. Click **+** to add tracks (Property, Spine, Sprite Animation, Audio, Activation)
-4. Add keyframes by clicking on the timeline ruler
-5. The timeline is saved as a `.estl` asset file
-
-### Track Types
-
-| Type | Description |
-|------|-------------|
-| Property | Animate any numeric component property (position, scale, color, etc.) with keyframe interpolation |
-| Spine | Trigger Spine animation clips on a SpineAnimation component |
-| Sprite Animation | Play sprite animation clips |
-| AnimFrames | Visual frame track — each sprite frame is a colored, resizable block with its own duration |
-| Audio | Trigger audio events at specific times |
-| Activation | Enable/disable entities over time ranges |
-| Marker | Place named markers at specific times |
-| Custom Event | Trigger custom events at specific times |
+## Tutorial: Animate a Sprite
+
+Let's create a timeline that moves a sprite from left to right and fades it out.
+
+### Step 1: Select the Entity
+
+Click on the entity you want to animate in the Hierarchy.
+
+### Step 2: Open the Timeline Panel
+
+Open **View** → **Timeline** (or find it in the panel menu). If the entity doesn't have a `TimelinePlayer` component yet, the panel shows a **Create** button — click it to add one automatically.
+
+### Step 3: Add a Property Track
+
+1. Click the **+** button in the track list
+2. Select **Property** → **Transform** → **position.x**
+3. A new track appears, targeting the selected entity's `Transform.position.x`
+
+### Step 4: Add Keyframes
+
+1. Move the **playhead** to time 0.0 by clicking the ruler at the top
+2. Click the **diamond icon** (or press `K`) to add a keyframe — it captures the current value
+3. Move the playhead to 1.0 seconds
+4. In the Inspector, change position.x to 200
+5. Press `K` again — a second keyframe is added with the new value
+
+### Step 5: Add a Second Track
+
+1. Click **+** → **Property** → **Sprite** → **color.a**
+2. At time 0.0, add a keyframe (value: 1.0)
+3. At time 1.0, add a keyframe (value: 0.0)
+
+### Step 6: Preview
+
+Press **Space** to play in the editor. The sprite moves right while fading out over 1 second.
+
+### Step 7: Configure Playback
+
+In the Inspector, set the `TimelinePlayer` properties:
+- **wrapMode**: `loop` to make it repeat
+- **speed**: `0.5` to play at half speed
+
+## Track Targeting
+
+Every track has a **target entity**. By default, it's the entity that owns the `TimelinePlayer` component.
+
+### Animating Child Entities
+
+To animate a child entity, set the track's **Child Path** — a `/`-separated name hierarchy:
+
+```
+Arm/Hand → find child "Arm", then its child "Hand"
+Body → find direct child "Body"
+(empty) → target the root entity itself
+```
+
+In the editor, when you add a track while a child entity is selected, the child path is set automatically.
+
+<Aside type="tip">
+ Child paths are resolved once when playback starts. The target entities must exist in the hierarchy before playing the timeline.
+</Aside>
+
+## Track Types
+
+### Property
+
+Animate any numeric component property with keyframe interpolation.
+
+**Built-in properties** (optimized, computed in C++):
+
+| Component | Properties |
+|-----------|-----------|
+| Transform | position.x/y/z, scale.x/y/z, rotation |
+| Sprite | color.r/g/b/a, opacity, size.x/y |
+| UIRect | offsetMin.x/y, offsetMax.x/y, anchorMin.x/y, anchorMax.x/y, pivot.x/y |
+| Camera | orthoSize |
+
+**Custom properties**: Any other numeric component field can be animated using nested paths (e.g., `myComponent.health`).
+
+#### Keyframe Interpolation
+
+Right-click a keyframe to choose an interpolation mode:
+
+| Mode | Behavior |
+|------|----------|
+| Hermite | Smooth cubic curve using tangent handles (default) |
+| Linear | Straight line between keyframes |
+| Step | Hold value until next keyframe (no interpolation) |
+| EaseIn | Slow start, accelerating toward the next keyframe |
+| EaseOut | Fast start, decelerating toward the next keyframe |
+| EaseInOut | Smooth acceleration and deceleration |
+
+For Hermite mode, drag the tangent handles in the curve editor to shape the interpolation.
+
+### Spine
+
+Trigger Spine animation clips on a `SpineAnimation` component. Each keyframe specifies an animation name to play at that time.
+
+### Sprite Animation
+
+Play sprite animation clips. Each keyframe specifies a clip name to start at that time.
+
+### AnimFrames
+
+A visual frame track for sprite-sheet-style animation. Unlike sprite animation clips, each frame is displayed as a **colored, resizable block** on the timeline:
+
+- Each block references a texture and has its own **duration** (default: 1/12 second)
+- **Drag block edges** to adjust frame timing
+- The target entity must have a `Sprite` component — the texture is swapped each frame
+
+Use AnimFrames when you need per-frame timing control without creating a separate animation clip.
+
+### Audio
+
+Trigger audio playback at specific times. Each keyframe specifies an audio asset to play.
+
+### Activation
+
+Toggle entity visibility over time ranges. The entity is enabled within the active range and disabled outside it.
+
+### Marker
+
+Place named markers at specific times. Markers don't affect playback — they serve as reference points for the editor and for seeking.
+
+### Custom Event
+
+Trigger named events at specific times. Listen for these events in your systems to run custom logic at precise moments during the animation.
+
+## Editor Controls
### Keyboard Shortcuts
@@ -38,34 +147,49 @@ The **Timeline** system drives multi-track animations that coordinate property c
|----------|--------|
| `Space` | Play / Pause |
| `,` / `.` | Step backward / forward one frame |
-| `K` | Add keyframe at playhead |
+| `K` | Add keyframe at playhead position |
| `Delete` | Delete selected keyframes |
| `Ctrl+Click` | Toggle keyframe selection |
| `Shift+Click` | Range select keyframes |
+| Box drag | Rubber-band select multiple keyframes |
-### Toolbar Controls
+### Toolbar
-- **Record**: Toggle auto-keyframe mode — changes to properties are automatically recorded as keyframes
+- **Record**: Toggle auto-keyframe mode — property changes in the Inspector are automatically recorded as keyframes at the current playhead position
- **Speed**: Cycle playback speed (0.25x, 0.5x, 1x, 2x, 4x)
- **Wrap Mode**: Cycle between Once, Loop, and PingPong
- **Snap**: Toggle grid snapping during keyframe drag
- **Duration**: Double-click the time display to edit total timeline duration
+### Multi-Select & Batch Operations
+
+Select multiple keyframes (Ctrl+Click, Shift+Click, or box drag), then:
+- **Drag** to move them all together
+- **Delete** to remove them as a single undo step
+
+### Track Management
+
+- **Drag** tracks to reorder in the list
+- **Right-click** a track for rename / delete
+- Each track type has a distinct color indicator in the sidebar
+
### Live Playhead Sync
-When entering Play Mode, the timeline automatically switches to **LIVE** mode. The playhead tracks the runtime animation position in real-time, and a red "LIVE" indicator appears in the toolbar. Editor playback controls are disabled during live mode and restore when exiting Play Mode.
+When entering Play Mode, the timeline automatically switches to **LIVE** mode. The playhead tracks the runtime animation position in real-time (polled at 60fps), and a red blinking "LIVE" indicator appears in the toolbar. Editor playback controls are disabled during live mode and restore when exiting Play Mode.
## TimelinePlayer Component
-Add `TimelinePlayer` to an entity to play a timeline asset at runtime. Configure it in the editor Inspector or from code.
+Add `TimelinePlayer` to an entity to play a timeline asset at runtime.
| Property | Type | Default | Description |
|----------|------|---------|-------------|
| `timeline` | string | `''` | Path to the `.estl` timeline asset |
-| `playing` | boolean | `false` | Whether the timeline is currently playing |
+| `playing` | boolean | `false` | Set to `true` to start playback |
| `speed` | number | `1.0` | Playback speed multiplier |
| `wrapMode` | string | `'once'` | `'once'`, `'loop'`, or `'pingPong'` |
+When `playing` is set to `true`, the timeline starts. When it finishes (in `once` mode), `playing` is automatically set back to `false`.
+
### WrapMode
| Value | Description |
@@ -76,7 +200,7 @@ Add `TimelinePlayer` to an entity to play a timeline asset at runtime. Configure
## TimelineControl API
-Use `TimelineControl` to control timeline playback from systems:
+Use `TimelineControl` for runtime playback control from systems:
```typescript
import { defineSystem, addSystem, Query, TimelinePlayer, TimelineControl } from 'esengine';
@@ -115,13 +239,9 @@ When loading timelines outside the editor (e.g., in a custom asset pipeline), us
```typescript
import { registerTimelineAsset, getTimelineAsset, parseTimelineAsset } from 'esengine';
-// Parse raw timeline data
const asset = parseTimelineAsset(jsonData);
-
-// Register for runtime lookup
registerTimelineAsset('timelines/intro.estl', asset);
-// Retrieve later
const tl = getTimelineAsset('timelines/intro.estl');
```
@@ -145,12 +265,12 @@ addStartupSystem(defineSystem(
}
));
-// Allow skipping with any key
+// Allow skipping with Space
addSystem(defineSystem(
[Res(Input), Query(TimelinePlayer)],
(input, query) => {
if (input.isKeyPressed('Space')) {
- for (const [entity, player] of query) {
+ for (const [entity] of query) {
if (TimelineControl.isPlaying(entity)) {
TimelineControl.stop(entity);
}
@@ -162,6 +282,7 @@ addSystem(defineSystem(
## Next Steps
+- [State Machine](/docs/guides/state-machine/) — drive timelines through state transitions
- [Tween Animation](/docs/guides/tween/) — code-driven property animation
- [Spine Animation](/docs/guides/spine/) — skeletal animation
- [Sprite Animation](/docs/guides/sprite-animation/) — frame-by-frame sprite animation
diff --git a/docs/astro/src/content/docs/guides/ui.mdx b/docs/astro/src/content/docs/guides/ui.mdx
index 35c93a11a..d6e742fed 100644
--- a/docs/astro/src/content/docs/guides/ui.mdx
+++ b/docs/astro/src/content/docs/guides/ui.mdx
@@ -52,7 +52,7 @@ When `anchorMin` equals `anchorMax`, the element has a fixed `size` at the ancho
## FlexContainer
-CSS Flexbox-like layout for automatic child arrangement.
+CSS Flexbox-like layout for automatic child arrangement, powered by the [Yoga](https://yogalayout.dev/) layout engine.
| Property | Type | Default | Description |
|----------|------|---------|-------------|
@@ -60,8 +60,9 @@ CSS Flexbox-like layout for automatic child arrangement.
| `wrap` | FlexWrap | `NoWrap` | `NoWrap`, `Wrap` |
| `justifyContent` | JustifyContent | `Start` | `Start`, `Center`, `End`, `SpaceBetween`, `SpaceAround`, `SpaceEvenly` |
| `alignItems` | AlignItems | `Stretch` | `Start`, `Center`, `End`, `Stretch` |
-| `gap` | Vec2 | `{0, 0}` | Spacing between items |
-| `padding` | Vec4 | `{x:0, y:0, z:0, w:0}` | Padding as `{x: top, y: right, z: bottom, w: left}` |
+| `alignContent` | AlignContent | `Start` | `Start`, `Center`, `End`, `Stretch`, `SpaceBetween`, `SpaceAround` — controls multi-line cross-axis alignment |
+| `gap` | Vec2 | `{0, 0}` | Spacing between items (`x` = column gap, `y` = row gap) |
+| `padding` | Padding | `{left:0, top:0, right:0, bottom:0}` | Inner padding |
## FlexItem
@@ -73,6 +74,11 @@ Child properties for entities inside a `FlexContainer`.
| `flexShrink` | number | `1` | How much the item shrinks when space is tight |
| `flexBasis` | number | `-1` | Base size before grow/shrink (-1 = auto) |
| `order` | number | `0` | Display order override |
+| `alignSelf` | AlignSelf | `Auto` | `Auto`, `Start`, `Center`, `End`, `Stretch` — overrides parent `alignItems` for this item |
+| `margin` | Padding | `{left:0, top:0, right:0, bottom:0}` | Outer margin |
+| `minWidth` / `minHeight` | number | `-1` | Minimum dimensions (-1 = none) |
+| `maxWidth` / `maxHeight` | number | `-1` | Maximum dimensions (-1 = none) |
+| `widthPercent` / `heightPercent` | number | `-1` | Size as percentage of parent (-1 = disabled) |
## LayoutGroup
diff --git a/docs/astro/src/content/docs/zh/changelog-v0110.mdx b/docs/astro/src/content/docs/zh/changelog-v0110.mdx
new file mode 100644
index 000000000..f87f30996
--- /dev/null
+++ b/docs/astro/src/content/docs/zh/changelog-v0110.mdx
@@ -0,0 +1,98 @@
+---
+title: v0.11.0
+description: Estella v0.11.0 更新日志
+---
+
+import { Aside } from '@astrojs/starlight/components';
+
+<Aside type="tip">
+v0.11.0 引入完整的可视化状态机系统,使用 Yoga 替换布局引擎,上线自研 Dock 系统,并带来大量编辑器体验改进。
+</Aside>
+
+## 状态机:可视化状态管理
+
+全新的状态机系统,用于驱动动画和游戏逻辑,配备受 Rive 和 Unity Animator 启发的可视化节点图编辑器。
+
+### 组件与资产
+
+新增 `StateMachine` 组件,引用 `.statemachine` 资产文件,支持 `autoPlay`。定义命名状态(Idle、Run、Attack……),每个状态关联一个时间轴片段,通过用户自定义参数(float、int、bool、trigger)设置条件转换。
+
+### 节点图编辑器
+
+专用面板提供完整的节点图编辑体验:
+
+- 在状态节点间拖拽创建转换
+- 点击转换箭头配置条件(参数比较、退出时间)
+- 右键画布添加状态或设置默认状态
+- 多图层标签页切换
+
+### 多图层、混合状态与退出状态
+
+- **多图层**:每个图层独立运行自己的状态图,可配置权重(0.0–1.0)和混合模式(Override / Additive)
+- **混合状态(Blend State)**:通过 1D 混合树在多个时间轴片段之间混合——在阈值处定义动作条目,运行时在最近的两个动作之间插值
+- **退出状态(Exit State)**:特殊节点,表示图层已完成当前状态图,适用于一次性动画
+
+### 时间轴集成
+
+在节点图中选择状态后,时间轴面板自动打开该状态的时间轴片段进行编辑。状态机时间轴 handle 独立于常规时间轴 handle 管理。进入 Play Mode 时自动预加载时间轴资产,避免动画数据缺失。
+
+### Inspector 编辑
+
+可折叠的参数和图层编辑器,折叠状态持久保存。支持在 Inspector 中内联添加、删除、重命名参数,配置图层权重和混合模式。
+
+## Yoga 布局引擎
+
+使用 **Yoga**(Facebook 的跨平台布局引擎,React Native 同款)替换手写的 CSS Flexbox 实现,更准确地处理 flex 布局的边界情况。
+
+- `FlexContainer`:flexDirection、justifyContent、alignItems、alignContent、flexWrap、gap、padding、overflow
+- `FlexItem`:flexGrow、flexShrink、flexBasis、alignSelf、width/height、min/max 尺寸、margin、aspectRatio、position(relative/absolute)、positionInsets
+
+属性在 Inspector 中按组分类显示(布局、对齐、间距、尺寸、位置),使用更易读的显示名称。
+
+## 自研 Dock 系统
+
+使用自研 Dock 系统替换第三方 dockview 库:
+
+- **拖拽标签页**:在 dock 区域内重排序,或在区域间移动面板
+- **分割布局**:将标签页拖到边缘指示器上实现水平或垂直分割
+- **可调分隔条**:拖拽 dock 区域边界调整大小
+- **浮动面板**:任意面板可弹出为浮动窗口
+- **布局持久化**:保存至 localStorage 并在重新加载时恢复,菜单中可重置为默认布局
+
+## Add Component 弹窗
+
+"Add Component" 按钮现在打开重新设计的锚定面板:
+
+- **模糊搜索**:输入即可模糊匹配过滤组件
+- **分类列表**:组件按类别组织(渲染、UI、物理、音频、布局、动画等)
+- **键盘导航**:方向键导航,Enter 选择
+
+## spawn(name) API
+
+- `world.spawn(name?)` 创建实体时可指定名称
+- `world.getEntityByName(name)` 通过内部名称索引实现 O(1) 按名称查找实体
+- Hierarchy 面板在实体名称旁显示标签徽章,便于快速识别
+
+## 增强选择交互与 Gizmo 光标
+
+- **上下文感知光标**:移动箭头显示方向光标、缩放手柄显示缩放光标、旋转环显示旋转光标
+- **悬停高亮**:Gizmo 手柄悬停时高亮并变色
+- **点击优先级**:Gizmo 与实体重叠时优先响应 Gizmo
+
+## 多 Output Handler 支持
+
+`OutputService` 现在支持通过 `addOutputHandler()` / `removeOutputHandler()` 注册多个输出处理器。处理器按顺序调用,支持同时写入文件、发送到预览、输出到控制台等场景。
+
+## MCP 增强
+
+- 新增 UI 模板实例化路由,从模板创建 UI 层级
+- 改进截图功能,支持超时、面板内容选择器、html2canvas 集成
+- MCP 服务器提取为独立仓库,作为 git submodule 管理
+
+## Bug 修复
+
+- 修复 Windows 上预览服务器端口绑定失败
+- 修复 Windows 上 MCP bridge 文件未创建
+- 修复弹窗和下拉菜单超出视口边界——位置现在钳制到视口范围内
+- 修复 padding 编辑器与 vec 编辑器样式不一致
+- 修复新场景中 Canvas 缺少 UIRect
diff --git a/docs/astro/src/content/docs/zh/core-concepts/systems.mdx b/docs/astro/src/content/docs/zh/core-concepts/systems.mdx
index 1842d2315..bbe074edf 100644
--- a/docs/astro/src/content/docs/zh/core-concepts/systems.mdx
+++ b/docs/astro/src/content/docs/zh/core-concepts/systems.mdx
@@ -130,7 +130,7 @@ defineSystem([Commands()], (cmds) => {
| 方法 | 返回值 | 说明 |
|------|--------|------|
-| `cmds.spawn()` | `EntityCommands` | 创建新实体,返回构建器 |
+| `cmds.spawn(name?)` | `EntityCommands` | 创建新实体(可指定名称),返回构建器 |
| `cmds.entity(entity)` | `EntityCommands` | 获取已有实体的构建器 |
| `cmds.despawn(entity)` | `this` | 将实体加入销毁队列 |
| `cmds.insertResource(res, value)` | `this` | 插入或覆盖资源 |
diff --git a/docs/astro/src/content/docs/zh/guides/mcp.mdx b/docs/astro/src/content/docs/zh/guides/mcp.mdx
index e293215e1..029006925 100644
--- a/docs/astro/src/content/docs/zh/guides/mcp.mdx
+++ b/docs/astro/src/content/docs/zh/guides/mcp.mdx
@@ -13,7 +13,7 @@ Estella 编辑器内置 **MCP(Model Context Protocol)** 桥接器,允许 C
## 前提条件
-- Estella 编辑器 v0.10.0 或更高版本
+- Estella 编辑器 v0.11.0 或更高版本
- Node.js 18+
- MCP 兼容的 AI 客户端(如 Claude Desktop、Claude Code、Cursor)
@@ -136,12 +136,40 @@ AI 客户端 ←→ MCP Server (stdio) ←→ HTTP Bridge ←→ Estella 编辑
| `pause` | 暂停/恢复 |
| `set_play_speed` | 调整播放速度 |
+### UI 创建
+
+一次工具调用即可创建完整配置的 UI 控件层级。实体自动挂载到 Canvas 下。
+
+| 工具 | 说明 |
+|------|------|
+| `create_text` | 创建文本标签,支持 content、fontSize、color、align |
+| `create_image` | 创建图片元素,支持 tint color 和尺寸 |
+| `create_panel` | 创建带背景和遮罩的面板 |
+| `create_button` | 创建带背景和交互的按钮 |
+| `create_input_field` | 创建文本输入框,支持 placeholder 和初始值 |
+| `create_toggle` | 创建开关/复选框 |
+| `create_slider` | 创建带填充条和手柄的滑块 |
+| `create_progress_bar` | 创建带填充的进度条 |
+| `create_scroll_view` | 创建可滚动容器 |
+| `create_dropdown` | 创建带选项的下拉菜单 |
+
+### 编辑器状态
+
+| 工具 | 说明 |
+|------|------|
+| `get_console_logs` | 获取最近的控制台日志,可按级别过滤 |
+| `get_panel_layout` | 获取编辑器面板位置 |
+| `get_project_settings` | 获取项目设置 |
+| `get_build_status` | 获取最近的构建记录 |
+| `get_render_stats` | 获取帧时间和性能数据 |
+| `get_asset_info` | 通过 UUID 或路径获取资产详细信息 |
+
### 视觉
| 工具 | 说明 |
|------|------|
-| `screenshot` | 截取当前视口的截图 |
-| `screenshot_diff` | 逐像素比较两张截图 |
+| `capture_editor` | 截取编辑器截图(整个窗口或指定面板) |
+| `capture_diff` | 逐像素比较两张截图 |
## 示例提示
diff --git a/docs/astro/src/content/docs/zh/guides/scenes.mdx b/docs/astro/src/content/docs/zh/guides/scenes.mdx
index d5202618d..7361d1687 100644
--- a/docs/astro/src/content/docs/zh/guides/scenes.mdx
+++ b/docs/astro/src/content/docs/zh/guides/scenes.mdx
@@ -48,7 +48,18 @@ import { Aside } from '@astrojs/starlight/components';
### 按名字查找
-从场景加载的每个实体都会自动获得内置的 `Name` 组件,包含在编辑器中指定的名字。通过查询 `Name` 来查找实体:
+使用 `findEntityByName()` 进行 O(1) 名称查找:
+
+```typescript
+import { findEntityByName } from 'esengine';
+
+const player = findEntityByName(world, 'Player');
+if (player) {
+ // 找到了玩家实体
+}
+```
+
+也可以通过查询 `Name` 组件来遍历命名实体:
```typescript
import { defineSystem, addStartupSystem, Query, Name, Transform } from 'esengine';
diff --git a/docs/astro/src/content/docs/zh/guides/state-machine.mdx b/docs/astro/src/content/docs/zh/guides/state-machine.mdx
new file mode 100644
index 000000000..b3d456506
--- /dev/null
+++ b/docs/astro/src/content/docs/zh/guides/state-machine.mdx
@@ -0,0 +1,505 @@
+---
+title: 状态机
+description: Estella 可视化状态机系统,用于动画和交互式 UI
+---
+
+import { Aside } from '@astrojs/starlight/components';
+
+**StateMachine** 组件通过可视化状态图驱动动画和交互行为。定义状态,用条件转换连接它们,引擎自动处理剩余逻辑——按钮悬停效果、角色动画控制器、多步 UI 流程等常见模式无需编写脚本。
+
+<Aside type="note">
+ StateMachine 插件默认包含,无需手动配置。
+</Aside>
+
+## 教程:悬停按钮
+
+我们来一步步制作一个悬停时改变透明度的按钮。
+
+### 第 1 步:添加组件
+
+在 Hierarchy 中选择一个 UI 实体(如 Button),点击 **Add Component** → **StateMachine**。
+
+### 第 2 步:定义输入
+
+在 Inspector 中展开 StateMachine 组件,点击 **Inputs** 旁的 **+** 按钮添加参数:
+
+- **Name**: `hovered`
+- **Type**: `bool`
+- **Default**: `false`
+
+这个参数将跟踪指针是否在按钮上方。
+
+### 第 3 步:定义监听器
+
+点击 **Listeners** 旁的 **+** 添加两个事件绑定:
+
+1. **Event**: `pointerEnter` → **Input**: `hovered` → **Action**: `set` → **Value**: `true`
+2. **Event**: `pointerExit` → **Input**: `hovered` → **Action**: `reset` → **Value**: `false`
+
+现在指针事件会自动更新 `hovered` 输入。
+
+<Aside type="tip">
+ 实体需要 `UIInteraction` 组件才能使监听器生效。Button 等 UI 控件自动包含此组件。
+</Aside>
+
+### 第 4 步:在图面板中创建状态
+
+打开 **StateMachine** 面板(如果不可见,在面板菜单中找到它)。你会看到一个空画布和一个 Entry 节点。
+
+1. **右键**画布 → **Add State** → 命名为 `idle`
+2. **右键**再次 → **Add State** → 命名为 `hover`
+3. Entry 节点自动连接到第一个状态。如果需要,右键 `idle` → **Set as Default**。
+
+### 第 5 步:配置状态属性
+
+点击 `idle` 状态节点,在右侧详情面板中:
+
+1. 点击 **+ Add Property**
+2. 输入路径:`Sprite.color.a`
+3. 设置值:`1.0`
+
+点击 `hover` 状态节点并添加:
+
+- 路径:`Sprite.color.a`,值:`0.7`
+
+### 第 6 步:创建转换
+
+1. 将鼠标悬停在 `idle` 节点上,直到看到边缘出现连接手柄
+2. 从 `idle` **拖拽**到 `hover` — 创建一条转换箭头
+3. 点击箭头,在详情面板中配置:
+ - **Duration**: `0.15`(透明度补间的秒数)
+ - 点击 **+ Add Condition**:Input `hovered`,Comparator `eq`,Value `true`
+
+4. 创建第二条从 `hover` 回到 `idle` 的转换:
+ - **Duration**: `0.15`
+ - Condition:`hovered` `eq` `false`
+
+### 第 7 步:测试
+
+按 **F5** 或点击 Play。将鼠标悬停在按钮上——透明度平滑地淡入到 0.7 并恢复。
+
+### 同样的效果用代码实现
+
+```typescript
+import { Commands, StateMachine, UIInteraction } from 'esengine';
+
+cmds.spawn('my-button')
+ .insert(StateMachine, {
+ inputs: [
+ { name: 'hovered', type: 'bool', defaultValue: false },
+ ],
+ listeners: [
+ { event: 'pointerEnter', inputName: 'hovered', action: 'set', value: true },
+ { event: 'pointerExit', inputName: 'hovered', action: 'reset', value: false },
+ ],
+ initialState: 'idle',
+ states: {
+ idle: {
+ properties: { 'Sprite.color.a': 1.0 },
+ transitions: [
+ {
+ target: 'hover',
+ duration: 0.15,
+ conditions: [{ inputName: 'hovered', comparator: 'eq', value: true }],
+ },
+ ],
+ },
+ hover: {
+ properties: { 'Sprite.color.a': 0.7 },
+ transitions: [
+ {
+ target: 'idle',
+ duration: 0.15,
+ conditions: [{ inputName: 'hovered', comparator: 'eq', value: false }],
+ },
+ ],
+ },
+ },
+ });
+```
+
+## 控制输入
+
+### 通过监听器(推荐)
+
+监听器是驱动状态变化的主要方式。它们将指针事件映射为输入变化,无需编写代码:
+
+```typescript
+listeners: [
+ { event: 'pointerEnter', inputName: 'hovered', action: 'set', value: true },
+ { event: 'pointerExit', inputName: 'hovered', action: 'reset', value: false },
+ { event: 'pointerDown', inputName: 'click', action: 'set', value: true },
+ { event: 'pointerDown', inputName: 'selected', action: 'toggle' },
+]
+```
+
+在编辑器中,在 Inspector 的 StateMachine 组件 **Listeners** 部分添加监听器。
+
+### 通过初始值
+
+输入的 `defaultValue` 决定播放开始时的初始值。可以在 Inspector 中设置,也可以在代码中生成时设置:
+
+```typescript
+cmds.spawn('character')
+ .insert(StateMachine, {
+ inputs: [
+ { name: 'speed', type: 'number', defaultValue: 5 },
+ { name: 'grounded', type: 'bool', defaultValue: true },
+ ],
+ // ...states 和 transitions
+ });
+```
+
+<Aside type="caution">
+ 输入值由内部运行时管理,在 Play 模式启动时初始化一次。每个输入定义的 `defaultValue` 仅设置**初始**值。状态机开始运行后修改 `defaultValue` 不会生效——运行时使用自己内部的输入值副本。
+</Aside>
+
+### 动态控制的设计模式
+
+由于运行时输入无法从用户系统中直接修改,可以使用以下模式:
+
+**模式 1:监听器驱动** — 将游戏事件映射到不可见 UI 元素上的指针事件。例如,放置一个隐藏的 `UIInteraction` 实体接收指针事件来切换状态。
+
+**模式 2:组件驱动转换** — 不修改输入,而是让转换响应其他组件的值。例如,转换可以使用 `exitTime` 在时间轴完成后自动推进,无需更改输入。
+
+**模式 3:多个 StateMachine** — 对于复杂行为,在不同实体上使用独立的 StateMachine 组件,各自由自己的监听器驱动。
+
+## 状态详解
+
+每个状态代表一种视觉/行为配置。有三种状态类型:
+
+### 标准状态(属性模式)
+
+默认类型。进入状态时将值赋给实体属性:
+
+```typescript
+idle: {
+ properties: {
+ 'Sprite.color.a': 1.0, // 设置透明度
+ 'Transform.scale.x': 1.0, // 设置缩放
+ 'Transform.scale.y': 1.0,
+ },
+ transitions: [/* ... */],
+}
+```
+
+**属性路径**使用点号分隔:`组件名.字段.子字段`。示例:
+- `Sprite.color.r` / `.g` / `.b` / `.a` — 精灵颜色通道
+- `Transform.position.x` / `.y` — 位置
+- `Transform.scale.x` / `.y` — 缩放
+- `Transform.rotation` — 旋转角度(弧度)
+- `UIRect.size.x` / `.y` — UI 元素尺寸
+
+转换时,所有数值属性**一起补间**,共享转换的 `duration` 时长和可选的 `easing` 缓动曲线。单个转换中所有属性共用一个时长和一个缓动——无法为同一转换中的不同属性设置不同时长。非数值属性(如资产路径)在转换开始时立即应用。
+
+### 时间轴状态
+
+引用一个 `.estl` 时间轴资产。进入状态时从头播放时间轴:
+
+```typescript
+attack: {
+ timeline: 'animations/attack.estl',
+ timelineWrapMode: 'once', // 'once' 或 'loop'
+ transitions: [
+ {
+ target: 'idle',
+ conditions: [], // 无条件——使用 exitTime
+ duration: 0.1,
+ exitTime: 0.9, // 时间轴播放到 90% 后允许转换
+ },
+ ],
+}
+```
+
+`exitTime` 是 0–1 的比例值。即使所有条件都满足,转换也要等到时间轴播放超过这个进度才会触发。空的 `conditions` 数组配合 `exitTime` 意味着"动画播放完后自动转换"。
+
+### 混合状态
+
+参见下方[混合状态](#混合状态)章节。
+
+## 转换
+
+当**所有**条件同时为真时转换触发:
+
+```typescript
+{
+ target: 'run', // 目标状态名
+ duration: 0.2, // 补间时长(秒,默认:0)
+ easing: 'easeOutQuad', // 缓动曲线(默认:'linear')
+ exitTime: 0.8, // 可选:等待时间轴进度
+ conditions: [
+ { inputName: 'speed', comparator: 'gt', value: 3 },
+ { inputName: 'grounded', comparator: 'eq', value: true },
+ ],
+}
+```
+
+| 比较器 | 含义 |
+|--------|------|
+| `eq` | 等于 |
+| `neq` | 不等于 |
+| `gt` | 大于 |
+| `lt` | 小于 |
+| `gte` | 大于等于 |
+| `lte` | 小于等于 |
+
+可用缓动值:`linear`、`easeInQuad`、`easeOutQuad`、`easeInOutQuad`、`easeInCubic`、`easeOutCubic`、`easeInOutCubic`、`easeInBack`、`easeOutBack`、`easeInOutBack`、`easeInElastic`、`easeOutElastic`、`easeInOutElastic`、`easeOutBounce`
+
+转换**按顺序**求值——第一个条件全部满足的转换触发,其余在该帧跳过。
+
+## 输入
+
+三种输入类型驱动转换:
+
+| 类型 | 行为 | 适用于 |
+|------|------|--------|
+| `bool` | 保持当前值直到被更改 | 切换状态:hovered、selected、grounded |
+| `number` | 连续值,可使用 `gt`/`lt` 比较 | speed、health、混合参数 |
+| `trigger` | 设为 `true` 后**下一帧自动重置为 `false`** | 单次事件:jump、attack、death |
+
+## 监听器
+
+无需代码即可将指针事件映射到输入变更:
+
+```typescript
+listeners: [
+ // 指针进入 → 设置 hovered 为 true
+ { event: 'pointerEnter', inputName: 'hovered', action: 'set', value: true },
+ // 指针离开 → 设置 hovered 为 false
+ { event: 'pointerExit', inputName: 'hovered', action: 'reset', value: false },
+ // 点击 → 触发 'click' trigger
+ { event: 'pointerDown', inputName: 'click', action: 'set', value: true },
+ // 点击切换选中状态
+ { event: 'pointerDown', inputName: 'selected', action: 'toggle' },
+]
+```
+
+| 动作 | 效果 |
+|------|------|
+| `set` | 将输入设为 `value`(默认:`true`) |
+| `reset` | 将输入设为 `value`(默认:`false`) |
+| `toggle` | 翻转布尔输入 |
+
+## 多图层
+
+单个 StateMachine 可以包含多个**图层**,每个图层独立运行自己的状态图。所有图层共享相同的输入,但各自独立求值转换。
+
+```typescript
+{
+ inputs: [
+ { name: 'speed', type: 'number', defaultValue: 0 },
+ { name: 'attack', type: 'trigger' },
+ ],
+ listeners: [],
+ initialState: '', // 设置 layers 时忽略
+ states: {}, // 设置 layers 时忽略
+ layers: [
+ {
+ name: 'Locomotion',
+ initialState: 'idle',
+ states: {
+ idle: {
+ properties: { 'Transform.position.y': 0 },
+ transitions: [
+ { target: 'run', duration: 0.2, conditions: [{ inputName: 'speed', comparator: 'gt', value: 1 }] },
+ ],
+ },
+ run: {
+ timeline: 'animations/run.estl',
+ timelineWrapMode: 'loop',
+ transitions: [
+ { target: 'idle', duration: 0.2, conditions: [{ inputName: 'speed', comparator: 'lte', value: 1 }] },
+ ],
+ },
+ },
+ },
+ {
+ name: 'Action',
+ initialState: 'none',
+ states: {
+ none: {
+ transitions: [
+ { target: 'attack', duration: 0, conditions: [{ inputName: 'attack', comparator: 'eq', value: true }] },
+ ],
+ },
+ attack: {
+ timeline: 'animations/attack.estl',
+ timelineWrapMode: 'once',
+ transitions: [
+ { target: 'none', duration: 0.1, exitTime: 0.9, conditions: [] },
+ ],
+ },
+ },
+ },
+ ],
+}
+```
+
+在这个例子中,Locomotion 图层处理移动动画,Action 图层处理攻击——两者同时运行,可以影响同一实体上的不同属性。
+
+### Any State
+
+名为 `__any__` 的状态是通配符:它的转换在当前状态的转换**之外额外**求值,不论图层处于哪个状态。用于全局转换,比如"血量归零时从任何状态进入死亡状态"。
+
+### 退出状态
+
+图层可以转换到特殊的 `__exit__` 状态,完全停止该图层的处理。适用于单次播放的叠加图层(播放攻击动画后图层休眠)。
+
+## 混合状态
+
+混合状态根据输入值**每帧**连续插值属性,不同于标准状态只在进入时应用一次属性。当你需要平滑的、参数驱动的动画时使用混合状态——例如根据速度调整角色颜色,或用独立权重混合多个视觉效果。
+
+<Aside type="tip">
+ **何时使用混合 vs 标准状态:** 标准状态适合离散的视觉配置(空闲、悬停、按下)。混合状态适合属性需要沿连续参数平滑变化的场景(速度 → 颜色,血量 → 大小)。
+</Aside>
+
+### 1D 混合
+
+沿单个数值输入轴插值属性。定义多个**阈值**条目——引擎根据输入值在最近的两个阈值之间混合。
+
+```typescript
+locomotion: {
+ type: 'blend1d',
+ blendInput: 'speed', // 驱动混合的数值输入
+ blendStates: [
+ { threshold: 0, properties: { 'Sprite.color.g': 0.5 } },
+ { threshold: 5, properties: { 'Sprite.color.g': 0.8 } },
+ { threshold: 10, properties: { 'Sprite.color.g': 1.0 } },
+ ],
+ transitions: [],
+}
+```
+
+当 `speed` 为 2.5(在阈值 0 和 5 的中点)时,`Sprite.color.g` 线性插值到 0.65。低于最低阈值时钳制到第一个条目的值;高于最高阈值时钳制到最后一个条目的值。
+
+资产类型属性(如纹理)无法插值——它们吸附到最近的阈值。
+
+混合条目也可以引用时间轴而非属性:
+
+```typescript
+blendStates: [
+ { threshold: 0, timeline: 'animations/idle.estl', timelineWrapMode: 'loop' },
+ { threshold: 5, timeline: 'animations/walk.estl', timelineWrapMode: 'loop' },
+ { threshold: 10, timeline: 'animations/run.estl', timelineWrapMode: 'loop' },
+]
+```
+
+### 直接混合
+
+每个条目以各自的权重独立贡献。与使用单一输入轴的 1D 混合不同,直接混合让你分别控制多个效果:
+
+```typescript
+overlay: {
+ type: 'blendDirect',
+ blendStates: [
+ { mixInput: 'damageFlash', properties: { 'Sprite.color.r': 1.0 } },
+ { mixInput: 'freezeEffect', properties: { 'Sprite.color.b': 1.0 } },
+ { mixValue: 0.3, properties: { 'Sprite.color.g': 0.5 } },
+ ],
+ transitions: [],
+}
+```
+
+- **`mixInput`**:权重来自命名的数值输入(0.0–1.0)。改变输入值可控制该条目对结果的影响强度。
+- **`mixValue`**:权重是固定常数。该条目始终以此比例贡献。
+
+直接混合非常适合叠加独立的视觉效果——伤害闪光、冰冻染色、中毒发光——每个由各自的输入控制,互不干扰。
+
+### BlendEntry 参考
+
+| 属性 | 类型 | 说明 |
+|------|------|------|
+| `properties` | `Record<string, unknown>` | 属性路径 → 目标值映射(与标准状态相同) |
+| `timeline` | `string` | `.estl` 时间轴资产路径(properties 的替代方案) |
+| `timelineWrapMode` | `'once' \| 'loop'` | 时间轴播放模式(默认:`'once'`) |
+| `threshold` | `number` | 1D 混合轴上的位置(`blend1d` 必需) |
+| `mixInput` | `string` | 输入名称,其值用作混合权重(用于 `blendDirect`) |
+| `mixValue` | `number` | 固定混合权重(用于 `blendDirect`,`mixInput` 的替代方案) |
+
+## 节点图编辑器
+
+**StateMachine** 面板提供可视化编辑体验。通过 **View** → **StateMachine** 或面板菜单打开。
+
+### 画布
+
+- **状态节点**显示为圆角矩形。初始状态有绿色 Entry 箭头指向它。
+- **转换箭头**连接状态。点击箭头可选中并编辑。
+- **右键**画布背景可添加新状态或粘贴。
+- **右键**状态节点可设为默认、删除或添加转换。
+- **双击**状态可重命名。
+- **拖拽**画布平移,**滚轮**缩放。
+
+### 特殊节点
+
+| 节点 | 颜色 | 用途 |
+|------|------|------|
+| Entry | 绿色箭头 | 标记初始状态 |
+| Any State | 紫色 | 从此处出发的转换不论当前状态均可触发 |
+| Exit | 红色 | 转换到此处停止图层 |
+
+### 详情面板
+
+点击图中的**状态**或**转换**打开详情面板:
+
+**对于状态:**
+- 选择属性模式或时间轴模式
+- 属性模式:添加 属性路径 → 值 的键值对
+- 时间轴模式:选择 `.estl` 资产和循环模式
+- 混合状态:配置混合类型、输入和阈值条目
+
+**对于转换:**
+- 设置时长和缓动曲线
+- 设置 exitTime(用于时间轴状态)
+- 添加/删除条件:输入、比较器、值
+
+### 图层标签页
+
+使用多图层时,面板顶部的标签页可切换图层。每个图层有自己的图。
+
+## 组件参考
+
+### StateMachine
+
+| 属性 | 类型 | 默认值 | 说明 |
+|------|------|--------|------|
+| `states` | `Record<string, StateNode>` | `{}` | 状态定义(单图层模式) |
+| `inputs` | `InputDef[]` | `[]` | 参数定义,所有图层共享 |
+| `listeners` | `ListenerDef[]` | `[]` | 事件到输入的绑定 |
+| `initialState` | `string` | `''` | 默认状态名称(单图层模式) |
+| `layers` | `LayerData[]` | — | 多图层定义(设置后覆盖 `states` 和 `initialState`) |
+
+### StateNode
+
+| 属性 | 类型 | 默认值 | 说明 |
+|------|------|--------|------|
+| `properties` | `Record<string, unknown>` | — | 属性路径 → 目标值映射 |
+| `timeline` | `string` | — | `.estl` 时间轴资产路径 |
+| `timelineWrapMode` | `'once' \| 'loop'` | `'once'` | 时间轴播放模式 |
+| `transitions` | `Transition[]` | `[]` | 出向转换 |
+| `type` | `'standard' \| 'blend1d' \| 'blendDirect'` | `'standard'` | 状态类型 |
+| `blendInput` | `string` | — | 用于 1D 混合的输入名称 |
+| `blendStates` | `BlendEntry[]` | — | 混合树条目 |
+
+### Transition
+
+| 属性 | 类型 | 默认值 | 说明 |
+|------|------|--------|------|
+| `target` | `string` | — | 目标状态名 |
+| `conditions` | `Condition[]` | — | 所有条件必须为真才触发 |
+| `duration` | `number` | `0` | 补间时长(秒) |
+| `exitTime` | `number` | — | 检查条件前要求的时间轴进度比例(0–1) |
+| `easing` | `string` | `'linear'` | 属性补间的缓动曲线 |
+
+### Condition
+
+| 属性 | 类型 | 说明 |
+|------|------|------|
+| `inputName` | `string` | 要比较的输入名称 |
+| `comparator` | `'eq' \| 'neq' \| 'gt' \| 'lt' \| 'gte' \| 'lte'` | 比较运算符 |
+| `value` | `boolean \| number` | 比较的目标值 |
+
+## 下一步
+
+- [时间轴](/docs/zh/guides/timeline/) — 时间轴状态使用的多轨道动画系统
+- [补间动画](/docs/zh/guides/tween/) — 代码驱动的属性动画
+- [UI 交互](/docs/zh/guides/ui-interaction/) — 指针事件和焦点
diff --git a/docs/astro/src/content/docs/zh/guides/timeline.mdx b/docs/astro/src/content/docs/zh/guides/timeline.mdx
index 32496bcf4..d6d2b26cf 100644
--- a/docs/astro/src/content/docs/zh/guides/timeline.mdx
+++ b/docs/astro/src/content/docs/zh/guides/timeline.mdx
@@ -5,32 +5,141 @@ description: Estella 中的时间轴动画系统
import { Aside } from '@astrojs/starlight/components';
-**时间轴**系统驱动多轨道动画,可以在时间线上协调属性变化、Spine 播放、精灵动画、音频事件和实体激活。时间轴在编辑器的 Timeline 面板中创建,运行时通过 `TimelinePlayer` 组件和 `TimelineControl` API 播放。
+**时间轴**系统驱动多轨道动画,在时间线上协调属性变化、Spine 播放、精灵动画、音频事件和实体激活。时间轴在编辑器的 Timeline 面板中创建,运行时通过 `TimelinePlayer` 组件和 `TimelineControl` API 播放。
<Aside type="note">
时间轴插件默认包含,无需手动设置。
</Aside>
-## 编辑器工作流
+## 教程:动画化一个精灵
-1. 在 Hierarchy 中选择一个实体
-2. 打开 **Timeline** 面板
-3. 点击 **+** 添加轨道(Property、Spine、Sprite Animation、Audio、Activation)
-4. 在时间轴标尺上点击添加关键帧
-5. 时间轴保存为 `.estl` 资源文件
+我们来创建一个时间轴,让精灵从左移到右并淡出。
-### 轨道类型
+### 第 1 步:选择实体
-| 类型 | 说明 |
+在 Hierarchy 中点击你要动画化的实体。
+
+### 第 2 步:打开 Timeline 面板
+
+打开 **View** → **Timeline**(或在面板菜单中找到它)。如果实体还没有 `TimelinePlayer` 组件,面板会显示 **Create** 按钮——点击它自动添加。
+
+### 第 3 步:添加属性轨道
+
+1. 点击轨道列表中的 **+** 按钮
+2. 选择 **Property** → **Transform** → **position.x**
+3. 新轨道出现,目标指向所选实体的 `Transform.position.x`
+
+### 第 4 步:添加关键帧
+
+1. 点击顶部标尺将**播放头**移到时间 0.0
+2. 点击**菱形图标**(或按 `K`)添加关键帧——捕获当前值
+3. 将播放头移到 1.0 秒
+4. 在 Inspector 中把 position.x 改为 200
+5. 再按 `K` ——添加第二个关键帧,记录新值
+
+### 第 5 步:添加第二条轨道
+
+1. 点击 **+** → **Property** → **Sprite** → **color.a**
+2. 在时间 0.0 添加关键帧(值:1.0)
+3. 在时间 1.0 添加关键帧(值:0.0)
+
+### 第 6 步:预览
+
+按 **Space** 在编辑器中播放。精灵在 1 秒内向右移动同时淡出。
+
+### 第 7 步:配置播放
+
+在 Inspector 中设置 `TimelinePlayer` 属性:
+- **wrapMode**: `loop` 循环播放
+- **speed**: `0.5` 半速播放
+
+## 轨道目标定位
+
+每条轨道都有一个**目标实体**。默认情况下,目标是拥有 `TimelinePlayer` 组件的实体。
+
+### 动画化子实体
+
+要动画化子实体,设置轨道的 **Child Path** —— 以 `/` 分隔的名称层级路径:
+
+```
+Arm/Hand → 找到子实体 "Arm",再找它的子实体 "Hand"
+Body → 找到直接子实体 "Body"
+(空) → 目标为根实体自身
+```
+
+在编辑器中,当你在选中子实体时添加轨道,child path 会自动设置。
+
+<Aside type="tip">
+ Child path 在播放开始时解析一次。目标实体必须在播放时间轴之前就存在于层级中。
+</Aside>
+
+## 轨道类型
+
+### Property(属性)
+
+通过关键帧插值动画化任意数值组件属性。
+
+**内置属性**(优化路径,在 C++ 中计算):
+
+| 组件 | 属性 |
+|------|------|
+| Transform | position.x/y/z, scale.x/y/z, rotation |
+| Sprite | color.r/g/b/a, opacity, size.x/y |
+| UIRect | offsetMin.x/y, offsetMax.x/y, anchorMin.x/y, anchorMax.x/y, pivot.x/y |
+| Camera | orthoSize |
+
+**自定义属性**:其他任何数值组件字段都可以通过嵌套路径动画化(如 `myComponent.health`)。
+
+#### 关键帧插值
+
+右键关键帧可选择插值模式:
+
+| 模式 | 行为 |
|------|------|
-| Property | 通过关键帧插值动画化任意数值组件属性(位置、缩放、颜色等) |
-| Spine | 在 SpineAnimation 组件上触发 Spine 动画片段 |
-| Sprite Animation | 播放精灵动画片段 |
-| AnimFrames | 可视化帧轨道——每个精灵帧显示为带颜色、可调整大小的色块,拥有独立时长 |
-| Audio | 在特定时间触发音频事件 |
-| Activation | 在时间范围内启用/禁用实体 |
-| Marker | 在特定时间放置命名标记 |
-| Custom Event | 在特定时间触发自定义事件 |
+| Hermite | 使用切线手柄的平滑三次曲线(默认) |
+| Linear | 关键帧之间的直线 |
+| Step | 保持值直到下一个关键帧(无插值) |
+| EaseIn | 缓慢开始,加速到下一个关键帧 |
+| EaseOut | 快速开始,减速到下一个关键帧 |
+| EaseInOut | 平滑的加速和减速 |
+
+Hermite 模式下,拖拽曲线编辑器中的切线手柄可以调整插值曲线形状。
+
+### Spine
+
+在 `SpineAnimation` 组件上触发 Spine 动画片段。每个关键帧指定一个在该时间播放的动画名称。
+
+### Sprite Animation(精灵动画)
+
+播放精灵动画片段。每个关键帧指定一个在该时间开始的片段名称。
+
+### AnimFrames(帧动画)
+
+用于精灵序列帧动画的可视化帧轨道。与精灵动画片段不同,每帧显示为时间轴上**带颜色、可调整大小的色块**:
+
+- 每个色块引用一张纹理,拥有独立的**时长**(默认:1/12 秒)
+- **拖拽色块边缘**调整帧时序
+- 目标实体必须有 `Sprite` 组件——每帧自动切换纹理
+
+当你需要逐帧控制时序而不想创建单独的动画片段时,使用 AnimFrames。
+
+### Audio(音频)
+
+在特定时间触发音频播放。每个关键帧指定一个要播放的音频资源。
+
+### Activation(激活)
+
+在时间范围内切换实体可见性。实体在活动范围内启用,范围外禁用。
+
+### Marker(标记)
+
+在特定时间放置命名标记。标记不影响播放——仅作为编辑器中的参考点和定位用途。
+
+### Custom Event(自定义事件)
+
+在特定时间触发命名事件。在你的系统中监听这些事件,可以在动画的精确时刻执行自定义逻辑。
+
+## 编辑器控制
### 快捷键
@@ -42,30 +151,45 @@ import { Aside } from '@astrojs/starlight/components';
| `Delete` | 删除选中的关键帧 |
| `Ctrl+Click` | 切换关键帧选择 |
| `Shift+Click` | 范围选择关键帧 |
+| 框选拖拽 | 橡皮筋选择多个关键帧 |
-### 工具栏控件
+### 工具栏
-- **录制**:切换自动关键帧模式——属性变更会自动记录为关键帧
+- **录制**:切换自动关键帧模式——在 Inspector 中修改属性时自动在当前播放头位置记录关键帧
- **速度**:循环切换播放速度(0.25x、0.5x、1x、2x、4x)
- **循环模式**:循环切换 Once、Loop 和 PingPong
- **吸附**:切换拖拽关键帧时的网格吸附
- **时长**:双击时间显示可编辑总时长
+### 多选与批量操作
+
+选择多个关键帧(Ctrl+Click、Shift+Click 或框选),然后:
+- **拖拽**一起移动
+- **Delete** 作为单次撤销步骤删除
+
+### 轨道管理
+
+- **拖拽**轨道重新排序
+- **右键**轨道可重命名/删除
+- 每种轨道类型在侧边栏有不同颜色标识
+
### 实时播放头同步
-进入 Play 模式时,时间轴自动切换到 **LIVE** 模式。播放头实时跟踪运行时动画位置,工具栏显示红色"LIVE"指示器。LIVE 模式下编辑器播放控件被禁用,退出 Play 模式后恢复。
+进入 Play 模式时,时间轴自动切换到 **LIVE** 模式。播放头以 60fps 实时跟踪运行时动画位置,工具栏显示红色闪烁的"LIVE"指示器。LIVE 模式下编辑器播放控件被禁用,退出 Play 模式后恢复。
## TimelinePlayer 组件
-将 `TimelinePlayer` 添加到实体上即可在运行时播放时间轴资源。可在编辑器 Inspector 中配置或通过代码设置。
+将 `TimelinePlayer` 添加到实体上即可在运行时播放时间轴资源。
| 属性 | 类型 | 默认值 | 说明 |
|------|------|--------|------|
| `timeline` | string | `''` | `.estl` 时间轴资源路径 |
-| `playing` | boolean | `false` | 是否正在播放 |
+| `playing` | boolean | `false` | 设为 `true` 开始播放 |
| `speed` | number | `1.0` | 播放速度倍率 |
| `wrapMode` | string | `'once'` | `'once'`、`'loop'` 或 `'pingPong'` |
+当 `playing` 设为 `true` 时开始播放。播放完成后(`once` 模式下),`playing` 自动恢复为 `false`。
+
### WrapMode
| 值 | 说明 |
@@ -76,7 +200,7 @@ import { Aside } from '@astrojs/starlight/components';
## TimelineControl API
-在系统中使用 `TimelineControl` 控制时间轴播放:
+在系统中使用 `TimelineControl` 进行运行时播放控制:
```typescript
import { defineSystem, addSystem, Query, TimelinePlayer, TimelineControl } from 'esengine';
@@ -115,13 +239,9 @@ addSystem(defineSystem(
```typescript
import { registerTimelineAsset, getTimelineAsset, parseTimelineAsset } from 'esengine';
-// 解析原始时间轴数据
const asset = parseTimelineAsset(jsonData);
-
-// 注册供运行时查找
registerTimelineAsset('timelines/intro.estl', asset);
-// 之后获取
const tl = getTimelineAsset('timelines/intro.estl');
```
@@ -145,12 +265,12 @@ addStartupSystem(defineSystem(
}
));
-// 按任意键跳过
+// 按 Space 跳过
addSystem(defineSystem(
[Res(Input), Query(TimelinePlayer)],
(input, query) => {
if (input.isKeyPressed('Space')) {
- for (const [entity, player] of query) {
+ for (const [entity] of query) {
if (TimelineControl.isPlaying(entity)) {
TimelineControl.stop(entity);
}
@@ -162,6 +282,7 @@ addSystem(defineSystem(
## 下一步
+- [状态机](/docs/zh/guides/state-machine/) — 通过状态转换驱动时间轴
- [Tween 动画](/docs/zh/guides/tween/) — 代码驱动的属性动画
- [Spine 动画](/docs/zh/guides/spine/) — 骨骼动画
- [精灵动画](/docs/zh/guides/sprite-animation/) — 逐帧精灵动画
diff --git a/docs/astro/src/content/docs/zh/guides/ui.mdx b/docs/astro/src/content/docs/zh/guides/ui.mdx
index 41000e4d4..db8650afd 100644
--- a/docs/astro/src/content/docs/zh/guides/ui.mdx
+++ b/docs/astro/src/content/docs/zh/guides/ui.mdx
@@ -52,7 +52,7 @@ addStartupSystem(defineSystem([Commands()], (cmds) => {
## FlexContainer
-类似 CSS Flexbox 的自动子元素排列布局。
+类似 CSS Flexbox 的自动子元素排列布局,基于 [Yoga](https://yogalayout.dev/) 布局引擎。
| 属性 | 类型 | 默认值 | 说明 |
|------|------|--------|------|
@@ -60,8 +60,9 @@ addStartupSystem(defineSystem([Commands()], (cmds) => {
| `wrap` | FlexWrap | `NoWrap` | `NoWrap`、`Wrap` |
| `justifyContent` | JustifyContent | `Start` | `Start`、`Center`、`End`、`SpaceBetween`、`SpaceAround`、`SpaceEvenly` |
| `alignItems` | AlignItems | `Stretch` | `Start`、`Center`、`End`、`Stretch` |
-| `gap` | Vec2 | `{0, 0}` | 子元素间距 |
-| `padding` | Vec4 | `{x:0, y:0, z:0, w:0}` | 内边距,格式为 `{x: 上, y: 右, z: 下, w: 左}` |
+| `alignContent` | AlignContent | `Start` | `Start`、`Center`、`End`、`Stretch`、`SpaceBetween`、`SpaceAround` — 控制多行交叉轴对齐 |
+| `gap` | Vec2 | `{0, 0}` | 子元素间距(`x` = 列间距,`y` = 行间距) |
+| `padding` | Padding | `{left:0, top:0, right:0, bottom:0}` | 内边距 |
## FlexItem
@@ -73,6 +74,11 @@ addStartupSystem(defineSystem([Commands()], (cmds) => {
| `flexShrink` | number | `1` | 空间不足时收缩的比例 |
| `flexBasis` | number | `-1` | 扩展/收缩前的基础尺寸(-1 = 自动) |
| `order` | number | `0` | 显示顺序覆盖 |
+| `alignSelf` | AlignSelf | `Auto` | `Auto`、`Start`、`Center`、`End`、`Stretch` — 覆盖父级 `alignItems` |
+| `margin` | Padding | `{left:0, top:0, right:0, bottom:0}` | 外边距 |
+| `minWidth` / `minHeight` | number | `-1` | 最小尺寸(-1 = 无限制) |
+| `maxWidth` / `maxHeight` | number | `-1` | 最大尺寸(-1 = 无限制) |
+| `widthPercent` / `heightPercent` | number | `-1` | 相对父级的百分比尺寸(-1 = 禁用) |
## LayoutGroup