feat(asset): 统一资产引用使用 GUID 替代路径 (#287)

* feat(world-streaming): 添加世界流式加载系统

实现基于区块的世界流式加载系统,支持开放世界游戏:

运行时包 (@esengine/world-streaming):
- ChunkComponent: 区块实体组件,包含坐标、边界、状态
- StreamingAnchorComponent: 流式锚点组件(玩家/摄像机)
- ChunkLoaderComponent: 流式加载配置组件
- ChunkStreamingSystem: 区块加载/卸载调度系统
- ChunkCullingSystem: 区块可见性剔除系统
- ChunkManager: 区块生命周期管理服务
- SpatialHashGrid: 空间哈希网格
- ChunkSerializer: 区块序列化

编辑器包 (@esengine/world-streaming-editor):
- ChunkVisualizer: 区块可视化覆盖层
- ChunkLoaderInspectorProvider: 区块加载器检视器
- StreamingAnchorInspectorProvider: 流式锚点检视器
- WorldStreamingPlugin: 完整插件导出

* feat(asset): 统一资产引用使用 GUID 替代路径

将所有组件的资产引用字段从路径改为 GUID:
- SpriteComponent: texture -> textureGuid, material -> materialGuid
- SpriteAnimatorComponent: AnimationFrame.texture -> textureGuid
- UIRenderComponent: texture -> textureGuid
- UIButtonComponent: normalTexture -> normalTextureGuid 等
- AudioSourceComponent: clip -> clipGuid
- ParticleSystemComponent: 已使用 textureGuid

修复 AssetRegistryService 注册问题和路径规范化,
添加渲染系统的 GUID 解析支持。

* fix(sprite-editor): 更新 material 为 materialGuid

* fix(editor-app): 更新 AnimationFrame.texture 为 textureGuid
This commit is contained in:
YHH
2025-12-06 14:08:48 +08:00
committed by GitHub
parent 0c03b13d74
commit 3617f40309
25 changed files with 443 additions and 152 deletions

View File

@@ -5,8 +5,11 @@ import { Component, ECSComponent, Serializable, Serialize, Property } from '@ese
* Animation frame data
*/
export interface AnimationFrame {
/** 纹理路径 | Texture path */
texture: string;
/**
* 纹理资产 GUID
* Texture asset GUID
*/
textureGuid: string;
/** 帧持续时间(秒) | Frame duration in seconds */
duration: number;
/** UV坐标 [u0, v0, u1, v1] | UV coordinates */
@@ -43,7 +46,7 @@ export class SpriteAnimatorComponent extends Component {
@Property({
type: 'animationClips',
label: 'Animation Clips',
controls: [{ component: 'Sprite', property: 'texture' }]
controls: [{ component: 'Sprite', property: 'textureGuid' }]
})
public clips: AnimationClip[] = [];
@@ -101,7 +104,7 @@ export class SpriteAnimatorComponent extends Component {
* Create animation clip from sprite atlas
*
* @param name - 动画名称 | Animation name
* @param texture - 纹理路径 | Texture path
* @param textureGuid - 纹理资产 GUID | Texture asset GUID
* @param frameCount - 帧数 | Number of frames
* @param frameWidth - 每帧宽度 | Frame width
* @param frameHeight - 每帧高度 | Frame height
@@ -112,7 +115,7 @@ export class SpriteAnimatorComponent extends Component {
*/
createClipFromAtlas(
name: string,
texture: string,
textureGuid: string,
frameCount: number,
frameWidth: number,
frameHeight: number,
@@ -132,7 +135,7 @@ export class SpriteAnimatorComponent extends Component {
const y = row * frameHeight;
frames.push({
texture,
textureGuid,
duration,
uv: [
x / atlasWidth,
@@ -159,19 +162,19 @@ export class SpriteAnimatorComponent extends Component {
* Create animation clip from frame sequence
*
* @param name - 动画名称 | Animation name
* @param textures - 纹理路径数组 | Array of texture paths
* @param textureGuids - 纹理资产 GUID 数组 | Array of texture asset GUIDs
* @param fps - 帧率 | Frames per second
* @param loop - 是否循环 | Whether to loop
*/
createClipFromSequence(
name: string,
textures: string[],
textureGuids: string[],
fps: number = 12,
loop: boolean = true
): AnimationClip {
const duration = 1 / fps;
const frames: AnimationFrame[] = textures.map((texture) => ({
texture,
const frames: AnimationFrame[] = textureGuids.map((textureGuid) => ({
textureGuid,
duration
}));

View File

@@ -27,19 +27,20 @@ export type MaterialOverrides = Record<string, MaterialPropertyOverride>;
* Sprite component - manages 2D image rendering
*/
@ECSComponent('Sprite')
@Serializable({ version: 3, typeId: 'Sprite' })
@Serializable({ version: 4, typeId: 'Sprite' })
export class SpriteComponent extends Component {
/** 纹理路径或资源ID | Texture path or asset ID */
@Serialize()
@Property({ type: 'asset', label: 'Texture', assetType: 'texture' })
public texture: string = '';
/**
* 资产GUID(新的资产系统)
* Asset GUID for new asset system
* 纹理资产 GUID
* Texture asset GUID
*
* Stores the unique identifier of the texture asset.
* The actual file path is resolved at runtime via AssetDatabase.
* 存储纹理资产的唯一标识符。
* 实际文件路径在运行时通过 AssetDatabase 解析。
*/
@Serialize()
public assetGuid?: string;
@Property({ type: 'asset', label: 'Texture', assetType: 'texture' })
public textureGuid: string = '';
/**
* 纹理ID运行时使用
@@ -151,15 +152,15 @@ export class SpriteComponent extends Component {
public sortingOrder: number = 0;
/**
* 材质资产路径(共享材质)
* Material asset path (shared material)
* 材质资产 GUID(共享材质)
* Material asset GUID (shared material)
*
* Multiple sprites can reference the same material file.
* 多个精灵可以引用同一个材质文件。
*/
@Serialize()
@Property({ type: 'asset', label: 'Material', extensions: ['.mat'] })
public material: string = '';
public materialGuid: string = '';
/**
* 材质属性覆盖(实例级别)
@@ -215,9 +216,13 @@ export class SpriteComponent extends Component {
this.originY = value;
}
constructor(texture: string = '') {
/**
* @param textureGuidOrPath - Texture GUID or path (for backward compatibility)
*/
constructor(textureGuidOrPath: string = '') {
super();
this.texture = texture;
// Support both GUID and path for backward compatibility
this.textureGuid = textureGuidOrPath;
}
/**
@@ -260,7 +265,7 @@ export class SpriteComponent extends Component {
}
this._assetReference = reference;
if (reference) {
this.assetGuid = reference.guid;
this.textureGuid = reference.guid;
}
}
@@ -292,11 +297,11 @@ export class SpriteComponent extends Component {
}
/**
* 获取有效的纹理源
* Get effective texture source
* 获取纹理 GUID
* Get texture GUID
*/
getTextureSource(): string {
return this.assetGuid || this.texture;
return this.textureGuid;
}
// ============= Material Override Methods =============

View File

@@ -51,7 +51,7 @@ export class SpriteAnimatorSystem extends EntitySystem {
if (sprite) {
const frame = animator.getCurrentFrame();
if (frame) {
sprite.texture = frame.texture;
sprite.textureGuid = frame.textureGuid;
// Update UV if specified
if (frame.uv) {