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,6 +1,7 @@
|
||||
{
|
||||
"id": "particle",
|
||||
"name": "@esengine/particle",
|
||||
"globalKey": "particle",
|
||||
"displayName": "Particle System",
|
||||
"description": "2D particle system for visual effects | 2D 粒子系统用于视觉特效",
|
||||
"version": "1.0.0",
|
||||
@@ -15,6 +16,7 @@
|
||||
"isCore": false,
|
||||
"defaultEnabled": true,
|
||||
"isEngineModule": true,
|
||||
"hasRuntime": true,
|
||||
"canContainContent": true,
|
||||
"platforms": [
|
||||
"web",
|
||||
@@ -40,6 +42,10 @@
|
||||
"ParticleLoader"
|
||||
]
|
||||
},
|
||||
"assetExtensions": {
|
||||
".particle": "particle",
|
||||
".particle.json": "particle"
|
||||
},
|
||||
"editorPackage": "@esengine/particle-editor",
|
||||
"requiresWasm": false,
|
||||
"outputPath": "dist/index.js",
|
||||
|
||||
@@ -44,6 +44,7 @@
|
||||
"@esengine/engine-core": "workspace:*",
|
||||
"@esengine/ecs-engine-bindgen": "workspace:*",
|
||||
"@esengine/physics-rapier2d": "workspace:*",
|
||||
"@esengine/camera": "workspace:*",
|
||||
"@esengine/build-config": "workspace:*",
|
||||
"rimraf": "^5.0.5",
|
||||
"tsup": "^8.0.0",
|
||||
|
||||
213
packages/particle/src/ClickFxComponent.ts
Normal file
213
packages/particle/src/ClickFxComponent.ts
Normal file
@@ -0,0 +1,213 @@
|
||||
/**
|
||||
* 点击特效组件 - 在点击位置播放粒子效果
|
||||
* Click FX Component - Play particle effects at click position
|
||||
*
|
||||
* 类似 Unity 的 ShowFxWhenClicked 功能。
|
||||
* Similar to Unity's ShowFxWhenClicked functionality.
|
||||
*
|
||||
* @example
|
||||
* ```typescript
|
||||
* // 在编辑器中添加此组件到相机或空实体上
|
||||
* // Add this component to camera or empty entity in editor
|
||||
*
|
||||
* // 配置粒子资产列表,点击时会轮换播放
|
||||
* // Configure particle asset list, will cycle through on click
|
||||
* clickFx.particleAssets = ['guid1', 'guid2', 'guid3'];
|
||||
* ```
|
||||
*/
|
||||
|
||||
import { Component, ECSComponent, Property, Serializable, Serialize } from '@esengine/ecs-framework';
|
||||
|
||||
/**
|
||||
* 点击特效触发模式
|
||||
* Click FX trigger mode
|
||||
*/
|
||||
export enum ClickFxTriggerMode {
|
||||
/** 鼠标左键点击 | Left mouse button click */
|
||||
LeftClick = 'leftClick',
|
||||
/** 鼠标右键点击 | Right mouse button click */
|
||||
RightClick = 'rightClick',
|
||||
/** 任意鼠标按钮 | Any mouse button */
|
||||
AnyClick = 'anyClick',
|
||||
/** 触摸 | Touch */
|
||||
Touch = 'touch',
|
||||
/** 鼠标和触摸都响应 | Both mouse and touch */
|
||||
All = 'all'
|
||||
}
|
||||
|
||||
/**
|
||||
* 点击特效组件
|
||||
* Click FX Component
|
||||
*
|
||||
* 在用户点击/触摸屏幕时,在点击位置播放粒子效果。
|
||||
* Plays particle effects at the click/touch position when user interacts.
|
||||
*/
|
||||
@ECSComponent('ClickFx')
|
||||
@Serializable({ version: 1, typeId: 'ClickFx' })
|
||||
export class ClickFxComponent extends Component {
|
||||
/**
|
||||
* 粒子资产 GUID 列表
|
||||
* List of particle asset GUIDs
|
||||
*
|
||||
* 多个资产会轮换播放,实现多样化的点击效果。
|
||||
* Multiple assets will cycle through for varied click effects.
|
||||
*/
|
||||
@Serialize()
|
||||
@Property({
|
||||
type: 'array',
|
||||
label: 'Particle Assets',
|
||||
itemType: { type: 'asset', extensions: ['.particle', '.particle.json'] },
|
||||
reorderable: true
|
||||
})
|
||||
public particleAssets: string[] = [];
|
||||
|
||||
/**
|
||||
* 触发模式
|
||||
* Trigger mode
|
||||
*/
|
||||
@Serialize()
|
||||
@Property({
|
||||
type: 'enum',
|
||||
label: 'Trigger Mode',
|
||||
options: [
|
||||
{ label: 'Left Click', value: ClickFxTriggerMode.LeftClick },
|
||||
{ label: 'Right Click', value: ClickFxTriggerMode.RightClick },
|
||||
{ label: 'Any Click', value: ClickFxTriggerMode.AnyClick },
|
||||
{ label: 'Touch', value: ClickFxTriggerMode.Touch },
|
||||
{ label: 'All', value: ClickFxTriggerMode.All }
|
||||
]
|
||||
})
|
||||
public triggerMode: ClickFxTriggerMode = ClickFxTriggerMode.All;
|
||||
|
||||
/**
|
||||
* 是否启用
|
||||
* Whether enabled
|
||||
*/
|
||||
@Serialize()
|
||||
@Property({ type: 'boolean', label: 'Enabled' })
|
||||
public fxEnabled: boolean = true;
|
||||
|
||||
/**
|
||||
* 最大同时播放数量
|
||||
* Maximum concurrent effects
|
||||
*
|
||||
* 限制同时播放的粒子效果数量,防止性能问题。
|
||||
* Limits concurrent particle effects to prevent performance issues.
|
||||
*/
|
||||
@Serialize()
|
||||
@Property({ type: 'integer', label: 'Max Concurrent', min: 1, max: 50 })
|
||||
public maxConcurrent: number = 10;
|
||||
|
||||
/**
|
||||
* 粒子效果生命周期(秒)
|
||||
* Particle effect lifetime in seconds
|
||||
*
|
||||
* 效果播放多长时间后自动销毁。
|
||||
* How long before the effect is automatically destroyed.
|
||||
*/
|
||||
@Serialize()
|
||||
@Property({ type: 'number', label: 'Effect Lifetime', min: 0.1, max: 30, step: 0.1 })
|
||||
public effectLifetime: number = 3;
|
||||
|
||||
/**
|
||||
* 位置偏移(相对于点击位置)
|
||||
* Position offset (relative to click position)
|
||||
*/
|
||||
@Serialize()
|
||||
@Property({ type: 'vector2', label: 'Position Offset' })
|
||||
public positionOffset: { x: number; y: number } = { x: 0, y: 0 };
|
||||
|
||||
/**
|
||||
* 缩放
|
||||
* Scale
|
||||
*/
|
||||
@Serialize()
|
||||
@Property({ type: 'number', label: 'Scale', min: 0.1, max: 10, step: 0.1 })
|
||||
public scale: number = 1;
|
||||
|
||||
// ============= 运行时状态(不序列化)| Runtime state (not serialized) =============
|
||||
|
||||
/** 当前粒子索引 | Current particle index */
|
||||
private _currentIndex: number = 0;
|
||||
|
||||
/** 活跃的特效实体 ID 列表 | Active effect entity IDs */
|
||||
private _activeEffects: { entityId: number; startTime: number }[] = [];
|
||||
|
||||
/**
|
||||
* 获取下一个要播放的粒子资产 GUID
|
||||
* Get next particle asset GUID to play
|
||||
*/
|
||||
public getNextParticleAsset(): string | null {
|
||||
if (this.particleAssets.length === 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const guid = this.particleAssets[this._currentIndex];
|
||||
this._currentIndex = (this._currentIndex + 1) % this.particleAssets.length;
|
||||
return guid;
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加活跃特效
|
||||
* Add active effect
|
||||
*/
|
||||
public addActiveEffect(entityId: number): void {
|
||||
this._activeEffects.push({ entityId, startTime: Date.now() });
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取活跃特效列表
|
||||
* Get active effects list
|
||||
*/
|
||||
public getActiveEffects(): ReadonlyArray<{ entityId: number; startTime: number }> {
|
||||
return this._activeEffects;
|
||||
}
|
||||
|
||||
/**
|
||||
* 移除活跃特效
|
||||
* Remove active effect
|
||||
*/
|
||||
public removeActiveEffect(entityId: number): void {
|
||||
const index = this._activeEffects.findIndex(e => e.entityId === entityId);
|
||||
if (index !== -1) {
|
||||
this._activeEffects.splice(index, 1);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 清除所有活跃特效记录
|
||||
* Clear all active effect records
|
||||
*/
|
||||
public clearActiveEffects(): void {
|
||||
this._activeEffects = [];
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取活跃特效数量
|
||||
* Get active effect count
|
||||
*/
|
||||
public get activeEffectCount(): number {
|
||||
return this._activeEffects.length;
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否可以添加新特效
|
||||
* Whether can add new effect
|
||||
*/
|
||||
public canAddEffect(): boolean {
|
||||
return this._activeEffects.length < this.maxConcurrent;
|
||||
}
|
||||
|
||||
/**
|
||||
* 重置状态
|
||||
* Reset state
|
||||
*/
|
||||
public reset(): void {
|
||||
this._currentIndex = 0;
|
||||
this._activeEffects = [];
|
||||
}
|
||||
|
||||
override onRemovedFromEntity(): void {
|
||||
this.reset();
|
||||
}
|
||||
}
|
||||
@@ -1,16 +1,17 @@
|
||||
import type { ComponentRegistry as ComponentRegistryType, IScene } from '@esengine/ecs-framework';
|
||||
import type { IRuntimeModule, IPlugin, ModuleManifest, SystemContext } from '@esengine/engine-core';
|
||||
import { TransformTypeToken } from '@esengine/engine-core';
|
||||
import type { IRuntimeModule, IRuntimePlugin, ModuleManifest, SystemContext } from '@esengine/engine-core';
|
||||
import { TransformTypeToken, CanvasElementToken } from '@esengine/engine-core';
|
||||
import { AssetManagerToken } from '@esengine/asset-system';
|
||||
import { RenderSystemToken, EngineBridgeToken, EngineIntegrationToken } from '@esengine/ecs-engine-bindgen';
|
||||
import { Physics2DQueryToken } from '@esengine/physics-rapier2d';
|
||||
import { assetManager as globalAssetManager } from '@esengine/asset-system';
|
||||
import { ParticleSystemComponent } from './ParticleSystemComponent';
|
||||
import { ClickFxComponent } from './ClickFxComponent';
|
||||
import { ParticleUpdateSystem } from './systems/ParticleSystem';
|
||||
import { ClickFxSystem } from './systems/ClickFxSystem';
|
||||
import { ParticleLoader, ParticleAssetType } from './loaders/ParticleLoader';
|
||||
import { ParticleUpdateSystemToken } from './tokens';
|
||||
|
||||
export type { SystemContext, ModuleManifest, IRuntimeModule, IPlugin };
|
||||
export type { SystemContext, ModuleManifest, IRuntimeModule, IRuntimePlugin };
|
||||
|
||||
// 重新导出 tokens | Re-export tokens
|
||||
export { ParticleUpdateSystemToken } from './tokens';
|
||||
@@ -21,6 +22,7 @@ class ParticleRuntimeModule implements IRuntimeModule {
|
||||
|
||||
registerComponents(registry: typeof ComponentRegistryType): void {
|
||||
registry.register(ParticleSystemComponent);
|
||||
registry.register(ClickFxComponent);
|
||||
}
|
||||
|
||||
createSystems(scene: IScene, context: SystemContext): void {
|
||||
@@ -32,26 +34,22 @@ class ParticleRuntimeModule implements IRuntimeModule {
|
||||
const physics2DQuery = context.services.get(Physics2DQueryToken);
|
||||
const renderSystem = context.services.get(RenderSystemToken);
|
||||
|
||||
// 注册粒子资产加载器到上下文的 assetManager 和全局单例
|
||||
// Register particle asset loader to context assetManager AND global singleton
|
||||
if (!this._loaderRegistered) {
|
||||
// 注册粒子资产加载器到上下文的 assetManager
|
||||
// Register particle asset loader to context assetManager
|
||||
if (!this._loaderRegistered && assetManager) {
|
||||
const loader = new ParticleLoader();
|
||||
|
||||
// Register to context's assetManager (used by GameRuntime)
|
||||
if (assetManager) {
|
||||
assetManager.registerLoader(ParticleAssetType, loader);
|
||||
}
|
||||
|
||||
// Also register to global singleton (used by ParticleSystemComponent.loadAsset)
|
||||
// 同时注册到全局单例(ParticleSystemComponent.loadAsset 使用的是全局单例)
|
||||
globalAssetManager.registerLoader(ParticleAssetType, loader);
|
||||
|
||||
assetManager.registerLoader(ParticleAssetType, loader);
|
||||
this._loaderRegistered = true;
|
||||
console.log('[ParticleRuntimeModule] Registered ParticleLoader to both context and global assetManager');
|
||||
console.log('[ParticleRuntimeModule] Registered ParticleLoader to context assetManager');
|
||||
}
|
||||
|
||||
this._updateSystem = new ParticleUpdateSystem();
|
||||
|
||||
// 设置资产管理器 | Set asset manager
|
||||
if (assetManager) {
|
||||
this._updateSystem.setAssetManager(assetManager);
|
||||
}
|
||||
|
||||
// 设置 Transform 组件类型 | Set Transform component type
|
||||
if (transformType) {
|
||||
this._updateSystem.setTransformType(transformType);
|
||||
@@ -74,6 +72,29 @@ class ParticleRuntimeModule implements IRuntimeModule {
|
||||
|
||||
scene.addSystem(this._updateSystem);
|
||||
|
||||
// 添加点击特效系统 | Add click FX system
|
||||
const clickFxSystem = new ClickFxSystem();
|
||||
|
||||
// 设置资产管理器 | Set asset manager
|
||||
if (assetManager) {
|
||||
clickFxSystem.setAssetManager(assetManager);
|
||||
}
|
||||
|
||||
// 设置 EngineBridge(用于屏幕坐标转世界坐标)
|
||||
// Set EngineBridge (for screen to world coordinate conversion)
|
||||
if (engineBridge) {
|
||||
clickFxSystem.setEngineBridge(engineBridge);
|
||||
}
|
||||
|
||||
// 从服务注册表获取 Canvas 元素(用于计算相对坐标)
|
||||
// Get canvas element from service registry (for calculating relative coordinates)
|
||||
const canvas = context.services.get(CanvasElementToken);
|
||||
if (canvas) {
|
||||
clickFxSystem.setCanvas(canvas);
|
||||
}
|
||||
|
||||
scene.addSystem(clickFxSystem);
|
||||
|
||||
// 注册粒子更新系统到服务注册表 | Register particle update system to service registry
|
||||
context.services.register(ParticleUpdateSystemToken, this._updateSystem);
|
||||
|
||||
@@ -106,12 +127,12 @@ const manifest: ModuleManifest = {
|
||||
isEngineModule: true,
|
||||
canContainContent: true,
|
||||
dependencies: ['core', 'math', 'sprite'],
|
||||
exports: { components: ['ParticleSystemComponent'] },
|
||||
exports: { components: ['ParticleSystemComponent', 'ClickFxComponent'] },
|
||||
editorPackage: '@esengine/particle-editor',
|
||||
requiresWasm: false
|
||||
};
|
||||
|
||||
export const ParticlePlugin: IPlugin = {
|
||||
export const ParticlePlugin: IRuntimePlugin = {
|
||||
manifest,
|
||||
runtimeModule: new ParticleRuntimeModule()
|
||||
};
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,10 +12,12 @@ export {
|
||||
} from './ParticleEmitter';
|
||||
|
||||
// Component
|
||||
export { ParticleSystemComponent, ParticleBlendMode, SimulationSpace, type BurstConfig } from './ParticleSystemComponent';
|
||||
export { ParticleSystemComponent, ParticleBlendMode, SimulationSpace, RenderSpace, type BurstConfig } from './ParticleSystemComponent';
|
||||
export { ClickFxComponent, ClickFxTriggerMode } from './ClickFxComponent';
|
||||
|
||||
// System
|
||||
export { ParticleUpdateSystem } from './systems/ParticleSystem';
|
||||
export { ClickFxSystem } from './systems/ClickFxSystem';
|
||||
|
||||
// Modules
|
||||
export {
|
||||
@@ -52,8 +54,7 @@ export {
|
||||
// Rendering
|
||||
export {
|
||||
ParticleRenderDataProvider,
|
||||
type ParticleProviderRenderData,
|
||||
type IRenderDataProvider
|
||||
type ParticleProviderRenderData
|
||||
} from './rendering';
|
||||
|
||||
// Presets
|
||||
|
||||
@@ -9,6 +9,7 @@ import type {
|
||||
IAssetParseContext,
|
||||
AssetContentType
|
||||
} from '@esengine/asset-system';
|
||||
import { SortingLayers } from '@esengine/engine-core';
|
||||
import { EmissionShape, type ColorValue } from '../ParticleEmitter';
|
||||
import { ParticleBlendMode } from '../ParticleSystemComponent';
|
||||
|
||||
@@ -121,12 +122,18 @@ export interface IParticleAsset {
|
||||
particleSize: number;
|
||||
/** 混合模式 | Blend mode */
|
||||
blendMode: ParticleBlendMode;
|
||||
/** 排序顺序 | Sorting order */
|
||||
sortingOrder: number;
|
||||
/**
|
||||
* 排序层名称
|
||||
* Sorting layer name
|
||||
*/
|
||||
sortingLayer: string;
|
||||
/**
|
||||
* 层内排序顺序
|
||||
* Order within the sorting layer
|
||||
*/
|
||||
orderInLayer: number;
|
||||
/** 纹理资产 GUID | Texture asset GUID */
|
||||
textureGuid?: string;
|
||||
/** 纹理路径(编辑器兼容)| Texture path (editor compatibility) */
|
||||
texturePath?: string;
|
||||
|
||||
// 模块配置 | Module configurations
|
||||
/** 模块列表 | Module list */
|
||||
@@ -186,7 +193,8 @@ export function createDefaultParticleAsset(name: string = 'New Particle'): IPart
|
||||
|
||||
particleSize: 8,
|
||||
blendMode: ParticleBlendMode.Normal,
|
||||
sortingOrder: 0,
|
||||
sortingLayer: SortingLayers.Default,
|
||||
orderInLayer: 0,
|
||||
|
||||
modules: [],
|
||||
};
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import type { ParticleSystemComponent } from '../ParticleSystemComponent';
|
||||
import { type ParticleSystemComponent, RenderSpace } from '../ParticleSystemComponent';
|
||||
import { Color } from '@esengine/ecs-framework-math';
|
||||
import { sortingLayerManager, SortingLayers } from '@esengine/engine-core';
|
||||
|
||||
/**
|
||||
* 粒子渲染数据(与 EngineRenderSystem 兼容)
|
||||
@@ -14,8 +15,23 @@ export interface ParticleProviderRenderData {
|
||||
uvs: Float32Array;
|
||||
colors: Uint32Array;
|
||||
tileCount: number;
|
||||
sortingOrder: number;
|
||||
texturePath?: string;
|
||||
/**
|
||||
* 排序层名称
|
||||
* Sorting layer name
|
||||
*/
|
||||
sortingLayer: string;
|
||||
/**
|
||||
* 层内排序顺序
|
||||
* Order within the sorting layer
|
||||
*/
|
||||
orderInLayer: number;
|
||||
/** 纹理 GUID | Texture GUID */
|
||||
textureGuid?: string;
|
||||
/**
|
||||
* 是否在屏幕空间渲染
|
||||
* Whether to render in screen space
|
||||
*/
|
||||
bScreenSpace?: boolean;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -118,10 +134,17 @@ export class ParticleRenderDataProvider implements IRenderDataProvider {
|
||||
this._colors = new Uint32Array(this._maxParticles);
|
||||
}
|
||||
|
||||
// 按 sortingOrder 分组 | Group by sortingOrder
|
||||
const groups = new Map<number, {
|
||||
// 按 sortKey + renderSpace 分组
|
||||
// Group by sortKey + renderSpace
|
||||
// 使用 string key 来区分不同渲染空间的相同 sortKey
|
||||
// Use string key to distinguish same sortKey with different render spaces
|
||||
const groups = new Map<string, {
|
||||
component: ParticleSystemComponent;
|
||||
transform: ITransformLike;
|
||||
sortingLayer: string;
|
||||
orderInLayer: number;
|
||||
bScreenSpace: boolean;
|
||||
sortKey: number;
|
||||
}[]>();
|
||||
|
||||
for (const [component, transform] of this._particleSystems) {
|
||||
@@ -129,25 +152,34 @@ export class ParticleRenderDataProvider implements IRenderDataProvider {
|
||||
continue;
|
||||
}
|
||||
|
||||
const order = component.sortingOrder;
|
||||
if (!groups.has(order)) {
|
||||
groups.set(order, []);
|
||||
const sortingLayer = component.sortingLayer ?? SortingLayers.Default;
|
||||
const orderInLayer = component.orderInLayer ?? 0;
|
||||
const sortKey = sortingLayerManager.getSortKey(sortingLayer, orderInLayer);
|
||||
const bScreenSpace = component.renderSpace === RenderSpace.Screen;
|
||||
const groupKey = `${sortKey}:${bScreenSpace ? 'screen' : 'world'}`;
|
||||
|
||||
if (!groups.has(groupKey)) {
|
||||
groups.set(groupKey, []);
|
||||
}
|
||||
groups.get(order)!.push({ component, transform });
|
||||
groups.get(groupKey)!.push({ component, transform, sortingLayer, orderInLayer, bScreenSpace, sortKey });
|
||||
}
|
||||
|
||||
// 为每个 sortingOrder 组生成渲染数据 | Generate render data for each sortingOrder group
|
||||
for (const [sortingOrder, systems] of groups) {
|
||||
// 按 sortKey 排序后生成渲染数据
|
||||
// Generate render data sorted by sortKey
|
||||
// 字符串 key 格式: "sortKey:space",按 sortKey 数值排序
|
||||
const sortedKeys = [...groups.keys()].sort((a, b) => {
|
||||
const aKey = parseInt(a.split(':')[0], 10);
|
||||
const bKey = parseInt(b.split(':')[0], 10);
|
||||
return aKey - bKey;
|
||||
});
|
||||
|
||||
for (const groupKey of sortedKeys) {
|
||||
const systems = groups.get(groupKey)!;
|
||||
let particleIndex = 0;
|
||||
|
||||
for (const { component } of systems) {
|
||||
const pool = component.pool!;
|
||||
const size = component.particleSize;
|
||||
const textureId = component.textureId;
|
||||
|
||||
// 世界偏移 | World offset (particles are already in world space after emission)
|
||||
// 不需要额外偏移,因为粒子发射时已经使用了世界坐标
|
||||
// No additional offset needed since particles use world coords at emission
|
||||
|
||||
pool.forEachActive((p) => {
|
||||
const tOffset = particleIndex * 7;
|
||||
@@ -162,8 +194,11 @@ export class ParticleRenderDataProvider implements IRenderDataProvider {
|
||||
this._transforms[tOffset + 5] = 0.5; // originX
|
||||
this._transforms[tOffset + 6] = 0.5; // originY
|
||||
|
||||
// Texture ID
|
||||
this._textureIds[particleIndex] = textureId;
|
||||
// Texture ID: 设置为 0,让 EngineRenderSystem 通过 textureGuid 解析
|
||||
// Set to 0, let EngineRenderSystem resolve via textureGuid
|
||||
// 这样可以避免场景恢复后 textureId 过期导致的纹理混乱问题
|
||||
// This avoids texture confusion when textureId becomes stale after scene restore
|
||||
this._textureIds[particleIndex] = 0;
|
||||
|
||||
// UV (full texture)
|
||||
this._uvs[uvOffset] = 0;
|
||||
@@ -184,10 +219,11 @@ export class ParticleRenderDataProvider implements IRenderDataProvider {
|
||||
}
|
||||
|
||||
if (particleIndex > 0) {
|
||||
// 获取纹理路径(支持多种来源)| Get texture path (support multiple sources)
|
||||
const firstComponent = systems[0]?.component;
|
||||
const asset = firstComponent?.loadedAsset as { textureGuid?: string; texturePath?: string } | null;
|
||||
const texPath = asset?.textureGuid || asset?.texturePath || firstComponent?.textureGuid || undefined;
|
||||
// 获取纹理 GUID | Get texture GUID
|
||||
const firstSystem = systems[0];
|
||||
const firstComponent = firstSystem?.component;
|
||||
const asset = firstComponent?.loadedAsset as { textureGuid?: string } | null;
|
||||
const textureGuid = asset?.textureGuid || firstComponent?.textureGuid || undefined;
|
||||
|
||||
// 创建当前组的渲染数据 | Create render data for current group
|
||||
const renderData: ParticleProviderRenderData = {
|
||||
@@ -196,8 +232,10 @@ export class ParticleRenderDataProvider implements IRenderDataProvider {
|
||||
uvs: this._uvs.subarray(0, particleIndex * 4),
|
||||
colors: this._colors.subarray(0, particleIndex),
|
||||
tileCount: particleIndex,
|
||||
sortingOrder,
|
||||
texturePath: texPath
|
||||
sortingLayer: firstSystem?.sortingLayer ?? SortingLayers.Default,
|
||||
orderInLayer: firstSystem?.orderInLayer ?? 0,
|
||||
textureGuid,
|
||||
bScreenSpace: firstSystem?.bScreenSpace ?? false
|
||||
};
|
||||
|
||||
this._renderDataCache.push(renderData);
|
||||
|
||||
443
packages/particle/src/systems/ClickFxSystem.ts
Normal file
443
packages/particle/src/systems/ClickFxSystem.ts
Normal file
@@ -0,0 +1,443 @@
|
||||
/**
|
||||
* 点击特效系统 - 处理点击输入并生成粒子效果
|
||||
* Click FX System - Handles click input and spawns particle effects
|
||||
*
|
||||
* 监听用户点击/触摸事件,在点击位置创建粒子效果实体。
|
||||
* Listens for user click/touch events and creates particle effect entities at click position.
|
||||
*/
|
||||
|
||||
import { EntitySystem, Matcher, Entity, ECSSystem, PluginServiceRegistry, createServiceToken } from '@esengine/ecs-framework';
|
||||
import { Input, MouseButton, TransformComponent, SortingLayers } from '@esengine/engine-core';
|
||||
import type { IAssetManager } from '@esengine/asset-system';
|
||||
import { ClickFxComponent, ClickFxTriggerMode } from '../ClickFxComponent';
|
||||
import { ParticleSystemComponent, RenderSpace } from '../ParticleSystemComponent';
|
||||
import type { IParticleAsset } from '../loaders/ParticleLoader';
|
||||
|
||||
// ============================================================================
|
||||
// 本地服务令牌定义 | Local Service Token Definitions
|
||||
// ============================================================================
|
||||
// 使用 createServiceToken() 本地定义(与 runtime-core 相同策略)
|
||||
// createServiceToken() 使用 Symbol.for(),确保运行时与源模块令牌匹配
|
||||
//
|
||||
// Local token definitions using createServiceToken() (same strategy as runtime-core)
|
||||
// createServiceToken() uses Symbol.for(), ensuring runtime match with source module tokens
|
||||
// ============================================================================
|
||||
|
||||
/**
|
||||
* EngineBridge 接口(最小定义,用于坐标转换)
|
||||
* EngineBridge interface (minimal definition for coordinate conversion)
|
||||
*/
|
||||
interface IEngineBridge {
|
||||
screenToWorld(screenX: number, screenY: number): { x: number; y: number };
|
||||
}
|
||||
|
||||
/**
|
||||
* EngineRenderSystem 接口(最小定义,用于获取 UI Canvas 尺寸)
|
||||
* EngineRenderSystem interface (minimal definition for getting UI canvas size)
|
||||
*/
|
||||
interface IEngineRenderSystem {
|
||||
getUICanvasSize(): { width: number; height: number };
|
||||
}
|
||||
|
||||
// EngineBridge 令牌(与 engine-core 中的一致)
|
||||
// EngineBridge token (consistent with engine-core)
|
||||
const EngineBridgeToken = createServiceToken<IEngineBridge>('engineBridge');
|
||||
|
||||
// RenderSystem 令牌(与 ecs-engine-bindgen 中的一致)
|
||||
// RenderSystem token (consistent with ecs-engine-bindgen)
|
||||
const RenderSystemToken = createServiceToken<IEngineRenderSystem>('renderSystem');
|
||||
|
||||
/**
|
||||
* 点击特效系统
|
||||
* Click FX System
|
||||
*
|
||||
* @example
|
||||
* ```typescript
|
||||
* // 在场景中添加系统
|
||||
* scene.addSystem(new ClickFxSystem());
|
||||
*
|
||||
* // 创建带有 ClickFxComponent 的实体
|
||||
* const clickFxEntity = scene.createEntity('ClickFx');
|
||||
* const clickFx = clickFxEntity.addComponent(new ClickFxComponent());
|
||||
* clickFx.particleAssets = ['particle-guid-1', 'particle-guid-2'];
|
||||
* ```
|
||||
*/
|
||||
@ECSSystem('ClickFx', { updateOrder: 100 })
|
||||
export class ClickFxSystem extends EntitySystem {
|
||||
private _engineBridge: IEngineBridge | null = null;
|
||||
private _renderSystem: IEngineRenderSystem | null = null;
|
||||
private _assetManager: IAssetManager | null = null;
|
||||
private _entitiesToDestroy: Entity[] = [];
|
||||
private _canvas: HTMLCanvasElement | null = null;
|
||||
|
||||
constructor() {
|
||||
super(Matcher.empty().all(ClickFxComponent));
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置资产管理器
|
||||
* Set asset manager
|
||||
*/
|
||||
setAssetManager(assetManager: IAssetManager | null): void {
|
||||
this._assetManager = assetManager;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置服务注册表(用于获取 EngineBridge 和 RenderSystem)
|
||||
* Set service registry (for getting EngineBridge and RenderSystem)
|
||||
*/
|
||||
setServiceRegistry(services: PluginServiceRegistry): void {
|
||||
this._engineBridge = services.get(EngineBridgeToken) ?? null;
|
||||
this._renderSystem = services.get(RenderSystemToken) ?? null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置 EngineBridge(直接注入)
|
||||
* Set EngineBridge (direct injection)
|
||||
*/
|
||||
setEngineBridge(bridge: IEngineBridge): void {
|
||||
this._engineBridge = bridge;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置 RenderSystem(直接注入)
|
||||
* Set RenderSystem (direct injection)
|
||||
*/
|
||||
setRenderSystem(renderSystem: IEngineRenderSystem): void {
|
||||
this._renderSystem = renderSystem;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置 Canvas 元素(用于计算相对坐标)
|
||||
* Set canvas element (for calculating relative coordinates)
|
||||
*/
|
||||
setCanvas(canvas: HTMLCanvasElement): void {
|
||||
this._canvas = canvas;
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查是否应该处理
|
||||
* Check if should process
|
||||
*
|
||||
* 只在运行时模式(非编辑器模式)下处理点击事件
|
||||
* Only process click events in runtime mode (not editor mode)
|
||||
*/
|
||||
protected override onCheckProcessing(): boolean {
|
||||
// 编辑器模式下不处理(预览时也不处理,只有 Play 模式才处理)
|
||||
// Don't process in editor mode (including preview, only in Play mode)
|
||||
if (this.scene?.isEditorMode) {
|
||||
return false;
|
||||
}
|
||||
return super.onCheckProcessing();
|
||||
}
|
||||
|
||||
protected override process(entities: readonly Entity[]): void {
|
||||
// 处理延迟销毁 | Process delayed destruction
|
||||
if (this._entitiesToDestroy.length > 0 && this.scene) {
|
||||
this.scene.destroyEntities(this._entitiesToDestroy);
|
||||
this._entitiesToDestroy = [];
|
||||
}
|
||||
|
||||
for (const entity of entities) {
|
||||
const clickFx = entity.getComponent(ClickFxComponent);
|
||||
if (!clickFx || !clickFx.fxEnabled) continue;
|
||||
|
||||
// 清理过期的特效 | Clean up expired effects
|
||||
this._cleanupExpiredEffects(clickFx);
|
||||
|
||||
// 检查触发条件 | Check trigger conditions
|
||||
const triggered = this._checkTrigger(clickFx);
|
||||
if (!triggered) continue;
|
||||
|
||||
// 检查是否可以添加新特效 | Check if can add new effect
|
||||
if (!clickFx.canAddEffect()) continue;
|
||||
|
||||
// 获取点击/触摸位置 | Get click/touch position
|
||||
const screenPos = this._getInputPosition(clickFx);
|
||||
if (!screenPos) continue;
|
||||
|
||||
// 转换为 canvas 相对坐标 | Convert to canvas-relative coordinates
|
||||
const canvasPos = this._windowToCanvas(screenPos.x, screenPos.y);
|
||||
|
||||
// 应用偏移 | Apply offset
|
||||
canvasPos.x += clickFx.positionOffset.x;
|
||||
canvasPos.y += clickFx.positionOffset.y;
|
||||
|
||||
// 创建粒子效果(使用屏幕空间坐标)
|
||||
// Create particle effect (using screen space coordinates)
|
||||
this._spawnEffect(clickFx, canvasPos.x, canvasPos.y);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 窗口坐标转 canvas 相对坐标
|
||||
* Window to canvas-relative coordinate conversion
|
||||
*
|
||||
* 将窗口坐标转换为 UI Canvas 的像素坐标。
|
||||
* Converts window coordinates to UI canvas pixel coordinates.
|
||||
*/
|
||||
private _windowToCanvas(windowX: number, windowY: number): { x: number; y: number } {
|
||||
// 获取 UI Canvas 尺寸 | Get UI canvas size
|
||||
const canvasSize = this._renderSystem?.getUICanvasSize();
|
||||
const uiCanvasWidth = canvasSize?.width ?? 1920;
|
||||
const uiCanvasHeight = canvasSize?.height ?? 1080;
|
||||
|
||||
let canvasX = windowX;
|
||||
let canvasY = windowY;
|
||||
|
||||
if (this._canvas) {
|
||||
const rect = this._canvas.getBoundingClientRect();
|
||||
// 计算 CSS 坐标 | Calculate CSS coordinates
|
||||
canvasX = windowX - rect.left;
|
||||
canvasY = windowY - rect.top;
|
||||
|
||||
// 将 CSS 坐标映射到 UI Canvas 坐标
|
||||
// Map CSS coordinates to UI canvas coordinates
|
||||
// UI Canvas 保持宽高比,可能会有 letterbox/pillarbox
|
||||
// UI Canvas maintains aspect ratio, may have letterbox/pillarbox
|
||||
const cssWidth = rect.width;
|
||||
const cssHeight = rect.height;
|
||||
|
||||
// 计算 UI Canvas 在 CSS 坐标中的实际显示区域
|
||||
// Calculate actual display area of UI Canvas in CSS coordinates
|
||||
const uiAspect = uiCanvasWidth / uiCanvasHeight;
|
||||
const cssAspect = cssWidth / cssHeight;
|
||||
|
||||
let displayWidth: number;
|
||||
let displayHeight: number;
|
||||
let offsetX = 0;
|
||||
let offsetY = 0;
|
||||
|
||||
if (cssAspect > uiAspect) {
|
||||
// CSS 更宽,pillarbox(左右黑边)
|
||||
// CSS is wider, pillarbox (black bars on sides)
|
||||
displayHeight = cssHeight;
|
||||
displayWidth = cssHeight * uiAspect;
|
||||
offsetX = (cssWidth - displayWidth) / 2;
|
||||
} else {
|
||||
// CSS 更高,letterbox(上下黑边)
|
||||
// CSS is taller, letterbox (black bars on top/bottom)
|
||||
displayWidth = cssWidth;
|
||||
displayHeight = cssWidth / uiAspect;
|
||||
offsetY = (cssHeight - displayHeight) / 2;
|
||||
}
|
||||
|
||||
// 转换为 UI Canvas 坐标
|
||||
// Convert to UI canvas coordinates
|
||||
canvasX = ((canvasX - offsetX) / displayWidth) * uiCanvasWidth;
|
||||
canvasY = ((canvasY - offsetY) / displayHeight) * uiCanvasHeight;
|
||||
}
|
||||
|
||||
return { x: canvasX, y: canvasY };
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查触发条件
|
||||
* Check trigger conditions
|
||||
*/
|
||||
private _checkTrigger(clickFx: ClickFxComponent): boolean {
|
||||
const mode = clickFx.triggerMode;
|
||||
|
||||
switch (mode) {
|
||||
case ClickFxTriggerMode.LeftClick:
|
||||
return Input.isMouseButtonJustPressed(MouseButton.Left);
|
||||
|
||||
case ClickFxTriggerMode.RightClick:
|
||||
return Input.isMouseButtonJustPressed(MouseButton.Right);
|
||||
|
||||
case ClickFxTriggerMode.AnyClick:
|
||||
return Input.isMouseButtonJustPressed(MouseButton.Left) ||
|
||||
Input.isMouseButtonJustPressed(MouseButton.Middle) ||
|
||||
Input.isMouseButtonJustPressed(MouseButton.Right);
|
||||
|
||||
case ClickFxTriggerMode.Touch:
|
||||
return this._checkTouchStart();
|
||||
|
||||
case ClickFxTriggerMode.All:
|
||||
return Input.isMouseButtonJustPressed(MouseButton.Left) ||
|
||||
Input.isMouseButtonJustPressed(MouseButton.Middle) ||
|
||||
Input.isMouseButtonJustPressed(MouseButton.Right) ||
|
||||
this._checkTouchStart();
|
||||
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查是否有新的触摸开始
|
||||
* Check if there's a new touch start
|
||||
*/
|
||||
private _checkTouchStart(): boolean {
|
||||
for (const [id] of Input.touches) {
|
||||
if (Input.isTouchJustStarted(id)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取输入位置
|
||||
* Get input position
|
||||
*/
|
||||
private _getInputPosition(clickFx: ClickFxComponent): { x: number; y: number } | null {
|
||||
const mode = clickFx.triggerMode;
|
||||
|
||||
// 优先检查触摸 | Check touch first
|
||||
if (mode === ClickFxTriggerMode.Touch || mode === ClickFxTriggerMode.All) {
|
||||
for (const [id, touch] of Input.touches) {
|
||||
if (Input.isTouchJustStarted(id)) {
|
||||
return { x: touch.x, y: touch.y };
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 检查鼠标 | Check mouse
|
||||
if (mode !== ClickFxTriggerMode.Touch) {
|
||||
return { x: Input.mousePosition.x, y: Input.mousePosition.y };
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成粒子效果
|
||||
* Spawn particle effect
|
||||
*
|
||||
* 点击特效使用屏幕空间渲染,坐标相对于 UI Canvas 中心。
|
||||
* Click effects use screen space rendering, coordinates relative to UI canvas center.
|
||||
*/
|
||||
private _spawnEffect(clickFx: ClickFxComponent, screenX: number, screenY: number): void {
|
||||
const particleGuid = clickFx.getNextParticleAsset();
|
||||
if (!particleGuid) {
|
||||
console.warn('[ClickFxSystem] No particle assets configured');
|
||||
return;
|
||||
}
|
||||
|
||||
if (!this.scene) {
|
||||
console.warn('[ClickFxSystem] No scene available');
|
||||
return;
|
||||
}
|
||||
|
||||
// 获取 UI Canvas 尺寸 | Get UI canvas size
|
||||
const canvasSize = this._renderSystem?.getUICanvasSize();
|
||||
const canvasWidth = canvasSize?.width ?? 1920;
|
||||
const canvasHeight = canvasSize?.height ?? 1080;
|
||||
|
||||
// 将屏幕坐标转换为屏幕空间坐标(相对于 UI Canvas 中心)
|
||||
// Convert screen coords to screen space coords (relative to UI canvas center)
|
||||
// 屏幕空间坐标系:中心为 (0, 0),Y 轴向上
|
||||
// Screen space coordinate system: center at (0, 0), Y-axis up
|
||||
const screenSpaceX = screenX - canvasWidth / 2;
|
||||
const screenSpaceY = canvasHeight / 2 - screenY; // Y 翻转
|
||||
|
||||
// 创建特效实体 | Create effect entity
|
||||
const effectEntity = this.scene.createEntity(`ClickFx_${Date.now()}`);
|
||||
|
||||
// 添加 Transform(使用屏幕空间坐标)| Add Transform (using screen space coords)
|
||||
const transform = effectEntity.addComponent(new TransformComponent(screenSpaceX, screenSpaceY));
|
||||
transform.setScale(clickFx.scale, clickFx.scale, 1);
|
||||
|
||||
// 添加 ParticleSystem | Add ParticleSystem
|
||||
const particleSystem = effectEntity.addComponent(new ParticleSystemComponent());
|
||||
particleSystem.particleAssetGuid = particleGuid;
|
||||
particleSystem.autoPlay = true;
|
||||
// 使用 ScreenOverlay 层和屏幕空间渲染
|
||||
// Use ScreenOverlay layer and screen space rendering
|
||||
particleSystem.sortingLayer = SortingLayers.ScreenOverlay;
|
||||
particleSystem.orderInLayer = 0;
|
||||
particleSystem.renderSpace = RenderSpace.Screen;
|
||||
|
||||
// 记录活跃特效 | Record active effect
|
||||
clickFx.addActiveEffect(effectEntity.id);
|
||||
|
||||
// 异步加载并播放 | Async load and play
|
||||
if (this._assetManager) {
|
||||
this._assetManager.loadAsset<IParticleAsset>(particleGuid).then(result => {
|
||||
if (result?.asset) {
|
||||
particleSystem.setAssetData(result.asset);
|
||||
// 应用资产的排序属性 | Apply sorting properties from asset
|
||||
if (result.asset.sortingLayer) {
|
||||
particleSystem.sortingLayer = result.asset.sortingLayer;
|
||||
}
|
||||
if (result.asset.orderInLayer !== undefined) {
|
||||
particleSystem.orderInLayer = result.asset.orderInLayer;
|
||||
}
|
||||
particleSystem.play();
|
||||
} else {
|
||||
console.warn(`[ClickFxSystem] Failed to load particle asset: ${particleGuid}`);
|
||||
}
|
||||
}).catch(error => {
|
||||
console.error(`[ClickFxSystem] Error loading particle asset ${particleGuid}:`, error);
|
||||
});
|
||||
} else {
|
||||
console.warn('[ClickFxSystem] AssetManager not set, cannot load particle asset');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 清理过期的特效
|
||||
* Clean up expired effects
|
||||
*/
|
||||
private _cleanupExpiredEffects(clickFx: ClickFxComponent): void {
|
||||
if (!this.scene) return;
|
||||
|
||||
const now = Date.now();
|
||||
const lifetimeMs = clickFx.effectLifetime * 1000;
|
||||
const effectsToRemove: number[] = [];
|
||||
|
||||
for (const effect of clickFx.getActiveEffects()) {
|
||||
const age = now - effect.startTime;
|
||||
|
||||
if (age >= lifetimeMs) {
|
||||
// 标记为需要移除 | Mark for removal
|
||||
effectsToRemove.push(effect.entityId);
|
||||
|
||||
// 查找并销毁实体 | Find and destroy entity
|
||||
const entity = this.scene.findEntityById(effect.entityId);
|
||||
if (entity) {
|
||||
// 停止粒子系统 | Stop particle system
|
||||
const particleSystem = entity.getComponent(ParticleSystemComponent);
|
||||
if (particleSystem) {
|
||||
particleSystem.stop(true);
|
||||
}
|
||||
|
||||
// 添加到销毁队列 | Add to destroy queue
|
||||
this._entitiesToDestroy.push(entity);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 从记录中移除 | Remove from records
|
||||
for (const entityId of effectsToRemove) {
|
||||
clickFx.removeActiveEffect(entityId);
|
||||
}
|
||||
}
|
||||
|
||||
protected override onDestroy(): void {
|
||||
// 清理所有特效 | Clean up all effects
|
||||
if (this.scene) {
|
||||
const entities = this.scene.entities.buffer;
|
||||
for (let i = 0; i < entities.length; i++) {
|
||||
const entity = entities[i];
|
||||
const clickFx = entity.getComponent(ClickFxComponent);
|
||||
if (clickFx) {
|
||||
for (const effect of clickFx.getActiveEffects()) {
|
||||
const effectEntity = this.scene.findEntityById(effect.entityId);
|
||||
if (effectEntity) {
|
||||
this._entitiesToDestroy.push(effectEntity);
|
||||
}
|
||||
}
|
||||
clickFx.clearActiveEffects();
|
||||
}
|
||||
}
|
||||
|
||||
// 立即销毁 | Destroy immediately
|
||||
if (this._entitiesToDestroy.length > 0) {
|
||||
this.scene.destroyEntities(this._entitiesToDestroy);
|
||||
this._entitiesToDestroy = [];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,10 @@
|
||||
import { EntitySystem, Matcher, ECSSystem, Time, Entity, type Component, type ComponentType } from '@esengine/ecs-framework';
|
||||
import type { IEngineIntegration, IEngineBridge } from '@esengine/ecs-engine-bindgen';
|
||||
import type { IAssetManager } from '@esengine/asset-system';
|
||||
import { ParticleSystemComponent } from '../ParticleSystemComponent';
|
||||
import { ParticleRenderDataProvider } from '../rendering/ParticleRenderDataProvider';
|
||||
import { Physics2DCollisionModule, type IPhysics2DQuery } from '../modules/Physics2DCollisionModule';
|
||||
import type { IParticleAsset } from '../loaders/ParticleLoader';
|
||||
|
||||
/**
|
||||
* 默认粒子纹理 ID
|
||||
@@ -72,6 +74,7 @@ export class ParticleUpdateSystem extends EntitySystem {
|
||||
private _engineIntegration: IEngineIntegration | null = null;
|
||||
private _engineBridge: IEngineBridge | null = null;
|
||||
private _physics2DQuery: IPhysics2DQuery | null = null;
|
||||
private _assetManager: IAssetManager | null = null;
|
||||
private _defaultTextureLoaded: boolean = false;
|
||||
private _defaultTextureLoading: boolean = false;
|
||||
/** 追踪每个粒子组件上次加载的资产 GUID | Track last loaded asset GUID for each particle component */
|
||||
@@ -125,6 +128,16 @@ export class ParticleUpdateSystem extends EntitySystem {
|
||||
this._physics2DQuery = query;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置资产管理器
|
||||
* Set asset manager
|
||||
*
|
||||
* @param assetManager - 资产管理器实例 | Asset manager instance
|
||||
*/
|
||||
setAssetManager(assetManager: IAssetManager | null): void {
|
||||
this._assetManager = assetManager;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取渲染数据提供者
|
||||
* Get render data provider
|
||||
@@ -219,6 +232,31 @@ export class ParticleUpdateSystem extends EntitySystem {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 加载粒子资产
|
||||
* Load particle asset
|
||||
*
|
||||
* 使用注入的 assetManager 加载资产,避免使用全局单例。
|
||||
* Uses injected assetManager to load assets, avoiding global singleton.
|
||||
*
|
||||
* @param guid 资产 GUID | Asset GUID
|
||||
* @param bForceReload 是否强制重新加载 | Whether to force reload
|
||||
* @returns 加载的资产数据或 null | Loaded asset data or null
|
||||
*/
|
||||
private async _loadParticleAsset(guid: string, bForceReload: boolean = false): Promise<IParticleAsset | null> {
|
||||
if (!guid || !this._assetManager) {
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
const result = await this._assetManager.loadAsset<IParticleAsset>(guid, { forceReload: bForceReload });
|
||||
return result?.asset ?? null;
|
||||
} catch (error) {
|
||||
console.error(`[ParticleUpdateSystem] Error loading asset ${guid}:`, error);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 异步初始化粒子系统
|
||||
* Async initialize particle system
|
||||
@@ -226,7 +264,17 @@ export class ParticleUpdateSystem extends EntitySystem {
|
||||
private async _initializeParticle(entity: Entity, particle: ParticleSystemComponent): Promise<void> {
|
||||
// 如果有资产 GUID,先加载资产 | Load asset first if GUID is set
|
||||
if (particle.particleAssetGuid) {
|
||||
await particle.loadAsset(particle.particleAssetGuid);
|
||||
const asset = await this._loadParticleAsset(particle.particleAssetGuid);
|
||||
if (asset) {
|
||||
particle.setAssetData(asset);
|
||||
// 应用资产的排序属性 | Apply sorting properties from asset
|
||||
if (asset.sortingLayer) {
|
||||
particle.sortingLayer = asset.sortingLayer;
|
||||
}
|
||||
if (asset.orderInLayer !== undefined) {
|
||||
particle.orderInLayer = asset.orderInLayer;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 初始化粒子系统(不自动播放,由下面的逻辑控制)
|
||||
@@ -301,7 +349,17 @@ export class ParticleUpdateSystem extends EntitySystem {
|
||||
(async () => {
|
||||
try {
|
||||
if (currentGuid) {
|
||||
await particle.loadAsset(currentGuid);
|
||||
const asset = await this._loadParticleAsset(currentGuid);
|
||||
if (asset) {
|
||||
particle.setAssetData(asset);
|
||||
// 应用资产的排序属性 | Apply sorting properties from asset
|
||||
if (asset.sortingLayer) {
|
||||
particle.sortingLayer = asset.sortingLayer;
|
||||
}
|
||||
if (asset.orderInLayer !== undefined) {
|
||||
particle.orderInLayer = asset.orderInLayer;
|
||||
}
|
||||
}
|
||||
// 加载纹理 | Load texture
|
||||
await this.loadParticleTexture(particle);
|
||||
|
||||
@@ -340,24 +398,23 @@ export class ParticleUpdateSystem extends EntitySystem {
|
||||
// 已经加载过就跳过 | Skip if already loaded
|
||||
if (particle.textureId > 0) return;
|
||||
|
||||
// 从已加载的资产获取纹理路径 | Get texture path from loaded asset
|
||||
// 支持 textureGuid 和 texturePath(编辑器可能使用后者)
|
||||
// Support both textureGuid and texturePath (editor may use the latter)
|
||||
// 从已加载的资产获取纹理 GUID | Get texture GUID from loaded asset
|
||||
const asset = particle.loadedAsset;
|
||||
const texturePath = asset?.textureGuid || asset?.texturePath || particle.textureGuid;
|
||||
const textureGuid = asset?.textureGuid || particle.textureGuid;
|
||||
|
||||
if (texturePath) {
|
||||
if (textureGuid) {
|
||||
// 通过 GUID 加载纹理 | Load texture by GUID
|
||||
try {
|
||||
const textureId = await this._engineIntegration.loadTextureForComponent(texturePath);
|
||||
const textureId = await this._engineIntegration.loadTextureByGuid(textureGuid);
|
||||
particle.textureId = textureId;
|
||||
} catch (error) {
|
||||
console.error('[ParticleUpdateSystem] Failed to load texture:', texturePath, error);
|
||||
console.error('[ParticleUpdateSystem] Failed to load texture by GUID:', textureGuid, error);
|
||||
// 加载失败时使用默认纹理 | Use default texture on load failure
|
||||
await this._ensureDefaultTexture();
|
||||
particle.textureId = DEFAULT_PARTICLE_TEXTURE_ID;
|
||||
}
|
||||
} else {
|
||||
// 没有纹理路径时使用默认粒子纹理 | Use default particle texture when no path
|
||||
// 没有纹理 GUID 时使用默认粒子纹理 | Use default particle texture when no GUID
|
||||
await this._ensureDefaultTexture();
|
||||
particle.textureId = DEFAULT_PARTICLE_TEXTURE_ID;
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
* Defines service tokens exported by particle module.
|
||||
*/
|
||||
|
||||
import { createServiceToken } from '@esengine/engine-core';
|
||||
import { createServiceToken } from '@esengine/ecs-framework';
|
||||
import type { ParticleUpdateSystem } from './systems/ParticleSystem';
|
||||
|
||||
// ============================================================================
|
||||
|
||||
Reference in New Issue
Block a user