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": "runtime-core",
|
||||
"name": "@esengine/runtime-core",
|
||||
"globalKey": "runtimeCore",
|
||||
"displayName": "Runtime Core",
|
||||
"description": "Core runtime framework | 核心运行时框架",
|
||||
"version": "1.0.0",
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
},
|
||||
"dependencies": {
|
||||
"@esengine/ecs-framework": "workspace:*",
|
||||
"@esengine/ecs-framework-math": "workspace:*",
|
||||
"@esengine/ecs-engine-bindgen": "workspace:*",
|
||||
"@esengine/engine-core": "workspace:*",
|
||||
"@esengine/asset-system": "workspace:*",
|
||||
|
||||
@@ -6,11 +6,10 @@
|
||||
* This is the unified entry point for editor preview and standalone runtime
|
||||
*/
|
||||
|
||||
import { Core, Scene, SceneSerializer, HierarchySystem } from '@esengine/ecs-framework';
|
||||
import { Core, Scene, SceneSerializer, HierarchySystem, PluginServiceRegistry, createServiceToken } from '@esengine/ecs-framework';
|
||||
import {
|
||||
EngineBridge,
|
||||
EngineRenderSystem,
|
||||
CameraSystem,
|
||||
EngineBridgeToken,
|
||||
RenderSystemToken,
|
||||
EngineIntegrationToken,
|
||||
@@ -21,15 +20,25 @@ import {
|
||||
TransformSystem,
|
||||
InputSystem,
|
||||
Input,
|
||||
PluginServiceRegistry,
|
||||
TransformTypeToken,
|
||||
createServiceToken
|
||||
CanvasElementToken
|
||||
} from '@esengine/engine-core';
|
||||
import { AssetManager, EngineIntegration, AssetManagerToken } from '@esengine/asset-system';
|
||||
|
||||
// ============================================================================
|
||||
// 本地服务令牌定义 | Local Service Token Definitions
|
||||
// 用于访问各模块注册的服务 | For accessing services registered by modules
|
||||
// ============================================================================
|
||||
// 这些令牌使用 createServiceToken() 本地定义,而不是从源模块导入。
|
||||
// 这是有意为之:
|
||||
// 1. runtime-core 应保持与 ui/sprite/behavior-tree 等模块的松耦合
|
||||
// 2. createServiceToken() 使用 Symbol.for(),确保相同名称在运行时匹配
|
||||
// 3. 本地接口提供类型安全,无需引入模块依赖
|
||||
//
|
||||
// These tokens are defined locally using createServiceToken() instead of
|
||||
// importing from source modules. This is intentional:
|
||||
// 1. runtime-core should remain loosely coupled to ui/sprite/behavior-tree etc.
|
||||
// 2. createServiceToken() uses Symbol.for(), ensuring same names match at runtime
|
||||
// 3. Local interfaces provide type safety without introducing module dependencies
|
||||
// ============================================================================
|
||||
|
||||
/**
|
||||
@@ -88,6 +97,7 @@ const Physics2DSystemToken = createServiceToken<IPhysicsSystem>('physics2DSystem
|
||||
|
||||
// Tilemap 模块服务令牌 | Tilemap module service tokens
|
||||
const TilemapSystemToken = createServiceToken<ITilemapSystem>('tilemapSystem');
|
||||
|
||||
import {
|
||||
runtimePluginManager,
|
||||
type SystemContext,
|
||||
@@ -154,7 +164,6 @@ export class GameRuntime {
|
||||
private _bridge: EngineBridge | null = null;
|
||||
private _scene: Scene | null = null;
|
||||
private _renderSystem: EngineRenderSystem | null = null;
|
||||
private _cameraSystem: CameraSystem | null = null;
|
||||
private _inputSystem: InputSystem | null = null;
|
||||
private _assetManager: AssetManager | null = null;
|
||||
private _engineIntegration: EngineIntegration | null = null;
|
||||
@@ -174,7 +183,8 @@ export class GameRuntime {
|
||||
private _systemContext: SystemContext | null = null;
|
||||
|
||||
// 场景快照(用于编辑器预览后恢复)
|
||||
private _sceneSnapshot: string | null = null;
|
||||
// 支持二进制格式以提升性能
|
||||
private _sceneSnapshot: string | Uint8Array | null = null;
|
||||
|
||||
// Gizmo 注册表注入函数
|
||||
private _gizmoDataProvider?: (component: any, entity: any, isSelected: boolean) => any;
|
||||
@@ -318,8 +328,8 @@ export class GameRuntime {
|
||||
this._inputSystem.setInputSubsystem(inputSubsystem);
|
||||
}
|
||||
|
||||
this._cameraSystem = new CameraSystem(this._bridge);
|
||||
this._scene.addSystem(this._cameraSystem);
|
||||
// CameraSystem 由 CameraPlugin 通过插件系统创建
|
||||
// CameraSystem is created by CameraPlugin via plugin system
|
||||
|
||||
this._renderSystem = new EngineRenderSystem(this._bridge, TransformComponent);
|
||||
|
||||
@@ -352,6 +362,13 @@ export class GameRuntime {
|
||||
services.register(AssetManagerToken, this._assetManager);
|
||||
services.register(TransformTypeToken, TransformComponent);
|
||||
|
||||
// 注册 Canvas 元素(用于坐标转换等)
|
||||
// Register canvas element (for coordinate conversion, etc.)
|
||||
const canvas = this._platform.getCanvas();
|
||||
if (canvas) {
|
||||
services.register(CanvasElementToken, canvas);
|
||||
}
|
||||
|
||||
this._systemContext = {
|
||||
isEditor: this._platform.isEditorMode(),
|
||||
services
|
||||
@@ -516,6 +533,12 @@ export class GameRuntime {
|
||||
this._renderSystem.setPreviewMode(true);
|
||||
}
|
||||
|
||||
// 禁用编辑器模式,启用 InputSystem 和组件生命周期回调
|
||||
// Disable editor mode to enable InputSystem and component lifecycle callbacks
|
||||
if (this._scene) {
|
||||
this._scene.isEditorMode = false;
|
||||
}
|
||||
|
||||
// 调用场景 begin() 触发延迟的组件生命周期回调
|
||||
// Call scene begin() to trigger deferred component lifecycle callbacks
|
||||
if (this._scene) {
|
||||
@@ -577,6 +600,12 @@ export class GameRuntime {
|
||||
this._renderSystem.setPreviewMode(false);
|
||||
}
|
||||
|
||||
// 恢复编辑器模式(如果是编辑器平台)
|
||||
// Restore editor mode (if editor platform)
|
||||
if (this._scene && this._platform.isEditorMode()) {
|
||||
this._scene.isEditorMode = true;
|
||||
}
|
||||
|
||||
// 解绑 UI 输入
|
||||
const services = this._systemContext?.services;
|
||||
const uiInputSystem = services?.get(UIInputSystemToken);
|
||||
@@ -848,19 +877,41 @@ export class GameRuntime {
|
||||
/**
|
||||
* 保存场景快照
|
||||
* Save scene snapshot
|
||||
*
|
||||
* 使用二进制格式提升序列化性能,并支持 EntityRef 的正确序列化。
|
||||
* 在保存前清除纹理缓存,确保恢复时能够从干净状态重新加载纹理。
|
||||
*
|
||||
* Uses binary format for better serialization performance and supports proper
|
||||
* EntityRef serialization. Clears texture cache before saving to ensure
|
||||
* clean reload on restore.
|
||||
*
|
||||
* @param options 可选配置
|
||||
* @param options.useJson 是否使用 JSON 格式(用于调试),默认 false 使用二进制
|
||||
*/
|
||||
saveSceneSnapshot(): boolean {
|
||||
saveSceneSnapshot(options?: { useJson?: boolean }): boolean {
|
||||
if (!this._scene) {
|
||||
console.warn('[GameRuntime] Cannot save snapshot: no scene');
|
||||
return false;
|
||||
}
|
||||
|
||||
try {
|
||||
// 清除所有纹理缓存(确保恢复时重新加载)
|
||||
// Clear all texture caches (ensures reload on restore)
|
||||
// clearTextureMappings() 内部会同时清除 Rust 层和 JS 层的纹理缓存
|
||||
// clearTextureMappings() internally clears both Rust and JS layer texture caches
|
||||
if (this._engineIntegration) {
|
||||
this._engineIntegration.clearTextureMappings();
|
||||
}
|
||||
|
||||
// 使用二进制格式提升性能(默认)或 JSON 用于调试
|
||||
// Use binary format for performance (default) or JSON for debugging
|
||||
const format = options?.useJson ? 'json' : 'binary';
|
||||
|
||||
this._sceneSnapshot = SceneSerializer.serialize(this._scene, {
|
||||
format: 'json',
|
||||
format,
|
||||
pretty: false,
|
||||
includeMetadata: false
|
||||
}) as string;
|
||||
});
|
||||
return true;
|
||||
} catch (error) {
|
||||
console.error('[GameRuntime] Failed to save snapshot:', error);
|
||||
@@ -871,6 +922,14 @@ export class GameRuntime {
|
||||
/**
|
||||
* 恢复场景快照
|
||||
* Restore scene snapshot
|
||||
*
|
||||
* 使用两阶段反序列化确保 EntityRef 引用正确恢复:
|
||||
* 1. 创建所有实体和组件
|
||||
* 2. 解析所有 EntityRef 引用
|
||||
*
|
||||
* Uses two-phase deserialization to ensure EntityRef references are properly restored:
|
||||
* 1. Create all entities and components
|
||||
* 2. Resolve all EntityRef references
|
||||
*/
|
||||
async restoreSceneSnapshot(): Promise<boolean> {
|
||||
if (!this._scene || !this._sceneSnapshot) {
|
||||
@@ -885,7 +944,16 @@ export class GameRuntime {
|
||||
tilemapSystem.clearCache?.();
|
||||
}
|
||||
|
||||
// 反序列化场景
|
||||
// 清除所有纹理并重置状态(修复 Play/Stop 后纹理 ID 混乱的问题)
|
||||
// Clear all textures and reset state (fixes texture ID confusion after Play/Stop)
|
||||
// clearTextureMappings() 内部会同时清除 Rust 层和 JS 层的纹理缓存
|
||||
// clearTextureMappings() internally clears both Rust and JS layer texture caches
|
||||
if (this._engineIntegration) {
|
||||
this._engineIntegration.clearTextureMappings();
|
||||
}
|
||||
|
||||
// 反序列化场景(SceneSerializer 内部使用 SerializationContext 处理 EntityRef)
|
||||
// Deserialize scene (SceneSerializer internally uses SerializationContext for EntityRef)
|
||||
SceneSerializer.deserialize(this._scene, this._sceneSnapshot, {
|
||||
strategy: 'replace',
|
||||
preserveIds: true
|
||||
@@ -907,6 +975,20 @@ export class GameRuntime {
|
||||
return this._sceneSnapshot !== null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取快照大小(用于调试)
|
||||
* Get snapshot size (for debugging)
|
||||
*/
|
||||
getSnapshotSize(): number {
|
||||
if (!this._sceneSnapshot) {
|
||||
return 0;
|
||||
}
|
||||
if (typeof this._sceneSnapshot === 'string') {
|
||||
return this._sceneSnapshot.length;
|
||||
}
|
||||
return this._sceneSnapshot.byteLength;
|
||||
}
|
||||
|
||||
// ===== 多视口 API =====
|
||||
// ===== Multi-viewport API =====
|
||||
|
||||
@@ -963,7 +1045,6 @@ export class GameRuntime {
|
||||
}
|
||||
|
||||
this._renderSystem = null;
|
||||
this._cameraSystem = null;
|
||||
this._inputSystem = null;
|
||||
this._systemContext = null;
|
||||
this._platform.dispose();
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { runtimePluginManager, type IPlugin } from './PluginManager';
|
||||
import { runtimePluginManager, type IRuntimePlugin } from './PluginManager';
|
||||
|
||||
export interface PluginPackageInfo {
|
||||
plugin: boolean;
|
||||
@@ -18,7 +18,7 @@ export interface ProjectPluginConfig {
|
||||
|
||||
interface LoadedPluginInfo {
|
||||
id: string;
|
||||
plugin: IPlugin;
|
||||
plugin: IRuntimePlugin;
|
||||
packageInfo: PluginPackageInfo;
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@ const loadedPlugins = new Map<string, LoadedPluginInfo>();
|
||||
export async function loadPlugin(
|
||||
packageId: string,
|
||||
packageInfo: PluginPackageInfo
|
||||
): Promise<IPlugin | null> {
|
||||
): Promise<IRuntimePlugin | null> {
|
||||
if (loadedPlugins.has(packageId)) {
|
||||
return loadedPlugins.get(packageId)!.plugin;
|
||||
}
|
||||
@@ -40,7 +40,7 @@ export async function loadPlugin(
|
||||
try {
|
||||
const module = await import(/* @vite-ignore */ packageId);
|
||||
const exportName = packageInfo.pluginExport || 'default';
|
||||
const plugin = module[exportName] as IPlugin;
|
||||
const plugin = module[exportName] as IRuntimePlugin;
|
||||
|
||||
if (!plugin || !plugin.manifest) {
|
||||
console.warn(`[PluginLoader] Invalid plugin export from ${packageId}`);
|
||||
@@ -99,14 +99,14 @@ export async function loadEnabledPlugins(
|
||||
/**
|
||||
* 注册预加载的插件(用于已静态导入的插件)
|
||||
*/
|
||||
export function registerStaticPlugin(plugin: IPlugin): void {
|
||||
export function registerStaticPlugin(plugin: IRuntimePlugin): void {
|
||||
runtimePluginManager.register(plugin);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取已加载的插件列表
|
||||
*/
|
||||
export function getLoadedPlugins(): IPlugin[] {
|
||||
export function getLoadedPlugins(): IRuntimePlugin[] {
|
||||
return Array.from(loadedPlugins.values()).map(info => info.plugin);
|
||||
}
|
||||
|
||||
|
||||
@@ -5,16 +5,16 @@
|
||||
|
||||
import { ComponentRegistry, ServiceContainer } from '@esengine/ecs-framework';
|
||||
import type { IScene } from '@esengine/ecs-framework';
|
||||
import type { IPlugin, IRuntimeModule, SystemContext, ModuleManifest } from '@esengine/engine-core';
|
||||
import type { IRuntimePlugin, IRuntimeModule, SystemContext, ModuleManifest } from '@esengine/engine-core';
|
||||
|
||||
export type { IPlugin, IRuntimeModule, SystemContext, ModuleManifest };
|
||||
export type { IRuntimePlugin, IRuntimeModule, SystemContext, ModuleManifest };
|
||||
|
||||
export class RuntimePluginManager {
|
||||
private _plugins = new Map<string, IPlugin>();
|
||||
private _plugins = new Map<string, IRuntimePlugin>();
|
||||
private _enabledPlugins = new Set<string>();
|
||||
private _bInitialized = false;
|
||||
|
||||
register(plugin: IPlugin): void {
|
||||
register(plugin: IRuntimePlugin): void {
|
||||
const id = plugin.manifest.id;
|
||||
if (this._plugins.has(id)) {
|
||||
return;
|
||||
@@ -122,11 +122,11 @@ export class RuntimePluginManager {
|
||||
}
|
||||
}
|
||||
|
||||
getPlugins(): IPlugin[] {
|
||||
getPlugins(): IRuntimePlugin[] {
|
||||
return Array.from(this._plugins.values());
|
||||
}
|
||||
|
||||
getPlugin(id: string): IPlugin | undefined {
|
||||
getPlugin(id: string): IRuntimePlugin | undefined {
|
||||
return this._plugins.get(id);
|
||||
}
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ import { Core } from '@esengine/ecs-framework';
|
||||
import type { IScene } from '@esengine/ecs-framework';
|
||||
import {
|
||||
runtimePluginManager,
|
||||
type IPlugin,
|
||||
type IRuntimePlugin,
|
||||
type IRuntimeModule,
|
||||
type ModuleManifest,
|
||||
type SystemContext
|
||||
@@ -24,14 +24,14 @@ export interface RuntimeConfig {
|
||||
export function createPlugin(
|
||||
manifest: ModuleManifest,
|
||||
runtimeModule: IRuntimeModule
|
||||
): IPlugin {
|
||||
): IRuntimePlugin {
|
||||
return { manifest, runtimeModule };
|
||||
}
|
||||
|
||||
/**
|
||||
* 注册插件到运行时
|
||||
*/
|
||||
export function registerPlugin(plugin: IPlugin): void {
|
||||
export function registerPlugin(plugin: IRuntimePlugin): void {
|
||||
runtimePluginManager.register(plugin);
|
||||
}
|
||||
|
||||
|
||||
@@ -14,19 +14,36 @@ import type {
|
||||
} from '../IPlatformAdapter';
|
||||
import type { IPlatformInputSubsystem } from '@esengine/platform-common';
|
||||
|
||||
/**
|
||||
* 浏览器路径解析模式
|
||||
* Browser path resolve mode
|
||||
*/
|
||||
export type BrowserPathResolveMode = 'proxy' | 'direct';
|
||||
|
||||
/**
|
||||
* 浏览器路径解析器
|
||||
* Browser path resolver
|
||||
*
|
||||
* 支持两种模式:
|
||||
* - 'proxy': 使用 /asset?path=... 格式(编辑器 "Run in Browser" 使用)
|
||||
* - 'direct': 使用直接路径如 /assets/path.png(独立 Web 构建使用)
|
||||
*
|
||||
* Supports two modes:
|
||||
* - 'proxy': Uses /asset?path=... format (for editor "Run in Browser")
|
||||
* - 'direct': Uses direct paths like /assets/path.png (for standalone web builds)
|
||||
*/
|
||||
export class BrowserPathResolver implements IPathResolver {
|
||||
private _baseUrl: string;
|
||||
private _mode: BrowserPathResolveMode;
|
||||
|
||||
constructor(baseUrl: string = '') {
|
||||
constructor(baseUrl: string = '/assets', mode: BrowserPathResolveMode = 'proxy') {
|
||||
this._baseUrl = baseUrl;
|
||||
this._mode = mode;
|
||||
}
|
||||
|
||||
resolve(path: string): string {
|
||||
// 如果已经是完整 URL,直接返回
|
||||
// If already a full URL, return as-is
|
||||
if (path.startsWith('http://') ||
|
||||
path.startsWith('https://') ||
|
||||
path.startsWith('data:') ||
|
||||
@@ -35,28 +52,76 @@ export class BrowserPathResolver implements IPathResolver {
|
||||
return path;
|
||||
}
|
||||
|
||||
// 相对路径,添加资产请求前缀
|
||||
return `/asset?path=${encodeURIComponent(path)}`;
|
||||
if (this._mode === 'proxy') {
|
||||
// Proxy mode: use /asset?path=... format
|
||||
// 代理模式:使用 /asset?path=... 格式
|
||||
return `/asset?path=${encodeURIComponent(path)}`;
|
||||
}
|
||||
|
||||
// Direct mode: use direct URL paths
|
||||
// 直接模式:使用直接 URL 路径
|
||||
|
||||
// 规范化路径:移除 ./ 前缀,统一斜杠
|
||||
// Normalize path: remove ./ prefix, unify slashes
|
||||
let normalizedPath = path.replace(/\\/g, '/');
|
||||
|
||||
// 移除开头的 ./
|
||||
if (normalizedPath.startsWith('./')) {
|
||||
normalizedPath = normalizedPath.substring(2);
|
||||
}
|
||||
|
||||
// 移除开头的 /
|
||||
if (normalizedPath.startsWith('/')) {
|
||||
normalizedPath = normalizedPath.substring(1);
|
||||
}
|
||||
|
||||
// 如果路径以 assets/ 开头,移除它(避免与 baseUrl 重复)
|
||||
// If path starts with assets/, remove it (avoid duplication with baseUrl)
|
||||
if (normalizedPath.startsWith('assets/')) {
|
||||
normalizedPath = normalizedPath.substring(7);
|
||||
}
|
||||
|
||||
// 确保 baseUrl 没有尾部斜杠
|
||||
// Ensure baseUrl has no trailing slash
|
||||
const base = this._baseUrl.replace(/\/+$/, '');
|
||||
|
||||
return `${base}/${normalizedPath}`;
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新基础 URL
|
||||
* Update base URL
|
||||
*/
|
||||
setBaseUrl(baseUrl: string): void {
|
||||
this._baseUrl = baseUrl;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置解析模式
|
||||
* Set resolve mode
|
||||
*/
|
||||
setMode(mode: BrowserPathResolveMode): void {
|
||||
this._mode = mode;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 浏览器平台适配器配置
|
||||
* Browser platform adapter configuration
|
||||
*/
|
||||
export interface BrowserPlatformConfig {
|
||||
/** WASM 模块(预加载的)*/
|
||||
/** WASM 模块(预加载的)| Pre-loaded WASM module */
|
||||
wasmModule?: any;
|
||||
/** WASM 模块加载器(异步加载)*/
|
||||
/** WASM 模块加载器(异步加载)| Async WASM module loader */
|
||||
wasmModuleLoader?: () => Promise<any>;
|
||||
/** 资产基础 URL */
|
||||
/** 资产基础 URL | Asset base URL */
|
||||
assetBaseUrl?: string;
|
||||
/**
|
||||
* 路径解析模式 | Path resolve mode
|
||||
* - 'proxy': 使用 /asset?path=... 格式(默认,编辑器使用)
|
||||
* - 'direct': 使用直接路径(独立 Web 构建使用)
|
||||
*/
|
||||
pathResolveMode?: BrowserPathResolveMode;
|
||||
/**
|
||||
* 输入子系统工厂函数
|
||||
* Input subsystem factory function
|
||||
@@ -87,7 +152,10 @@ export class BrowserPlatformAdapter implements IPlatformAdapter {
|
||||
|
||||
constructor(config: BrowserPlatformConfig = {}) {
|
||||
this._config = config;
|
||||
this._pathResolver = new BrowserPathResolver(config.assetBaseUrl || '');
|
||||
this._pathResolver = new BrowserPathResolver(
|
||||
config.assetBaseUrl || '/assets',
|
||||
config.pathResolveMode || 'proxy'
|
||||
);
|
||||
}
|
||||
|
||||
get pathResolver(): IPathResolver {
|
||||
|
||||
@@ -12,6 +12,7 @@ import type {
|
||||
PlatformCapabilities,
|
||||
PlatformAdapterConfig
|
||||
} from '../IPlatformAdapter';
|
||||
import type { IPlatformInputSubsystem } from '@esengine/platform-common';
|
||||
|
||||
/**
|
||||
* 编辑器路径解析器
|
||||
@@ -61,6 +62,14 @@ export interface EditorPlatformConfig {
|
||||
gizmoDataProvider?: (component: any, entity: any, isSelected: boolean) => any;
|
||||
/** Gizmo 检查函数 */
|
||||
hasGizmoProvider?: (component: any) => boolean;
|
||||
/**
|
||||
* 输入子系统工厂函数
|
||||
* Input subsystem factory function
|
||||
*
|
||||
* 用于在 Play 模式下接收游戏输入
|
||||
* Used to receive game input in Play mode
|
||||
*/
|
||||
inputSubsystemFactory?: () => IPlatformInputSubsystem;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -84,6 +93,7 @@ export class EditorPlatformAdapter implements IPlatformAdapter {
|
||||
private _viewportSize = { width: 0, height: 0 };
|
||||
private _showGrid = true;
|
||||
private _showGizmos = true;
|
||||
private _inputSubsystem: IPlatformInputSubsystem | null = null;
|
||||
|
||||
constructor(config: EditorPlatformConfig) {
|
||||
this._config = config;
|
||||
@@ -137,6 +147,12 @@ export class EditorPlatformAdapter implements IPlatformAdapter {
|
||||
this._canvas.height = height;
|
||||
this._viewportSize = { width, height };
|
||||
}
|
||||
|
||||
// 创建输入子系统(如果提供了工厂函数)
|
||||
// Create input subsystem (if factory provided)
|
||||
if (this._config.inputSubsystemFactory) {
|
||||
this._inputSubsystem = this._config.inputSubsystemFactory();
|
||||
}
|
||||
}
|
||||
|
||||
async getWasmModule(): Promise<any> {
|
||||
@@ -179,7 +195,22 @@ export class EditorPlatformAdapter implements IPlatformAdapter {
|
||||
return this._showGizmos;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取输入子系统
|
||||
* Get input subsystem
|
||||
*
|
||||
* 用于 InputSystem 接收游戏输入事件
|
||||
* Used by InputSystem to receive game input events
|
||||
*/
|
||||
getInputSubsystem(): IPlatformInputSubsystem | null {
|
||||
return this._inputSubsystem;
|
||||
}
|
||||
|
||||
dispose(): void {
|
||||
if (this._inputSubsystem) {
|
||||
this._inputSubsystem.dispose?.();
|
||||
this._inputSubsystem = null;
|
||||
}
|
||||
this._canvas = null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,5 +3,10 @@
|
||||
* 平台适配器
|
||||
*/
|
||||
|
||||
export { BrowserPlatformAdapter, BrowserPathResolver, type BrowserPlatformConfig } from './BrowserPlatformAdapter';
|
||||
export {
|
||||
BrowserPlatformAdapter,
|
||||
BrowserPathResolver,
|
||||
type BrowserPlatformConfig,
|
||||
type BrowserPathResolveMode
|
||||
} from './BrowserPlatformAdapter';
|
||||
export { EditorPlatformAdapter, EditorPathResolver, type EditorPlatformConfig } from './EditorPlatformAdapter';
|
||||
|
||||
@@ -4,9 +4,12 @@ export {
|
||||
type SystemContext,
|
||||
type ModuleManifest,
|
||||
type IRuntimeModule,
|
||||
type IPlugin
|
||||
type IRuntimePlugin
|
||||
} from './PluginManager';
|
||||
|
||||
/** @deprecated Use IRuntimePlugin instead */
|
||||
export type { IRuntimePlugin as IPlugin } from './PluginManager';
|
||||
|
||||
export {
|
||||
createPlugin,
|
||||
registerPlugin,
|
||||
@@ -57,6 +60,7 @@ export {
|
||||
BrowserPlatformAdapter,
|
||||
BrowserPathResolver,
|
||||
type BrowserPlatformConfig,
|
||||
type BrowserPathResolveMode,
|
||||
EditorPlatformAdapter,
|
||||
EditorPathResolver,
|
||||
type EditorPlatformConfig
|
||||
@@ -87,7 +91,6 @@ export {
|
||||
type InputSystemConfig,
|
||||
type KeyState,
|
||||
type MouseButtonState,
|
||||
type Vector2,
|
||||
type KeyboardEventInfo,
|
||||
type MouseEventInfo,
|
||||
type WheelEventInfo,
|
||||
@@ -95,13 +98,18 @@ export {
|
||||
type TouchEvent
|
||||
} from '@esengine/engine-core';
|
||||
|
||||
// Re-export Plugin Service Registry from engine-core
|
||||
// Re-export vector interfaces from math
|
||||
export type { IVector2, IVector3 } from '@esengine/ecs-framework-math';
|
||||
|
||||
// Re-export Plugin Service Registry from ecs-framework (canonical source)
|
||||
export {
|
||||
PluginServiceRegistry,
|
||||
createServiceToken,
|
||||
TransformTypeToken,
|
||||
type ServiceToken
|
||||
} from '@esengine/engine-core';
|
||||
} from '@esengine/ecs-framework';
|
||||
|
||||
// Re-export engine-specific tokens from engine-core
|
||||
export { TransformTypeToken } from '@esengine/engine-core';
|
||||
|
||||
// Re-export service tokens from their respective modules
|
||||
export {
|
||||
|
||||
@@ -95,20 +95,30 @@ export class BrowserFileSystemService {
|
||||
/**
|
||||
* Normalize catalog to ensure it has all required fields
|
||||
* 规范化目录,确保包含所有必需字段
|
||||
*
|
||||
* Supports both 'entries' (IAssetCatalog) and 'assets' (IRuntimeCatalog) field names.
|
||||
* 同时支持 'entries' (IAssetCatalog) 和 'assets' (IRuntimeCatalog) 字段名。
|
||||
*/
|
||||
private _normalizeCatalog(raw: Record<string, unknown>): IAssetCatalog {
|
||||
// Determine load strategy
|
||||
// 确定加载策略
|
||||
let loadStrategy: AssetLoadStrategy = 'file';
|
||||
if (raw.loadStrategy === 'bundle' || raw.bundles) {
|
||||
// Only use bundle strategy if explicitly set or bundles is non-empty
|
||||
// 仅当明确设置或 bundles 非空时才使用 bundle 策略
|
||||
const hasBundles = raw.bundles && typeof raw.bundles === 'object' && Object.keys(raw.bundles as object).length > 0;
|
||||
if (raw.loadStrategy === 'bundle' || hasBundles) {
|
||||
loadStrategy = 'bundle';
|
||||
}
|
||||
|
||||
// Support both 'entries' and 'assets' field names for compatibility
|
||||
// 同时支持 'entries' 和 'assets' 字段名以保持兼容性
|
||||
const entries = (raw.entries ?? raw.assets) as Record<string, IAssetCatalogEntry> ?? {};
|
||||
|
||||
return {
|
||||
version: (raw.version as string) ?? '1.0.0',
|
||||
createdAt: (raw.createdAt as number) ?? Date.now(),
|
||||
loadStrategy,
|
||||
entries: (raw.entries as Record<string, IAssetCatalogEntry>) ?? {},
|
||||
entries,
|
||||
bundles: (raw.bundles as Record<string, IAssetBundleInfo>) ?? undefined
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user