feat: 预制体系统与架构改进 (#303)
* feat(prefab): 实现预制体系统和编辑器 UX 改进 ## 预制体系统 - 新增 PrefabSerializer: 预制体序列化/反序列化 - 新增 PrefabInstanceComponent: 追踪预制体实例来源和修改 - 新增 PrefabService: 预制体核心服务 - 新增 PrefabLoader: 预制体资产加载器 - 新增预制体命令: Create/Instantiate/Apply/Revert/BreakLink ## 预制体编辑模式 - 支持双击 .prefab 文件进入编辑模式 - 预制体编辑模式工具栏 (保存/退出) - 预制体实例指示器和操作菜单 ## 编辑器 UX 改进 - SceneHierarchy 快捷键: F2 重命名, Ctrl+D 复制, ↑↓ 导航 - 支持双击实体名称内联编辑 - 删除实体时显示子节点数量警告 - 右键菜单添加重命名/复制选项及快捷键提示 - 布局持久化和重置功能 ## Bug 修复 - 修复 editor-runtime 组件类重复导致的 TransformComponent 不识别问题 - 修复 .prefab-name 样式覆盖导致预制体工具栏文字不可见 - 修复 Inspector 资源字段高度不正确问题 * feat(editor): 改进编辑器 UX 交互体验 - ContentBrowser: 加载动画 spinner、搜索高亮、改进空状态设计 - SceneHierarchy: 选中项自动滚动到视图、搜索清除按钮 - PropertyInspector: 输入框本地状态管理、Enter/Escape 键处理 - EntityInspector: 组件折叠状态持久化、属性搜索清除按钮 - Viewport: 变换操作实时数值显示 - 国际化: 添加相关文本 (en/zh) * fix(build): 修复 Web 构建资产加载和编辑器 UX 改进 构建系统修复: - 修复 asset-catalog.json 字段名不匹配 (entries vs assets) - 修复 BrowserFileSystemService 支持两种目录格式 - 修复 bundle 策略检测逻辑 (空对象判断) - 修复 module.json 中 assetExtensions 声明和类型推断 行为树修复: - 修复 BehaviorTreeExecutionSystem 使用 loadAsset 替代 loadAssetByPath - 修复 BehaviorTreeAssetType 常量与 module.json 类型名一致 (behavior-tree) 编辑器 UX 改进: - 构建完成对话框添加"打开文件夹"按钮 - 构建完成对话框样式优化 (圆形图标背景、按钮布局) - SceneHierarchy 响应式布局 (窄窗口自动隐藏 Type 列) - SceneHierarchy 隐藏滚动条 错误追踪: - 添加全局错误处理器写入日志文件 (%TEMP%/esengine-editor-crash.log) - 添加 append_to_log Tauri 命令 * feat(render): 修复 UI 渲染和点击特效系统 ## UI 渲染修复 - 修复 GUID 验证 bug,使用统一的 isValidGUID() 函数 - 修复 UI 渲染顺序随机问题,Rust 端使用 IndexMap 替代 HashMap - Web 运行时添加 assetPathResolver 支持 GUID 解析 - UIInteractableComponent.blockEvents 默认值改为 false ## 点击特效系统 - 新增 ClickFxComponent 和 ClickFxSystem - 支持在点击位置播放粒子效果 - 支持多种触发模式和粒子轮换 ## Camera 系统重构 - CameraSystem 从 ecs-engine-bindgen 移至 camera 包 - 新增 CameraManager 统一管理相机 ## 编辑器改进 - 改进属性面板 UI 交互 - 粒子编辑器面板优化 - Transform 命令系统 * feat(render): 实现 Sorting Layer 系统和 Overlay 渲染层 - 新增 SortingLayerManager 管理排序层级 (Background, Default, Foreground, UI, Overlay) - 实现 ISortable 接口,统一 Sprite、UI、Particle 的排序属性 - 修复粒子 Overlay 层被 UI 遮挡问题:添加独立的 Overlay Pass 在 UI 之后渲染 - 更新粒子资产格式:从 sortingOrder 改为 sortingLayer + orderInLayer - 更新粒子编辑器面板支持新的排序属性 - 优化 UI 渲染系统使用新的排序层级 * feat(ci): 集成 SignPath 代码签名服务 - 添加 SignPath 自动签名工作流(Windows) - 配置 release-editor.yml 支持代码签名 - 将构建改为草稿模式,等待签名完成后发布 - 添加证书文件到 .gitignore 防止泄露 * fix(asset): 修复 Web 构建资产路径解析和全局单例移除 ## 资产路径修复 - 修复 Tauri 本地服务器 `/asset?path=...` 路径解析,正确与 root 目录连接 - BrowserPathResolver 支持两种模式: - 'proxy': 使用 /asset?path=... 格式(编辑器 Run in Browser) - 'direct': 使用直接路径 /assets/path.png(独立 Web 构建) - BrowserRuntime 使用 'direct' 模式,无需 Tauri 代理 ## 架构改进 - 移除全局单例 - 移除 globalAssetManager 导出,改用 AssetManagerToken 依赖注入 - 移除 globalPathResolver 导出,改用 PathResolutionService - 移除 globalPathResolutionService 导出 - ParticleUpdateSystem/ClickFxSystem 通过 setAssetManager() 注入依赖 - EngineService 使用 new AssetManager() 替代全局实例 ## 新增服务 - PathResolutionService: 统一路径解析接口 - RuntimeModeService: 运行时模式查询服务 - SerializationContext: EntityRef 序列化上下文 ## 其他改进 - 完善 ServiceToken 注释说明本地定义的意图 - 导出 BrowserPathResolveMode 类型 * fix(build): 添加 world-streaming composite 设置修复类型检查 * fix(build): 移除 world-streaming 引用避免 composite 冲突 * fix(build): 将 const enum 改为 enum 兼容 isolatedModules * fix(build): 添加缺失的 IAssetManager 导入
This commit is contained in:
@@ -1,12 +1,13 @@
|
||||
import { Component, ECSComponent, Property, Serializable, Serialize } from '@esengine/ecs-framework';
|
||||
import { assetManager } from '@esengine/asset-system';
|
||||
import type { IAssetManager } from '@esengine/asset-system';
|
||||
import { SortingLayers, type ISortable } from '@esengine/engine-core';
|
||||
import { ParticlePool, type Particle } from './Particle';
|
||||
import { ParticleEmitter, EmissionShape, createDefaultEmitterConfig, type EmitterConfig, type ColorValue } from './ParticleEmitter';
|
||||
import type { IParticleModule } from './modules/IParticleModule';
|
||||
import { ColorOverLifetimeModule } from './modules/ColorOverLifetimeModule';
|
||||
import { SizeOverLifetimeModule } from './modules/SizeOverLifetimeModule';
|
||||
import { CollisionModule } from './modules/CollisionModule';
|
||||
import { ForceFieldModule } from './modules/ForceFieldModule';
|
||||
import { CollisionModule, BoundaryType, CollisionBehavior } from './modules/CollisionModule';
|
||||
import { ForceFieldModule, ForceFieldType, type ForceField } from './modules/ForceFieldModule';
|
||||
import { Physics2DCollisionModule } from './modules/Physics2DCollisionModule';
|
||||
import type { IParticleAsset, IBurstConfig } from './loaders/ParticleLoader';
|
||||
|
||||
@@ -40,6 +41,29 @@ export enum SimulationSpace {
|
||||
World = 'world'
|
||||
}
|
||||
|
||||
/**
|
||||
* 渲染空间
|
||||
* Render space
|
||||
*
|
||||
* 决定粒子在哪个坐标空间渲染。
|
||||
* Determines which coordinate space the particles are rendered in.
|
||||
*/
|
||||
export enum RenderSpace {
|
||||
/**
|
||||
* 世界空间 - 受世界相机影响
|
||||
* World space - affected by world camera
|
||||
*/
|
||||
World = 'world',
|
||||
/**
|
||||
* 屏幕空间 - 使用固定正交投影,不受世界相机影响
|
||||
* Screen space - uses fixed orthographic projection, not affected by world camera
|
||||
*
|
||||
* 适用于点击特效、UI 粒子等需要固定在屏幕上的效果。
|
||||
* Suitable for click effects, UI particles, and other effects that need to stay fixed on screen.
|
||||
*/
|
||||
Screen = 'screen'
|
||||
}
|
||||
|
||||
/**
|
||||
* 运行时覆盖配置
|
||||
* Runtime override configuration
|
||||
@@ -95,8 +119,8 @@ export interface ParticleRuntimeOverrides {
|
||||
* ```
|
||||
*/
|
||||
@ECSComponent('ParticleSystem')
|
||||
@Serializable({ version: 3, typeId: 'ParticleSystem' })
|
||||
export class ParticleSystemComponent extends Component {
|
||||
@Serializable({ version: 4, typeId: 'ParticleSystem' })
|
||||
export class ParticleSystemComponent extends Component implements ISortable {
|
||||
// ============= 资产引用 | Asset Reference =============
|
||||
|
||||
/**
|
||||
@@ -144,6 +168,49 @@ export class ParticleSystemComponent extends Component {
|
||||
})
|
||||
public simulationSpace: SimulationSpace = SimulationSpace.World;
|
||||
|
||||
// ============= 排序 | Sorting =============
|
||||
|
||||
/**
|
||||
* 排序层
|
||||
* Sorting layer
|
||||
*
|
||||
* 决定渲染的大类顺序。
|
||||
* Determines the major render order category.
|
||||
*/
|
||||
@Serialize()
|
||||
@Property({
|
||||
type: 'enum',
|
||||
label: 'Sorting Layer',
|
||||
options: ['Background', 'Default', 'Foreground', 'WorldOverlay', 'UI', 'ScreenOverlay', 'Modal']
|
||||
})
|
||||
public sortingLayer: string = SortingLayers.Default;
|
||||
|
||||
/**
|
||||
* 层内顺序(越高越在上面)
|
||||
* Order within layer (higher = rendered on top)
|
||||
*/
|
||||
@Serialize()
|
||||
@Property({ type: 'integer', label: 'Order in Layer' })
|
||||
public orderInLayer: number = 0;
|
||||
|
||||
/**
|
||||
* 渲染空间
|
||||
* Render space
|
||||
*
|
||||
* World: 世界空间,受相机影响(默认)
|
||||
* Screen: 屏幕空间,固定在屏幕上,适用于点击特效等
|
||||
*/
|
||||
@Serialize()
|
||||
@Property({
|
||||
type: 'enum',
|
||||
label: 'Render Space',
|
||||
options: [
|
||||
{ label: 'World', value: RenderSpace.World },
|
||||
{ label: 'Screen', value: RenderSpace.Screen }
|
||||
]
|
||||
})
|
||||
public renderSpace: RenderSpace = RenderSpace.World;
|
||||
|
||||
// ============= 运行时覆盖 | Runtime Overrides =============
|
||||
|
||||
/**
|
||||
@@ -279,11 +346,6 @@ export class ParticleSystemComponent extends Component {
|
||||
return this._loadedAsset?.textureGuid ?? '';
|
||||
}
|
||||
|
||||
/** 排序顺序(从资产读取)| Sorting order (from asset) */
|
||||
get sortingOrder(): number {
|
||||
return this._loadedAsset?.sortingOrder ?? 0;
|
||||
}
|
||||
|
||||
/** 爆发列表(从资产读取)| Burst list (from asset) */
|
||||
get bursts(): IBurstConfig[] {
|
||||
return this._loadedAsset?.bursts ?? [];
|
||||
@@ -353,10 +415,15 @@ export class ParticleSystemComponent extends Component {
|
||||
* 加载粒子资产
|
||||
* Load particle asset
|
||||
*
|
||||
* @deprecated 建议通过 ParticleUpdateSystem 加载资产,系统会自动处理资产加载和初始化。
|
||||
* Prefer loading assets through ParticleUpdateSystem, which handles asset loading and initialization automatically.
|
||||
*
|
||||
* @param guid - Asset GUID to load | 要加载的资产 GUID
|
||||
* @param bForceReload - 是否强制重新加载 | Whether to force reload
|
||||
* @param assetManager - 资产管理器实例(必需)| Asset manager instance (required)
|
||||
* @returns Promise that resolves when asset is loaded | 资产加载完成时解析的 Promise
|
||||
*/
|
||||
async loadAsset(guid: string, bForceReload: boolean = false): Promise<boolean> {
|
||||
async loadAsset(guid: string, bForceReload: boolean = false, assetManager?: IAssetManager): Promise<boolean> {
|
||||
if (!guid) {
|
||||
this._loadedAsset = null;
|
||||
this._lastLoadedGuid = '';
|
||||
@@ -370,8 +437,12 @@ export class ParticleSystemComponent extends Component {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!assetManager) {
|
||||
console.error('[ParticleSystem] assetManager is required for loadAsset. Use ParticleUpdateSystem for automatic asset loading.');
|
||||
return false;
|
||||
}
|
||||
|
||||
try {
|
||||
console.log(`[ParticleSystem] Loading asset: ${guid}${bForceReload ? ' (force reload)' : ''}`);
|
||||
const result = await assetManager.loadAsset<IParticleAsset>(guid, { forceReload: bForceReload });
|
||||
const asset = result?.asset;
|
||||
|
||||
@@ -379,7 +450,15 @@ export class ParticleSystemComponent extends Component {
|
||||
this._loadedAsset = asset;
|
||||
this._lastLoadedGuid = guid;
|
||||
this._needsRebuild = true;
|
||||
console.log(`[ParticleSystem] Asset loaded successfully:`, asset.name);
|
||||
|
||||
// 应用资产的排序属性 | Apply sorting properties from asset
|
||||
if (asset.sortingLayer) {
|
||||
this.sortingLayer = asset.sortingLayer;
|
||||
}
|
||||
if (asset.orderInLayer !== undefined) {
|
||||
this.orderInLayer = asset.orderInLayer;
|
||||
}
|
||||
|
||||
return true;
|
||||
} else {
|
||||
console.warn(`[ParticleSystem] Failed to load asset: ${guid}`);
|
||||
@@ -395,12 +474,17 @@ export class ParticleSystemComponent extends Component {
|
||||
* 强制重新加载资产
|
||||
* Force reload the asset
|
||||
*
|
||||
* @deprecated 建议通过 ParticleUpdateSystem 加载资产。
|
||||
* Prefer loading assets through ParticleUpdateSystem.
|
||||
*
|
||||
* 当资产文件内容变化时调用此方法,强制从文件系统重新加载。
|
||||
* Call this method when asset file content changes, forcing a reload from filesystem.
|
||||
*
|
||||
* @param assetManager - 资产管理器实例(必需)| Asset manager instance (required)
|
||||
*/
|
||||
async reloadAsset(): Promise<boolean> {
|
||||
async reloadAsset(assetManager?: IAssetManager): Promise<boolean> {
|
||||
if (!this.particleAssetGuid) return false;
|
||||
return this.loadAsset(this.particleAssetGuid, true);
|
||||
return this.loadAsset(this.particleAssetGuid, true, assetManager);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -668,26 +752,89 @@ export class ParticleSystemComponent extends Component {
|
||||
this._emitter.config = config;
|
||||
}
|
||||
|
||||
// 设置默认模块 | Setup default modules
|
||||
if (this._modules.length === 0) {
|
||||
// 颜色模块(淡出)| Color module (fade out)
|
||||
const colorModule = new ColorOverLifetimeModule();
|
||||
colorModule.gradient = [
|
||||
{ time: 0, r: 1, g: 1, b: 1, a: 1 },
|
||||
{ time: 1, r: 1, g: 1, b: 1, a: endAlpha }
|
||||
];
|
||||
this._modules.push(colorModule);
|
||||
// 重建模块列表 | Rebuild modules list
|
||||
// 每次重建时清空并重新创建,确保配置同步
|
||||
// Clear and recreate on each rebuild to ensure config is in sync
|
||||
this._modules = [];
|
||||
|
||||
// 缩放模块 | Size module
|
||||
const sizeModule = new SizeOverLifetimeModule();
|
||||
sizeModule.startMultiplier = 1;
|
||||
sizeModule.endMultiplier = endScale;
|
||||
this._modules.push(sizeModule);
|
||||
}
|
||||
// 颜色模块(淡出)| Color module (fade out)
|
||||
const colorModule = new ColorOverLifetimeModule();
|
||||
colorModule.gradient = [
|
||||
{ time: 0, r: 1, g: 1, b: 1, a: 1 },
|
||||
{ time: 1, r: 1, g: 1, b: 1, a: endAlpha }
|
||||
];
|
||||
this._modules.push(colorModule);
|
||||
|
||||
// 缩放模块 | Size module
|
||||
const sizeModule = new SizeOverLifetimeModule();
|
||||
sizeModule.startMultiplier = 1;
|
||||
sizeModule.endMultiplier = endScale;
|
||||
this._modules.push(sizeModule);
|
||||
|
||||
// 从资产配置创建模块 | Create modules from asset configuration
|
||||
this._createModulesFromAsset(asset);
|
||||
|
||||
this._needsRebuild = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 从资产配置创建模块实例
|
||||
* Create module instances from asset configuration
|
||||
*/
|
||||
private _createModulesFromAsset(asset: IParticleAsset): void {
|
||||
if (!asset.modules || asset.modules.length === 0) return;
|
||||
|
||||
for (const moduleConfig of asset.modules) {
|
||||
if (!moduleConfig.enabled) continue;
|
||||
|
||||
switch (moduleConfig.type) {
|
||||
case 'Collision': {
|
||||
const collisionModule = new CollisionModule();
|
||||
const params = moduleConfig.params;
|
||||
if (params.boundaryType !== undefined) {
|
||||
collisionModule.boundaryType = params.boundaryType as BoundaryType;
|
||||
}
|
||||
if (params.behavior !== undefined) {
|
||||
collisionModule.behavior = params.behavior as CollisionBehavior;
|
||||
}
|
||||
if (params.left !== undefined) collisionModule.left = params.left as number;
|
||||
if (params.right !== undefined) collisionModule.right = params.right as number;
|
||||
if (params.top !== undefined) collisionModule.top = params.top as number;
|
||||
if (params.bottom !== undefined) collisionModule.bottom = params.bottom as number;
|
||||
if (params.radius !== undefined) collisionModule.radius = params.radius as number;
|
||||
if (params.bounceFactor !== undefined) collisionModule.bounceFactor = params.bounceFactor as number;
|
||||
if (params.lifeLossOnBounce !== undefined) collisionModule.lifeLossOnBounce = params.lifeLossOnBounce as number;
|
||||
if (params.minVelocityThreshold !== undefined) collisionModule.minVelocityThreshold = params.minVelocityThreshold as number;
|
||||
this._modules.push(collisionModule);
|
||||
break;
|
||||
}
|
||||
case 'ForceField': {
|
||||
const forceModule = new ForceFieldModule();
|
||||
const params = moduleConfig.params;
|
||||
// ForceFieldModule 使用 forceFields 数组 | ForceFieldModule uses forceFields array
|
||||
const field: ForceField = {
|
||||
type: (params.type as ForceFieldType) ?? ForceFieldType.Wind,
|
||||
enabled: true,
|
||||
strength: (params.strength as number) ?? 100,
|
||||
directionX: params.directionX as number | undefined,
|
||||
directionY: params.directionY as number | undefined,
|
||||
centerX: params.centerX as number | undefined,
|
||||
centerY: params.centerY as number | undefined,
|
||||
inwardStrength: params.inwardStrength as number | undefined,
|
||||
frequency: params.frequency as number | undefined,
|
||||
amplitude: params.amplitude as number | undefined,
|
||||
};
|
||||
forceModule.forceFields.push(field);
|
||||
this._modules.push(forceModule);
|
||||
break;
|
||||
}
|
||||
// 可扩展其他模块类型 | Extensible for other module types
|
||||
default:
|
||||
console.warn(`[ParticleSystem] Unknown module type: ${moduleConfig.type}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private _simulate(
|
||||
dt: number,
|
||||
worldX: number,
|
||||
@@ -752,6 +899,15 @@ export class ParticleSystemComponent extends Component {
|
||||
const normalizedAge = p.age / p.lifetime;
|
||||
for (const module of this._modules) {
|
||||
if (module.enabled) {
|
||||
// 更新模块的发射器位置 | Update module emitter position
|
||||
if (module instanceof CollisionModule) {
|
||||
module.emitterX = worldX;
|
||||
module.emitterY = worldY;
|
||||
}
|
||||
if (module instanceof ForceFieldModule) {
|
||||
module.emitterX = worldX;
|
||||
module.emitterY = worldY;
|
||||
}
|
||||
module.update(p, dt, normalizedAge);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user