Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
d8cadf2
refactor(engine): 重构2D渲染管线坐标系统
esengine Nov 21, 2025
7256c12
feat(engine): 完善2D渲染管线和编辑器视口功能
esengine Nov 21, 2025
284318c
feat(editor): 实现Viewport变换工具系统
esengine Nov 21, 2025
a888a21
feat(editor): 优化Inspector渲染性能并修复Gizmo变换工具显示
esengine Nov 22, 2025
45f5226
feat(editor): 实现Run on Device移动预览功能
esengine Nov 22, 2025
17e7ac2
feat(editor): 添加组件属性控制和依赖关系系统
esengine Nov 22, 2025
92f7b34
feat(editor): 实现动画预览功能和优化SpriteAnimator编辑器
esengine Nov 23, 2025
0faa936
feat(editor): 修复SpriteAnimator动画预览功能并迁移CI到pnpm
esengine Nov 23, 2025
57bdfa2
feat(editor): 修复SpriteAnimator动画预览并迁移到pnpm
esengine Nov 23, 2025
9672c3a
feat(editor): 修复SpriteAnimator动画预览并迁移到pnpm
esengine Nov 23, 2025
ac71dee
feat(editor): 修复SpriteAnimator动画预览并迁移到pnpm
esengine Nov 23, 2025
cf67dab
feat(editor): 修复SpriteAnimator动画预览并迁移到pnpm
esengine Nov 23, 2025
7b6b90a
feat(ci): 迁移项目到pnpm并修复CI构建问题
esengine Nov 23, 2025
c5238f7
chore: 迁移CI工作流到pnpm并添加WASM构建支持
esengine Nov 23, 2025
5bb1a0a
chore: 迁移CI工作流到pnpm并添加WASM构建支持
esengine Nov 23, 2025
8840a4a
chore: 迁移CI工作流到pnpm并添加WASM构建支持
esengine Nov 23, 2025
1d11cc0
chore: 迁移CI工作流到pnpm并添加WASM构建支持
esengine Nov 23, 2025
e28bbd0
chore: 迁移CI工作流到pnpm并添加WASM构建支持
esengine Nov 23, 2025
1ff05a8
chore: 迁移CI工作流到pnpm并添加WASM构建支持
esengine Nov 23, 2025
5fdbcb0
chore: 移除 network 相关包
esengine Nov 23, 2025
988fba4
chore: 移除 network 相关包
esengine Nov 23, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
91 changes: 81 additions & 10 deletions package-lock.json

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,9 @@
"format:check": "prettier --check \"packages/**/src/**/*.{ts,tsx,js,jsx}\"",
"type-check": "lerna run type-check",
"lint": "eslint \"packages/**/src/**/*.{ts,tsx,js,jsx}\"",
"lint:fix": "eslint \"packages/**/src/**/*.{ts,tsx,js,jsx}\" --fix"
"lint:fix": "eslint \"packages/**/src/**/*.{ts,tsx,js,jsx}\" --fix",
"build:wasm": "cd packages/engine && wasm-pack build --dev --out-dir pkg",
"build:wasm:release": "cd packages/engine && wasm-pack build --release --out-dir pkg"
},
"author": "yhh",
"license": "MIT",
Expand Down
249 changes: 249 additions & 0 deletions packages/asset-system/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,249 @@
# Asset System / 资产系统

A comprehensive asset management system for the ECS Framework.
ECS框架的综合资产管理系统。

## Features / 特性

- **Lazy Loading** / 懒加载 - Assets are loaded only when needed
- **Reference Counting** / 引用计数 - Automatic memory management
- **Memory Budget** / 内存预算 - Control memory usage with configurable limits
- **Asset Bundles** / 资产包 - Group related assets for efficient loading
- **Hot Reload** / 热重载 - Support for runtime asset updates
- **Multiple Loaders** / 多种加载器 - Built-in support for textures, JSON, text, and binary
- **Dependency Management** / 依赖管理 - Automatic loading of asset dependencies
- **Platform Variants** / 平台变体 - Different assets for different platforms
- **Quality Levels** / 质量级别 - Support for multiple quality settings

## Installation / 安装

```bash
npm install @esengine/asset-system
```

## Basic Usage / 基本用法

### Initialize Asset Manager / 初始化资产管理器

```typescript
import { AssetManager, AssetType } from '@esengine/asset-system';

// Create asset manager
const assetManager = new AssetManager();

// Set memory budget (optional)
assetManager.setMemoryBudget({
maxTotalMemory: 512 * 1024 * 1024, // 512MB
maxTextureMemory: 256 * 1024 * 1024,
maxMeshMemory: 128 * 1024 * 1024,
maxAudioMemory: 64 * 1024 * 1024,
evictionPolicy: 'lru'
});
```

### Load Assets / 加载资产

```typescript
// Load by path
const result = await assetManager.loadAssetByPath('/assets/textures/player.png');
const texture = result.asset;

// Load by GUID
const result2 = await assetManager.loadAsset('550e8400-e29b-41d4-a716-446655440000');
```

### Using Asset References / 使用资产引用

```typescript
import { AssetReference } from '@esengine/asset-system';

// Create a reference
const textureRef = new AssetReference('texture-guid', assetManager);

// Load when needed
const texture = await textureRef.loadAsync();

// Check if loaded
if (textureRef.isLoaded) {
const asset = textureRef.asset;
}

// Release when done
textureRef.release();
```

### Batch Loading / 批量加载

```typescript
// Load multiple assets
const guids = ['guid1', 'guid2', 'guid3'];
const results = await assetManager.loadAssets(guids);

// Preload a group
const preloadGroup = {
name: 'level1',
assets: ['texture1', 'texture2', 'sound1'],
priority: 100,
required: true
};

await assetManager.preloadGroup(preloadGroup, (progress) => {
console.log(`Loading: ${progress.progress * 100}%`);
});
```

## Custom Loaders / 自定义加载器

```typescript
import { IAssetLoader, AssetType } from '@esengine/asset-system';

class CustomLoader implements IAssetLoader {
readonly supportedType = AssetType.Custom;
readonly supportedExtensions = ['.custom'];

async load(path, metadata, options) {
// Your loading logic
const data = await fetch(path);
return {
asset: data,
handle: 0,
metadata,
loadTime: 0
};
}

canLoad(path, metadata) {
return path.endsWith('.custom');
}

estimateMemoryUsage(metadata) {
return metadata.size;
}

dispose(asset) {
// Cleanup
}
}

// Register custom loader
assetManager.registerLoader(AssetType.Custom, new CustomLoader());
```

## Integration with Sprite Component / 与精灵组件集成

```typescript
import { SpriteComponent } from '@esengine/components';
import { AssetReference } from '@esengine/asset-system';

// Create sprite with asset reference
const sprite = new SpriteComponent();
const textureRef = new AssetReference('texture-guid', assetManager);

sprite.setAssetReference(textureRef);
await sprite.loadTextureAsync();
```

## Engine Integration / 引擎集成

```typescript
import { EngineIntegration } from '@esengine/asset-system';

// Create integration
const integration = new EngineIntegration(assetManager, engineBridge);

// Load texture for component
const textureId = await integration.loadTextureForComponent('/assets/player.png');

// Batch load textures
const texturePaths = ['/assets/bg.png', '/assets/enemy.png'];
const textureIds = await integration.loadTexturesBatch(texturePaths);
```

## Asset Database / 资产数据库

```typescript
// Search assets
const textures = assetManager.database.findAssetsByType(AssetType.Texture);

// Search with query
const results = assetManager.database.searchAssets({
name: 'player',
type: AssetType.Texture,
labels: ['character', 'sprite']
});

// Check dependencies
const dependencies = assetManager.database.getDependencies('asset-guid');
```

## Memory Management / 内存管理

```typescript
// Get memory usage
const usage = assetManager.getMemoryUsage();
console.log(`Total: ${usage.total}, Texture: ${usage.texture}`);

// Unload unused assets
assetManager.unloadUnusedAssets();

// Clear cache
assetManager.clearCache();

// Get statistics
const stats = assetManager.getStatistics();
console.log(`Loaded: ${stats.loadedCount}, Memory: ${stats.totalMemory}`);
```

## Asset Catalog / 资产目录

```typescript
// Create catalog
const catalog = {
version: '1.0.0',
createdAt: Date.now(),
entries: new Map([
['texture-guid', {
guid: 'texture-guid',
path: '/assets/player.png',
type: AssetType.Texture,
size: 1024,
hash: 'abc123'
}]
]),
bundles: new Map()
};

// Initialize with catalog
const assetManager = new AssetManager(catalog);
```

## Best Practices / 最佳实践

1. **Use Asset References** / 使用资产引用
- Use `AssetReference` for lazy loading
- Release references when not needed

2. **Set Memory Budgets** / 设置内存预算
- Configure appropriate memory limits
- Choose the right eviction policy

3. **Batch Load** / 批量加载
- Load related assets together
- Use preload groups for levels/scenes

4. **Handle Errors** / 错误处理
- Always catch loading errors
- Provide fallback assets

5. **Clean Up** / 清理
- Release unused assets
- Clear cache when switching scenes

## API Reference / API参考

See the TypeScript definitions for complete API documentation.
查看TypeScript定义以获取完整的API文档。

## License / 许可证

MIT
52 changes: 52 additions & 0 deletions packages/asset-system/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
{
"name": "@esengine/asset-system",
"version": "1.0.0",
"description": "Asset management system for ES Engine",
"main": "dist/index.js",
"module": "dist/index.mjs",
"types": "dist/index.d.ts",
"exports": {
".": {
"import": "./dist/index.mjs",
"require": "./dist/index.js",
"types": "./dist/index.d.ts"
}
},
"files": [
"dist"
],
"scripts": {
"build": "rollup -c",
"build:npm": "npm run build",
"clean": "rimraf dist",
"type-check": "npx tsc --noEmit"
},
"keywords": [
"ecs",
"asset",
"resource",
"bundle"
],
"author": "yhh",
"license": "MIT",
"peerDependencies": {
"@esengine/ecs-framework": "^2.0.0"
},
"devDependencies": {
"@rollup/plugin-commonjs": "^28.0.3",
"@rollup/plugin-node-resolve": "^16.0.1",
"@rollup/plugin-typescript": "^11.1.6",
"rimraf": "^5.0.0",
"rollup": "^4.42.0",
"rollup-plugin-dts": "^6.2.1",
"typescript": "^5.8.3"
},
"publishConfig": {
"access": "public"
},
"repository": {
"type": "git",
"url": "https://github.com/esengine/ecs-framework.git",
"directory": "packages/asset-system"
}
}
49 changes: 49 additions & 0 deletions packages/asset-system/rollup.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import typescript from '@rollup/plugin-typescript';
import resolve from '@rollup/plugin-node-resolve';
import commonjs from '@rollup/plugin-commonjs';
import dts from 'rollup-plugin-dts';

const external = ['@esengine/ecs-framework'];

export default [
// ESM and CJS builds
{
input: 'src/index.ts',
output: [
{
file: 'dist/index.js',
format: 'cjs',
sourcemap: true,
exports: 'named'
},
{
file: 'dist/index.mjs',
format: 'es',
sourcemap: true
}
],
external,
plugins: [
resolve({
preferBuiltins: false,
browser: true
}),
commonjs(),
typescript({
tsconfig: './tsconfig.json',
declaration: false,
declarationMap: false
})
]
},
// Type definitions
{
input: 'src/index.ts',
output: {
file: 'dist/index.d.ts',
format: 'es'
},
external,
plugins: [dts()]
}
];
Loading
Loading