2025-12-08 21:47:47 +08:00
|
|
|
|
<h1 align="center">
|
|
|
|
|
|
<img src="https://raw.githubusercontent.com/esengine/esengine/master/docs/public/logo.svg" alt="ESEngine" width="180">
|
|
|
|
|
|
<br>
|
|
|
|
|
|
ESEngine
|
|
|
|
|
|
</h1>
|
|
|
|
|
|
|
|
|
|
|
|
<p align="center">
|
2025-12-26 14:50:35 +08:00
|
|
|
|
<strong>TypeScript 模块化游戏框架</strong>
|
2025-12-08 21:47:47 +08:00
|
|
|
|
</p>
|
|
|
|
|
|
|
|
|
|
|
|
<p align="center">
|
|
|
|
|
|
<a href="https://www.npmjs.com/package/@esengine/ecs-framework"><img src="https://img.shields.io/npm/v/@esengine/ecs-framework?style=flat-square&color=blue" alt="npm"></a>
|
2025-12-13 20:56:22 +08:00
|
|
|
|
<a href="https://github.com/esengine/esengine/actions"><img src="https://img.shields.io/github/actions/workflow/status/esengine/esengine/ci.yml?branch=master&style=flat-square" alt="build"></a>
|
2025-12-08 21:47:47 +08:00
|
|
|
|
<a href="https://github.com/esengine/esengine/blob/master/LICENSE"><img src="https://img.shields.io/badge/license-MIT-green?style=flat-square" alt="license"></a>
|
|
|
|
|
|
<a href="https://github.com/esengine/esengine/stargazers"><img src="https://img.shields.io/github/stars/esengine/esengine?style=flat-square" alt="stars"></a>
|
2025-12-13 20:56:22 +08:00
|
|
|
|
<img src="https://img.shields.io/badge/TypeScript-5.0+-blue?style=flat-square&logo=typescript&logoColor=white" alt="TypeScript">
|
2025-12-08 21:47:47 +08:00
|
|
|
|
</p>
|
|
|
|
|
|
|
|
|
|
|
|
<p align="center">
|
|
|
|
|
|
<a href="./README.md">English</a> | <b>中文</b>
|
|
|
|
|
|
</p>
|
|
|
|
|
|
|
|
|
|
|
|
<p align="center">
|
2025-12-09 09:09:45 +08:00
|
|
|
|
<a href="https://esengine.cn/">文档</a> ·
|
|
|
|
|
|
<a href="https://esengine.cn/api/README">API 参考</a> ·
|
2025-12-08 21:47:47 +08:00
|
|
|
|
<a href="./examples/">示例</a>
|
|
|
|
|
|
</p>
|
|
|
|
|
|
|
|
|
|
|
|
---
|
2025-12-03 22:15:22 +08:00
|
|
|
|
|
2025-12-26 14:50:35 +08:00
|
|
|
|
## ESEngine 是什么?
|
2025-12-23 18:00:21 +08:00
|
|
|
|
|
2025-12-26 14:50:35 +08:00
|
|
|
|
ESEngine 是一套**引擎无关的游戏开发模块**,可与 Cocos Creator、Laya、Phaser、PixiJS 等任何 JavaScript 游戏引擎配合使用。
|
2025-12-03 22:15:22 +08:00
|
|
|
|
|
2025-12-26 14:50:35 +08:00
|
|
|
|
核心是一个高性能的 **ECS(实体-组件-系统)** 框架,配套 AI、网络、物理等可选模块。
|
2025-12-03 22:15:22 +08:00
|
|
|
|
|
|
|
|
|
|
```bash
|
2025-12-08 21:26:35 +08:00
|
|
|
|
npm install @esengine/ecs-framework
|
2025-12-03 22:15:22 +08:00
|
|
|
|
```
|
|
|
|
|
|
|
2025-12-26 14:50:35 +08:00
|
|
|
|
## 功能模块
|
2025-12-03 22:15:22 +08:00
|
|
|
|
|
2025-12-26 14:50:35 +08:00
|
|
|
|
| 模块 | 描述 | 需要渲染引擎 |
|
|
|
|
|
|
|------|------|:----------:|
|
|
|
|
|
|
| **ECS 核心** | 实体-组件-系统框架,支持响应式查询 | 否 |
|
|
|
|
|
|
| **行为树** | AI 行为树,支持可视化编辑 | 否 |
|
|
|
|
|
|
| **蓝图** | 可视化脚本系统 | 否 |
|
|
|
|
|
|
| **状态机** | 有限状态机 | 否 |
|
|
|
|
|
|
| **定时器** | 定时器和冷却系统 | 否 |
|
|
|
|
|
|
| **空间索引** | 空间查询(四叉树、网格) | 否 |
|
|
|
|
|
|
| **寻路** | A* 和导航网格寻路 | 否 |
|
|
|
|
|
|
| **网络** | 客户端/服务端网络通信 (TSRPC) | 否 |
|
|
|
|
|
|
|
|
|
|
|
|
> 所有框架模块都可以独立使用,无需依赖特定渲染引擎。
|
2025-12-03 22:15:22 +08:00
|
|
|
|
|
|
|
|
|
|
## 快速开始
|
|
|
|
|
|
|
|
|
|
|
|
```typescript
|
|
|
|
|
|
import {
|
|
|
|
|
|
Core, Scene, Entity, Component, EntitySystem,
|
|
|
|
|
|
Matcher, Time, ECSComponent, ECSSystem
|
2025-12-08 21:26:35 +08:00
|
|
|
|
} from '@esengine/ecs-framework';
|
2025-12-03 22:15:22 +08:00
|
|
|
|
|
2025-12-26 14:50:35 +08:00
|
|
|
|
// 定义组件(纯数据)
|
2025-12-03 22:15:22 +08:00
|
|
|
|
@ECSComponent('Position')
|
|
|
|
|
|
class Position extends Component {
|
|
|
|
|
|
x = 0;
|
|
|
|
|
|
y = 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@ECSComponent('Velocity')
|
|
|
|
|
|
class Velocity extends Component {
|
|
|
|
|
|
dx = 0;
|
|
|
|
|
|
dy = 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-12-26 14:50:35 +08:00
|
|
|
|
// 定义系统(逻辑)
|
2025-12-03 22:15:22 +08:00
|
|
|
|
@ECSSystem('Movement')
|
|
|
|
|
|
class MovementSystem extends EntitySystem {
|
|
|
|
|
|
constructor() {
|
|
|
|
|
|
super(Matcher.all(Position, Velocity));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
protected process(entities: readonly Entity[]): void {
|
|
|
|
|
|
for (const entity of entities) {
|
|
|
|
|
|
const pos = entity.getComponent(Position);
|
|
|
|
|
|
const vel = entity.getComponent(Velocity);
|
|
|
|
|
|
pos.x += vel.dx * Time.deltaTime;
|
|
|
|
|
|
pos.y += vel.dy * Time.deltaTime;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-12-13 20:56:22 +08:00
|
|
|
|
// 初始化
|
2025-12-03 22:15:22 +08:00
|
|
|
|
Core.create();
|
|
|
|
|
|
const scene = new Scene();
|
|
|
|
|
|
scene.addSystem(new MovementSystem());
|
|
|
|
|
|
|
|
|
|
|
|
const player = scene.createEntity('Player');
|
|
|
|
|
|
player.addComponent(new Position());
|
|
|
|
|
|
player.addComponent(new Velocity());
|
|
|
|
|
|
|
|
|
|
|
|
Core.setScene(scene);
|
2025-12-03 22:48:22 +08:00
|
|
|
|
|
2025-12-26 14:50:35 +08:00
|
|
|
|
// 集成到你的游戏循环
|
2025-12-03 22:48:22 +08:00
|
|
|
|
function gameLoop(currentTime: number) {
|
2025-12-13 20:56:22 +08:00
|
|
|
|
Core.update(currentTime / 1000);
|
2025-12-03 22:48:22 +08:00
|
|
|
|
requestAnimationFrame(gameLoop);
|
|
|
|
|
|
}
|
|
|
|
|
|
requestAnimationFrame(gameLoop);
|
2025-12-03 22:15:22 +08:00
|
|
|
|
```
|
|
|
|
|
|
|
2025-12-26 14:50:35 +08:00
|
|
|
|
## 与其他引擎配合使用
|
|
|
|
|
|
|
|
|
|
|
|
ESEngine 的框架模块设计为可与你喜欢的渲染引擎配合使用:
|
|
|
|
|
|
|
|
|
|
|
|
### 与 Cocos Creator 配合
|
|
|
|
|
|
|
|
|
|
|
|
```typescript
|
|
|
|
|
|
import { Component as CCComponent, _decorator } from 'cc';
|
|
|
|
|
|
import { Core, Scene, Matcher, EntitySystem } from '@esengine/ecs-framework';
|
|
|
|
|
|
import { BehaviorTreeExecutionSystem } from '@esengine/behavior-tree';
|
2025-12-03 22:15:22 +08:00
|
|
|
|
|
2025-12-26 14:50:35 +08:00
|
|
|
|
const { ccclass } = _decorator;
|
2025-12-03 22:15:22 +08:00
|
|
|
|
|
2025-12-26 14:50:35 +08:00
|
|
|
|
@ccclass('GameManager')
|
|
|
|
|
|
export class GameManager extends CCComponent {
|
|
|
|
|
|
private ecsScene!: Scene;
|
|
|
|
|
|
|
|
|
|
|
|
start() {
|
|
|
|
|
|
Core.create();
|
|
|
|
|
|
this.ecsScene = new Scene();
|
|
|
|
|
|
|
|
|
|
|
|
// 添加 ECS 系统
|
|
|
|
|
|
this.ecsScene.addSystem(new BehaviorTreeExecutionSystem());
|
|
|
|
|
|
this.ecsScene.addSystem(new MyGameSystem());
|
|
|
|
|
|
|
|
|
|
|
|
Core.setScene(this.ecsScene);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
update(dt: number) {
|
|
|
|
|
|
Core.update(dt);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
### 与 Laya 配合
|
|
|
|
|
|
|
|
|
|
|
|
```typescript
|
|
|
|
|
|
import { Core, Scene } from '@esengine/ecs-framework';
|
|
|
|
|
|
import { FSMSystem } from '@esengine/fsm';
|
|
|
|
|
|
|
|
|
|
|
|
class Main {
|
|
|
|
|
|
constructor() {
|
|
|
|
|
|
Core.create();
|
|
|
|
|
|
const scene = new Scene();
|
|
|
|
|
|
scene.addSystem(new FSMSystem());
|
|
|
|
|
|
Core.setScene(scene);
|
|
|
|
|
|
|
|
|
|
|
|
Laya.timer.frameLoop(1, this, this.update);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
update() {
|
|
|
|
|
|
Core.update(Laya.timer.delta / 1000);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
## 包列表
|
|
|
|
|
|
|
|
|
|
|
|
### 框架包(引擎无关)
|
|
|
|
|
|
|
|
|
|
|
|
这些包**零渲染依赖**,可与任何引擎配合使用:
|
2025-12-03 22:15:22 +08:00
|
|
|
|
|
2025-12-24 23:33:12 +08:00
|
|
|
|
```bash
|
2025-12-26 14:50:35 +08:00
|
|
|
|
npm install @esengine/ecs-framework # ECS 核心
|
|
|
|
|
|
npm install @esengine/behavior-tree # AI 行为树
|
|
|
|
|
|
npm install @esengine/blueprint # 可视化脚本
|
|
|
|
|
|
npm install @esengine/fsm # 状态机
|
|
|
|
|
|
npm install @esengine/timer # 定时器和冷却
|
|
|
|
|
|
npm install @esengine/spatial # 空间索引
|
|
|
|
|
|
npm install @esengine/pathfinding # 寻路
|
|
|
|
|
|
npm install @esengine/network # 网络
|
2025-12-24 23:33:12 +08:00
|
|
|
|
```
|
2025-12-03 22:15:22 +08:00
|
|
|
|
|
2025-12-26 14:50:35 +08:00
|
|
|
|
### ESEngine 运行时(可选)
|
|
|
|
|
|
|
|
|
|
|
|
如果你需要完整的引擎解决方案:
|
2025-12-03 22:15:22 +08:00
|
|
|
|
|
2025-12-24 23:33:12 +08:00
|
|
|
|
| 分类 | 包名 |
|
2025-12-03 22:15:22 +08:00
|
|
|
|
|------|------|
|
2025-12-26 14:50:35 +08:00
|
|
|
|
| **核心** | `engine-core`, `asset-system`, `material-system` |
|
|
|
|
|
|
| **渲染** | `sprite`, `tilemap`, `particle`, `camera`, `mesh-3d` |
|
2025-12-24 23:33:12 +08:00
|
|
|
|
| **物理** | `physics-rapier2d` |
|
|
|
|
|
|
| **平台** | `platform-web`, `platform-wechat` |
|
|
|
|
|
|
|
2025-12-26 14:50:35 +08:00
|
|
|
|
### 编辑器(可选)
|
2025-12-03 22:15:22 +08:00
|
|
|
|
|
2025-12-26 14:50:35 +08:00
|
|
|
|
基于 Tauri 构建的可视化编辑器:
|
|
|
|
|
|
|
|
|
|
|
|
- 从 [Releases](https://github.com/esengine/esengine/releases) 下载
|
|
|
|
|
|
- 支持行为树编辑、Tilemap 绘制、可视化脚本
|
2025-12-03 22:15:22 +08:00
|
|
|
|
|
2025-12-26 14:50:35 +08:00
|
|
|
|
## 项目结构
|
2025-12-03 22:15:22 +08:00
|
|
|
|
|
2025-12-26 14:50:35 +08:00
|
|
|
|
```
|
|
|
|
|
|
esengine/
|
|
|
|
|
|
├── packages/
|
|
|
|
|
|
│ ├── framework/ # 引擎无关模块(可发布到 NPM)
|
|
|
|
|
|
│ │ ├── core/ # ECS 框架
|
|
|
|
|
|
│ │ ├── math/ # 数学工具
|
|
|
|
|
|
│ │ ├── behavior-tree/ # AI 行为树
|
|
|
|
|
|
│ │ ├── blueprint/ # 可视化脚本
|
|
|
|
|
|
│ │ ├── fsm/ # 有限状态机
|
|
|
|
|
|
│ │ ├── timer/ # 定时器系统
|
|
|
|
|
|
│ │ ├── spatial/ # 空间查询
|
|
|
|
|
|
│ │ ├── pathfinding/ # 寻路
|
|
|
|
|
|
│ │ ├── procgen/ # 程序化生成
|
|
|
|
|
|
│ │ └── network/ # 网络
|
|
|
|
|
|
│ │
|
|
|
|
|
|
│ ├── engine/ # ESEngine 运行时
|
|
|
|
|
|
│ ├── rendering/ # 渲染模块
|
|
|
|
|
|
│ ├── physics/ # 物理模块
|
|
|
|
|
|
│ ├── editor/ # 可视化编辑器
|
|
|
|
|
|
│ └── rust/ # WASM 渲染器
|
|
|
|
|
|
│
|
|
|
|
|
|
├── docs/ # 文档
|
|
|
|
|
|
└── examples/ # 示例
|
|
|
|
|
|
```
|
2025-12-03 22:15:22 +08:00
|
|
|
|
|
2025-12-26 14:50:35 +08:00
|
|
|
|
## 从源码构建
|
2025-12-03 22:15:22 +08:00
|
|
|
|
|
|
|
|
|
|
```bash
|
2025-12-08 21:23:37 +08:00
|
|
|
|
git clone https://github.com/esengine/esengine.git
|
2025-12-08 21:47:47 +08:00
|
|
|
|
cd esengine
|
2025-12-03 22:15:22 +08:00
|
|
|
|
|
|
|
|
|
|
pnpm install
|
|
|
|
|
|
pnpm build
|
|
|
|
|
|
|
2025-12-26 14:50:35 +08:00
|
|
|
|
# 框架包类型检查
|
|
|
|
|
|
pnpm type-check:framework
|
2025-12-03 22:15:22 +08:00
|
|
|
|
|
2025-12-26 14:50:35 +08:00
|
|
|
|
# 运行测试
|
|
|
|
|
|
pnpm test
|
2025-12-03 22:15:22 +08:00
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
## 文档
|
|
|
|
|
|
|
2025-12-26 14:50:35 +08:00
|
|
|
|
- [ECS 框架指南](./packages/framework/core/README.md)
|
|
|
|
|
|
- [行为树指南](./packages/framework/behavior-tree/README.md)
|
2025-12-09 09:09:45 +08:00
|
|
|
|
- [API 参考](https://esengine.cn/api/README)
|
2025-12-03 22:15:22 +08:00
|
|
|
|
|
|
|
|
|
|
## 社区
|
|
|
|
|
|
|
2025-12-24 23:35:43 +08:00
|
|
|
|
- [QQ 交流群](https://jq.qq.com/?_wv=1027&k=29w1Nud6) - 中文社区
|
2025-12-26 14:50:35 +08:00
|
|
|
|
- [Discord](https://discord.gg/gCAgzXFW) - 国际社区
|
2025-12-08 21:23:37 +08:00
|
|
|
|
- [GitHub Issues](https://github.com/esengine/esengine/issues) - Bug 反馈和功能建议
|
|
|
|
|
|
- [GitHub Discussions](https://github.com/esengine/esengine/discussions) - 问题和想法
|
2025-12-03 22:15:22 +08:00
|
|
|
|
|
|
|
|
|
|
## 贡献
|
|
|
|
|
|
|
2025-12-26 14:50:35 +08:00
|
|
|
|
欢迎贡献代码!提交 PR 前请阅读贡献指南。
|
2025-12-03 22:15:22 +08:00
|
|
|
|
|
|
|
|
|
|
1. Fork 仓库
|
2025-12-13 20:56:22 +08:00
|
|
|
|
2. 创建功能分支 (`git checkout -b feature/amazing-feature`)
|
|
|
|
|
|
3. 提交修改 (`git commit -m 'Add amazing feature'`)
|
|
|
|
|
|
4. 推送分支 (`git push origin feature/amazing-feature`)
|
|
|
|
|
|
5. 发起 Pull Request
|
2025-12-03 22:15:22 +08:00
|
|
|
|
|
|
|
|
|
|
## 许可证
|
|
|
|
|
|
|
2025-12-26 14:50:35 +08:00
|
|
|
|
ESEngine 基于 [MIT 协议](LICENSE) 开源,个人和商业使用均免费。
|
2025-12-13 20:56:22 +08:00
|
|
|
|
|
|
|
|
|
|
---
|
|
|
|
|
|
|
|
|
|
|
|
<p align="center">
|
2025-12-26 14:50:35 +08:00
|
|
|
|
由 ESEngine 社区用心打造
|
2025-12-13 20:56:22 +08:00
|
|
|
|
</p>
|