fix(particle): 修复粒子系统在浏览器预览中的资产加载和渲染 (#290)
* fix(editor): 修复粒子实体创建和优化检视器 - 添加 effects 分类到右键菜单,修复粒子实体无法创建的问题 - 添加粒子效果的本地化标签 - 简化粒子组件检视器,优先显示资产文件选择 - 高级属性只在未选择资产时显示,且默认折叠 - 添加可折叠的属性分组提升用户体验 * fix(particle): 修复粒子系统在浏览器预览中的资产加载和渲染 - 添加粒子 Gizmo 支持,显示发射形状并响应 Transform 缩放/旋转 - 修复资产热重载:添加 reloadAsset() 方法和 assets:refresh 事件监听 - 修复 VectorFieldEditors 数值输入精度(step 改为 0.01) - 修复浏览器预览中粒子资产加载失败的问题: - 将相对路径转换为绝对路径以正确复制资产文件 - 使用原始 GUID 而非生成的 GUID 构建 asset catalog - 初始化全局 assetManager 单例的 catalog 和 loader - 在 GameRuntime 的 systemContext 中添加 engineIntegration - 公开 AssetManager.initializeFromCatalog 方法供运行时使用
This commit is contained in:
@@ -18,7 +18,7 @@ import {
|
||||
BrowserFileSystemService,
|
||||
type IPlugin
|
||||
} from '@esengine/runtime-core';
|
||||
import type { IAssetManager } from '@esengine/asset-system';
|
||||
import { assetManager as globalAssetManager, type IAssetManager, type IAssetCatalog, type IAssetCatalogEntry } from '@esengine/asset-system';
|
||||
import { BrowserAssetReader } from './BrowserAssetReader';
|
||||
|
||||
/**
|
||||
@@ -133,9 +133,50 @@ export class BrowserRuntime {
|
||||
Core.services.registerInstance(IFileSystemServiceKey, this._fileSystem);
|
||||
}
|
||||
|
||||
// Set asset reader for AssetManager
|
||||
if (this._runtime.assetManager && this._assetReader) {
|
||||
this._runtime.assetManager.setReader(this._assetReader);
|
||||
// Set asset reader for AssetManager (both runtime instance and global singleton)
|
||||
// 设置资产读取器(运行时实例和全局单例)
|
||||
if (this._assetReader) {
|
||||
// Initialize the GLOBAL assetManager singleton (used by particle and other modules)
|
||||
// 初始化全局 assetManager 单例(被 particle 等模块使用)
|
||||
globalAssetManager.setReader(this._assetReader);
|
||||
|
||||
// Also set for runtime's assetManager if available
|
||||
if (this._runtime.assetManager) {
|
||||
this._runtime.assetManager.setReader(this._assetReader);
|
||||
}
|
||||
|
||||
// Initialize AssetManager with catalog data from BrowserFileSystemService
|
||||
// 使用 BrowserFileSystemService 的 catalog 数据初始化 AssetManager
|
||||
if (this._fileSystem?.catalog) {
|
||||
const browserCatalog = this._fileSystem.catalog;
|
||||
const assetCatalog: IAssetCatalog = {
|
||||
version: browserCatalog.version,
|
||||
createdAt: browserCatalog.createdAt,
|
||||
entries: new Map<string, IAssetCatalogEntry>(),
|
||||
bundles: new Map()
|
||||
};
|
||||
|
||||
// Convert browser catalog entries to IAssetCatalog format
|
||||
// 将浏览器 catalog 条目转换为 IAssetCatalog 格式
|
||||
for (const [guid, entry] of Object.entries(browserCatalog.entries)) {
|
||||
assetCatalog.entries.set(guid, {
|
||||
guid: entry.guid,
|
||||
path: entry.path,
|
||||
type: entry.type,
|
||||
size: entry.size,
|
||||
hash: entry.hash
|
||||
});
|
||||
}
|
||||
|
||||
// Initialize GLOBAL assetManager singleton (this is what particle module uses)
|
||||
// 初始化全局 assetManager 单例(particle 模块使用的就是这个)
|
||||
globalAssetManager.initializeFromCatalog(assetCatalog);
|
||||
|
||||
// Also initialize runtime's assetManager if available
|
||||
if (this._runtime.assetManager) {
|
||||
this._runtime.assetManager.initializeFromCatalog(assetCatalog);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Disable editor mode (hides grid, gizmos, axis indicator)
|
||||
|
||||
Reference in New Issue
Block a user