@esengine/ecs-framework 2.2.1 → 2.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.cjs +2 -2
- package/index.cjs.map +1 -1
- package/index.d.ts +259 -202
- package/index.es5.js +2 -2
- package/index.es5.js.map +1 -1
- package/index.mjs +2 -2
- package/index.mjs.map +1 -1
- package/index.umd.js +2 -2
- package/index.umd.js.map +1 -1
- package/package.json +1 -1
package/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @esengine/ecs-framework v2.2.
|
|
2
|
+
* @esengine/ecs-framework v2.2.2
|
|
3
3
|
* TypeScript definitions
|
|
4
4
|
*/
|
|
5
5
|
/**
|
|
@@ -4466,17 +4466,17 @@ declare class SceneSerializer {
|
|
|
4466
4466
|
*
|
|
4467
4467
|
* @param scene 要序列化的场景
|
|
4468
4468
|
* @param options 序列化选项
|
|
4469
|
-
* @returns 序列化后的数据(JSON字符串或二进制
|
|
4469
|
+
* @returns 序列化后的数据(JSON字符串或二进制Uint8Array)
|
|
4470
4470
|
*/
|
|
4471
|
-
static serialize(scene: IScene, options?: SceneSerializationOptions): string |
|
|
4471
|
+
static serialize(scene: IScene, options?: SceneSerializationOptions): string | Uint8Array;
|
|
4472
4472
|
/**
|
|
4473
4473
|
* 反序列化场景
|
|
4474
4474
|
*
|
|
4475
4475
|
* @param scene 目标场景
|
|
4476
|
-
* @param saveData 序列化的数据(JSON字符串或二进制
|
|
4476
|
+
* @param saveData 序列化的数据(JSON字符串或二进制Uint8Array)
|
|
4477
4477
|
* @param options 反序列化选项
|
|
4478
4478
|
*/
|
|
4479
|
-
static deserialize(scene: IScene, saveData: string |
|
|
4479
|
+
static deserialize(scene: IScene, saveData: string | Uint8Array, options?: SceneDeserializationOptions): void;
|
|
4480
4480
|
/**
|
|
4481
4481
|
* 序列化场景自定义数据
|
|
4482
4482
|
*
|
|
@@ -4729,7 +4729,7 @@ declare class IncrementalSerializer {
|
|
|
4729
4729
|
*
|
|
4730
4730
|
* @param incremental 增量快照
|
|
4731
4731
|
* @param options 序列化选项
|
|
4732
|
-
* @returns 序列化后的数据(JSON字符串或二进制
|
|
4732
|
+
* @returns 序列化后的数据(JSON字符串或二进制Uint8Array)
|
|
4733
4733
|
*
|
|
4734
4734
|
* @example
|
|
4735
4735
|
* ```typescript
|
|
@@ -4751,11 +4751,11 @@ declare class IncrementalSerializer {
|
|
|
4751
4751
|
static serializeIncremental(incremental: IncrementalSnapshot, options?: {
|
|
4752
4752
|
format?: IncrementalSerializationFormat;
|
|
4753
4753
|
pretty?: boolean;
|
|
4754
|
-
}): string |
|
|
4754
|
+
}): string | Uint8Array;
|
|
4755
4755
|
/**
|
|
4756
4756
|
* 反序列化增量快照
|
|
4757
4757
|
*
|
|
4758
|
-
* @param data 序列化的数据(JSON字符串或二进制
|
|
4758
|
+
* @param data 序列化的数据(JSON字符串或二进制Uint8Array)
|
|
4759
4759
|
* @returns 增量快照
|
|
4760
4760
|
*
|
|
4761
4761
|
* @example
|
|
@@ -4767,7 +4767,7 @@ declare class IncrementalSerializer {
|
|
|
4767
4767
|
* const snapshot = IncrementalSerializer.deserializeIncremental(buffer);
|
|
4768
4768
|
* ```
|
|
4769
4769
|
*/
|
|
4770
|
-
static deserializeIncremental(data: string |
|
|
4770
|
+
static deserializeIncremental(data: string | Uint8Array): IncrementalSnapshot;
|
|
4771
4771
|
/**
|
|
4772
4772
|
* 计算增量快照的大小(字节)
|
|
4773
4773
|
*
|
|
@@ -5195,10 +5195,10 @@ declare class Scene implements IScene {
|
|
|
5195
5195
|
/**
|
|
5196
5196
|
* 序列化场景
|
|
5197
5197
|
*
|
|
5198
|
-
* 将场景及其所有实体、组件序列化为JSON字符串或二进制
|
|
5198
|
+
* 将场景及其所有实体、组件序列化为JSON字符串或二进制Uint8Array
|
|
5199
5199
|
*
|
|
5200
5200
|
* @param options 序列化选项
|
|
5201
|
-
* @returns 序列化后的数据(JSON字符串或二进制
|
|
5201
|
+
* @returns 序列化后的数据(JSON字符串或二进制Uint8Array)
|
|
5202
5202
|
*
|
|
5203
5203
|
* @example
|
|
5204
5204
|
* ```typescript
|
|
@@ -5214,13 +5214,13 @@ declare class Scene implements IScene {
|
|
|
5214
5214
|
* });
|
|
5215
5215
|
* ```
|
|
5216
5216
|
*/
|
|
5217
|
-
serialize(options?: SceneSerializationOptions): string |
|
|
5217
|
+
serialize(options?: SceneSerializationOptions): string | Uint8Array;
|
|
5218
5218
|
/**
|
|
5219
5219
|
* 反序列化场景
|
|
5220
5220
|
*
|
|
5221
5221
|
* 从序列化数据恢复场景状态
|
|
5222
5222
|
*
|
|
5223
|
-
* @param saveData 序列化的数据(JSON字符串或二进制
|
|
5223
|
+
* @param saveData 序列化的数据(JSON字符串或二进制Uint8Array)
|
|
5224
5224
|
* @param options 反序列化选项
|
|
5225
5225
|
*
|
|
5226
5226
|
* @example
|
|
@@ -5236,7 +5236,7 @@ declare class Scene implements IScene {
|
|
|
5236
5236
|
* });
|
|
5237
5237
|
* ```
|
|
5238
5238
|
*/
|
|
5239
|
-
deserialize(saveData: string |
|
|
5239
|
+
deserialize(saveData: string | Uint8Array, options?: SceneDeserializationOptions): void;
|
|
5240
5240
|
/** 增量序列化的基础快照 */
|
|
5241
5241
|
private _incrementalBaseSnapshot?;
|
|
5242
5242
|
/**
|
|
@@ -5288,7 +5288,7 @@ declare class Scene implements IScene {
|
|
|
5288
5288
|
/**
|
|
5289
5289
|
* 应用增量变更到场景
|
|
5290
5290
|
*
|
|
5291
|
-
* @param incremental 增量快照数据(IncrementalSnapshot对象、JSON字符串或二进制
|
|
5291
|
+
* @param incremental 增量快照数据(IncrementalSnapshot对象、JSON字符串或二进制Uint8Array)
|
|
5292
5292
|
* @param componentRegistry 组件类型注册表(可选,默认使用全局注册表)
|
|
5293
5293
|
*
|
|
5294
5294
|
* @example
|
|
@@ -5300,12 +5300,12 @@ declare class Scene implements IScene {
|
|
|
5300
5300
|
* const jsonData = IncrementalSerializer.serializeIncremental(snapshot, { format: 'json' });
|
|
5301
5301
|
* scene.applyIncremental(jsonData);
|
|
5302
5302
|
*
|
|
5303
|
-
* // 从二进制
|
|
5303
|
+
* // 从二进制Uint8Array应用
|
|
5304
5304
|
* const binaryData = IncrementalSerializer.serializeIncremental(snapshot, { format: 'binary' });
|
|
5305
5305
|
* scene.applyIncremental(binaryData);
|
|
5306
5306
|
* ```
|
|
5307
5307
|
*/
|
|
5308
|
-
applyIncremental(incremental: IncrementalSnapshot | string |
|
|
5308
|
+
applyIncremental(incremental: IncrementalSnapshot | string | Uint8Array, componentRegistry?: Map<string, any>): void;
|
|
5309
5309
|
/**
|
|
5310
5310
|
* 更新增量快照基准
|
|
5311
5311
|
*
|
|
@@ -7417,179 +7417,6 @@ declare class ECSFluentAPI {
|
|
|
7417
7417
|
*/
|
|
7418
7418
|
declare function createECSAPI(scene: IScene, querySystem: QuerySystem, eventSystem: TypeSafeEventSystem): ECSFluentAPI;
|
|
7419
7419
|
|
|
7420
|
-
/**
|
|
7421
|
-
* 单场景管理器
|
|
7422
|
-
*
|
|
7423
|
-
* 适用场景:
|
|
7424
|
-
* - 单人游戏
|
|
7425
|
-
* - 简单场景切换
|
|
7426
|
-
* - 不需要多World隔离的项目
|
|
7427
|
-
*
|
|
7428
|
-
* 特点:
|
|
7429
|
-
* - 轻量级,零额外开销
|
|
7430
|
-
* - 简单直观的API
|
|
7431
|
-
* - 支持延迟场景切换
|
|
7432
|
-
* - 自动管理ECS API
|
|
7433
|
-
*
|
|
7434
|
-
* @example
|
|
7435
|
-
* ```typescript
|
|
7436
|
-
* // 初始化Core
|
|
7437
|
-
* Core.create({ debug: true });
|
|
7438
|
-
*
|
|
7439
|
-
* // 创建场景管理器
|
|
7440
|
-
* const sceneManager = new SceneManager();
|
|
7441
|
-
*
|
|
7442
|
-
* // 设置场景
|
|
7443
|
-
* class GameScene extends Scene {
|
|
7444
|
-
* initialize() {
|
|
7445
|
-
* const player = this.createEntity('Player');
|
|
7446
|
-
* player.addComponent(new Transform(100, 100));
|
|
7447
|
-
* }
|
|
7448
|
-
* }
|
|
7449
|
-
*
|
|
7450
|
-
* sceneManager.setScene(new GameScene());
|
|
7451
|
-
*
|
|
7452
|
-
* // 游戏循环
|
|
7453
|
-
* function gameLoop(deltaTime: number) {
|
|
7454
|
-
* Core.update(deltaTime); // 更新全局服务
|
|
7455
|
-
* sceneManager.update(); // 更新场景
|
|
7456
|
-
* }
|
|
7457
|
-
*
|
|
7458
|
-
* // 延迟切换场景(下一帧生效)
|
|
7459
|
-
* sceneManager.loadScene(new MenuScene());
|
|
7460
|
-
* ```
|
|
7461
|
-
*/
|
|
7462
|
-
declare class SceneManager implements IService {
|
|
7463
|
-
/**
|
|
7464
|
-
* 当前活跃场景
|
|
7465
|
-
*/
|
|
7466
|
-
private _currentScene;
|
|
7467
|
-
/**
|
|
7468
|
-
* 待切换的下一个场景(延迟切换用)
|
|
7469
|
-
*/
|
|
7470
|
-
private _nextScene;
|
|
7471
|
-
/**
|
|
7472
|
-
* ECS流式API
|
|
7473
|
-
*/
|
|
7474
|
-
private _ecsAPI;
|
|
7475
|
-
/**
|
|
7476
|
-
* 日志器
|
|
7477
|
-
*/
|
|
7478
|
-
private _logger;
|
|
7479
|
-
/**
|
|
7480
|
-
* 场景切换回调函数
|
|
7481
|
-
*/
|
|
7482
|
-
private _onSceneChangedCallback?;
|
|
7483
|
-
/**
|
|
7484
|
-
* 设置场景切换回调
|
|
7485
|
-
*
|
|
7486
|
-
* @param callback 场景切换时的回调函数
|
|
7487
|
-
* @internal
|
|
7488
|
-
*/
|
|
7489
|
-
setSceneChangedCallback(callback: () => void): void;
|
|
7490
|
-
/**
|
|
7491
|
-
* 设置当前场景(立即切换)
|
|
7492
|
-
*
|
|
7493
|
-
* 会自动处理旧场景的结束和新场景的初始化。
|
|
7494
|
-
*
|
|
7495
|
-
* @param scene - 要设置的场景实例
|
|
7496
|
-
* @returns 返回设置的场景实例,便于链式调用
|
|
7497
|
-
*
|
|
7498
|
-
* @example
|
|
7499
|
-
* ```typescript
|
|
7500
|
-
* const gameScene = sceneManager.setScene(new GameScene());
|
|
7501
|
-
* console.log(gameScene.name); // 可以立即使用返回的场景
|
|
7502
|
-
* ```
|
|
7503
|
-
*/
|
|
7504
|
-
setScene<T extends IScene>(scene: T): T;
|
|
7505
|
-
/**
|
|
7506
|
-
* 延迟加载场景(下一帧切换)
|
|
7507
|
-
*
|
|
7508
|
-
* 场景不会立即切换,而是在下一次调用 update() 时切换。
|
|
7509
|
-
* 这对于避免在当前帧的中途切换场景很有用。
|
|
7510
|
-
*
|
|
7511
|
-
* @param scene - 要加载的场景实例
|
|
7512
|
-
*
|
|
7513
|
-
* @example
|
|
7514
|
-
* ```typescript
|
|
7515
|
-
* // 在某个System中触发场景切换
|
|
7516
|
-
* class GameOverSystem extends EntitySystem {
|
|
7517
|
-
* process(entities: readonly Entity[]) {
|
|
7518
|
-
* if (playerHealth <= 0) {
|
|
7519
|
-
* sceneManager.loadScene(new GameOverScene());
|
|
7520
|
-
* // 当前帧继续执行,场景将在下一帧切换
|
|
7521
|
-
* }
|
|
7522
|
-
* }
|
|
7523
|
-
* }
|
|
7524
|
-
* ```
|
|
7525
|
-
*/
|
|
7526
|
-
loadScene<T extends IScene>(scene: T): void;
|
|
7527
|
-
/**
|
|
7528
|
-
* 获取当前活跃的场景
|
|
7529
|
-
*
|
|
7530
|
-
* @returns 当前场景实例,如果没有场景则返回null
|
|
7531
|
-
*/
|
|
7532
|
-
get currentScene(): IScene | null;
|
|
7533
|
-
/**
|
|
7534
|
-
* 获取ECS流式API
|
|
7535
|
-
*
|
|
7536
|
-
* 提供便捷的实体查询、事件发射等功能。
|
|
7537
|
-
*
|
|
7538
|
-
* @returns ECS API实例,如果当前没有场景则返回null
|
|
7539
|
-
*
|
|
7540
|
-
* @example
|
|
7541
|
-
* ```typescript
|
|
7542
|
-
* const api = sceneManager.api;
|
|
7543
|
-
* if (api) {
|
|
7544
|
-
* // 查询所有敌人
|
|
7545
|
-
* const enemies = api.find(Enemy, Transform);
|
|
7546
|
-
*
|
|
7547
|
-
* // 发射事件
|
|
7548
|
-
* api.emit('game:start', { level: 1 });
|
|
7549
|
-
* }
|
|
7550
|
-
* ```
|
|
7551
|
-
*/
|
|
7552
|
-
get api(): ECSFluentAPI | null;
|
|
7553
|
-
/**
|
|
7554
|
-
* 更新场景
|
|
7555
|
-
*
|
|
7556
|
-
* 应该在每帧的游戏循环中调用。
|
|
7557
|
-
* 会自动处理延迟场景切换。
|
|
7558
|
-
*
|
|
7559
|
-
* @example
|
|
7560
|
-
* ```typescript
|
|
7561
|
-
* function gameLoop(deltaTime: number) {
|
|
7562
|
-
* Core.update(deltaTime);
|
|
7563
|
-
* sceneManager.update(); // 每帧调用
|
|
7564
|
-
* }
|
|
7565
|
-
* ```
|
|
7566
|
-
*/
|
|
7567
|
-
update(): void;
|
|
7568
|
-
/**
|
|
7569
|
-
* 销毁场景管理器
|
|
7570
|
-
*
|
|
7571
|
-
* 会自动结束当前场景并清理所有资源。
|
|
7572
|
-
* 通常在应用程序关闭时调用。
|
|
7573
|
-
*/
|
|
7574
|
-
destroy(): void;
|
|
7575
|
-
/**
|
|
7576
|
-
* 检查是否有活跃场景
|
|
7577
|
-
*
|
|
7578
|
-
* @returns 如果有活跃场景返回true,否则返回false
|
|
7579
|
-
*/
|
|
7580
|
-
get hasScene(): boolean;
|
|
7581
|
-
/**
|
|
7582
|
-
* 检查是否有待切换的场景
|
|
7583
|
-
*
|
|
7584
|
-
* @returns 如果有待切换场景返回true,否则返回false
|
|
7585
|
-
*/
|
|
7586
|
-
get hasPendingScene(): boolean;
|
|
7587
|
-
/**
|
|
7588
|
-
* 释放资源(IService接口)
|
|
7589
|
-
*/
|
|
7590
|
-
dispose(): void;
|
|
7591
|
-
}
|
|
7592
|
-
|
|
7593
7420
|
/**
|
|
7594
7421
|
* 全局系统接口
|
|
7595
7422
|
* 全局系统是在World级别运行的系统,不依赖特定Scene
|
|
@@ -7688,6 +7515,10 @@ declare class World {
|
|
|
7688
7515
|
* 获取所有Scene
|
|
7689
7516
|
*/
|
|
7690
7517
|
getAllScenes(): IScene[];
|
|
7518
|
+
/**
|
|
7519
|
+
* 移除所有Scene
|
|
7520
|
+
*/
|
|
7521
|
+
removeAllScenes(): void;
|
|
7691
7522
|
/**
|
|
7692
7523
|
* 设置Scene激活状态
|
|
7693
7524
|
*/
|
|
@@ -7823,6 +7654,12 @@ interface IWorldManagerConfig {
|
|
|
7823
7654
|
* 是否启用调试模式
|
|
7824
7655
|
*/
|
|
7825
7656
|
debug?: boolean;
|
|
7657
|
+
/**
|
|
7658
|
+
* 是否创建默认World(默认true)
|
|
7659
|
+
*
|
|
7660
|
+
* 当通过Core使用时应该为true,直接使用WorldManager时可设为false
|
|
7661
|
+
*/
|
|
7662
|
+
createDefaultWorld?: boolean;
|
|
7826
7663
|
}
|
|
7827
7664
|
/**
|
|
7828
7665
|
* World管理器 - 管理所有World实例
|
|
@@ -7852,24 +7689,38 @@ interface IWorldManagerConfig {
|
|
|
7852
7689
|
*
|
|
7853
7690
|
* // 游戏循环
|
|
7854
7691
|
* function gameLoop(deltaTime: number) {
|
|
7855
|
-
* Core.update(deltaTime);
|
|
7856
|
-
* worldManager.updateAll(); // 更新所有活跃World
|
|
7692
|
+
* Core.update(deltaTime); // 自动更新所有@Updatable服务(包括WorldManager)
|
|
7857
7693
|
* }
|
|
7858
7694
|
* ```
|
|
7859
7695
|
*/
|
|
7860
|
-
declare class WorldManager implements IService {
|
|
7696
|
+
declare class WorldManager implements IService, IUpdatable {
|
|
7697
|
+
/**
|
|
7698
|
+
* 默认World的ID
|
|
7699
|
+
*/
|
|
7700
|
+
static readonly DEFAULT_WORLD_ID = "__default__";
|
|
7861
7701
|
private readonly _config;
|
|
7862
7702
|
private readonly _worlds;
|
|
7863
7703
|
private readonly _activeWorlds;
|
|
7864
7704
|
private _cleanupTimer;
|
|
7865
7705
|
private _isRunning;
|
|
7866
7706
|
constructor(config?: IWorldManagerConfig);
|
|
7707
|
+
/**
|
|
7708
|
+
* 获取默认World
|
|
7709
|
+
*
|
|
7710
|
+
* 默认World由WorldManager自动创建,供SceneManager使用。
|
|
7711
|
+
* 此方法主要供SceneManager内部使用。
|
|
7712
|
+
*
|
|
7713
|
+
* @returns 默认World实例
|
|
7714
|
+
*/
|
|
7715
|
+
getDefaultWorld(): World;
|
|
7867
7716
|
/**
|
|
7868
7717
|
* 创建新World
|
|
7869
7718
|
*/
|
|
7870
7719
|
createWorld(worldId: string, config?: IWorldConfig): World;
|
|
7871
7720
|
/**
|
|
7872
7721
|
* 移除World
|
|
7722
|
+
*
|
|
7723
|
+
* 注意:默认World不能被删除
|
|
7873
7724
|
*/
|
|
7874
7725
|
removeWorld(worldId: string): boolean;
|
|
7875
7726
|
/**
|
|
@@ -7895,18 +7746,12 @@ declare class WorldManager implements IService {
|
|
|
7895
7746
|
/**
|
|
7896
7747
|
* 更新所有活跃的World
|
|
7897
7748
|
*
|
|
7898
|
-
*
|
|
7749
|
+
* 此方法由ServiceContainer自动调用(@Updatable装饰器)
|
|
7899
7750
|
* 会自动更新所有活跃World的全局系统和场景。
|
|
7900
7751
|
*
|
|
7901
|
-
* @
|
|
7902
|
-
* ```typescript
|
|
7903
|
-
* function gameLoop(deltaTime: number) {
|
|
7904
|
-
* Core.update(deltaTime); // 更新全局服务
|
|
7905
|
-
* worldManager.updateAll(); // 更新所有World
|
|
7906
|
-
* }
|
|
7907
|
-
* ```
|
|
7752
|
+
* @param deltaTime 帧时间间隔(未使用,保留用于接口兼容)
|
|
7908
7753
|
*/
|
|
7909
|
-
|
|
7754
|
+
update(deltaTime?: number): void;
|
|
7910
7755
|
/**
|
|
7911
7756
|
* 获取所有激活的World
|
|
7912
7757
|
*/
|
|
@@ -7955,6 +7800,12 @@ declare class WorldManager implements IService {
|
|
|
7955
7800
|
* 是否启用调试模式
|
|
7956
7801
|
*/
|
|
7957
7802
|
debug?: boolean;
|
|
7803
|
+
/**
|
|
7804
|
+
* 是否创建默认World(默认true)
|
|
7805
|
+
*
|
|
7806
|
+
* 当通过Core使用时应该为true,直接使用WorldManager时可设为false
|
|
7807
|
+
*/
|
|
7808
|
+
createDefaultWorld?: boolean;
|
|
7958
7809
|
};
|
|
7959
7810
|
worlds: any[];
|
|
7960
7811
|
};
|
|
@@ -8009,6 +7860,12 @@ declare class WorldManager implements IService {
|
|
|
8009
7860
|
* 是否启用调试模式
|
|
8010
7861
|
*/
|
|
8011
7862
|
debug?: boolean;
|
|
7863
|
+
/**
|
|
7864
|
+
* 是否创建默认World(默认true)
|
|
7865
|
+
*
|
|
7866
|
+
* 当通过Core使用时应该为true,直接使用WorldManager时可设为false
|
|
7867
|
+
*/
|
|
7868
|
+
createDefaultWorld?: boolean;
|
|
8012
7869
|
};
|
|
8013
7870
|
};
|
|
8014
7871
|
/**
|
|
@@ -8054,6 +7911,188 @@ declare class WorldManager implements IService {
|
|
|
8054
7911
|
get config(): IWorldManagerConfig;
|
|
8055
7912
|
}
|
|
8056
7913
|
|
|
7914
|
+
/**
|
|
7915
|
+
* 单场景管理器
|
|
7916
|
+
*
|
|
7917
|
+
* 适用场景:
|
|
7918
|
+
* - 单人游戏
|
|
7919
|
+
* - 简单场景切换
|
|
7920
|
+
* - 不需要多World隔离的项目
|
|
7921
|
+
*
|
|
7922
|
+
* 特点:
|
|
7923
|
+
* - 轻量级,零额外开销
|
|
7924
|
+
* - 简单直观的API
|
|
7925
|
+
* - 支持延迟场景切换
|
|
7926
|
+
* - 自动管理ECS API
|
|
7927
|
+
* - 通过依赖注入获取WorldManager的默认World
|
|
7928
|
+
*
|
|
7929
|
+
* @example
|
|
7930
|
+
* ```typescript
|
|
7931
|
+
* // 初始化Core
|
|
7932
|
+
* Core.create({ debug: true });
|
|
7933
|
+
*
|
|
7934
|
+
* // 设置场景
|
|
7935
|
+
* class GameScene extends Scene {
|
|
7936
|
+
* initialize() {
|
|
7937
|
+
* const player = this.createEntity('Player');
|
|
7938
|
+
* player.addComponent(new Transform(100, 100));
|
|
7939
|
+
* }
|
|
7940
|
+
* }
|
|
7941
|
+
*
|
|
7942
|
+
* Core.setScene(new GameScene());
|
|
7943
|
+
*
|
|
7944
|
+
* // 游戏循环
|
|
7945
|
+
* function gameLoop(deltaTime: number) {
|
|
7946
|
+
* Core.update(deltaTime); // 自动更新所有服务(包括SceneManager)
|
|
7947
|
+
* }
|
|
7948
|
+
*
|
|
7949
|
+
* // 延迟切换场景(下一帧生效)
|
|
7950
|
+
* Core.loadScene(new MenuScene());
|
|
7951
|
+
* ```
|
|
7952
|
+
*/
|
|
7953
|
+
declare class SceneManager implements IService, IUpdatable {
|
|
7954
|
+
/**
|
|
7955
|
+
* 内部默认World(从WorldManager获取)
|
|
7956
|
+
*/
|
|
7957
|
+
private _defaultWorld;
|
|
7958
|
+
/**
|
|
7959
|
+
* 待切换的下一个场景(延迟切换用)
|
|
7960
|
+
*/
|
|
7961
|
+
private _nextScene;
|
|
7962
|
+
/**
|
|
7963
|
+
* ECS流式API
|
|
7964
|
+
*/
|
|
7965
|
+
private _ecsAPI;
|
|
7966
|
+
/**
|
|
7967
|
+
* 日志器
|
|
7968
|
+
*/
|
|
7969
|
+
private _logger;
|
|
7970
|
+
/**
|
|
7971
|
+
* 场景切换回调函数
|
|
7972
|
+
*/
|
|
7973
|
+
private _onSceneChangedCallback?;
|
|
7974
|
+
/**
|
|
7975
|
+
* 默认场景ID
|
|
7976
|
+
*/
|
|
7977
|
+
private static readonly DEFAULT_SCENE_ID;
|
|
7978
|
+
/**
|
|
7979
|
+
* 构造函数
|
|
7980
|
+
*
|
|
7981
|
+
* WorldManager通过依赖注入自动传入
|
|
7982
|
+
*
|
|
7983
|
+
* @param worldManager WorldManager实例,用于获取默认World
|
|
7984
|
+
*/
|
|
7985
|
+
constructor(worldManager: WorldManager);
|
|
7986
|
+
/**
|
|
7987
|
+
* 设置场景切换回调
|
|
7988
|
+
*
|
|
7989
|
+
* @param callback 场景切换时的回调函数
|
|
7990
|
+
* @internal
|
|
7991
|
+
*/
|
|
7992
|
+
setSceneChangedCallback(callback: () => void): void;
|
|
7993
|
+
/**
|
|
7994
|
+
* 设置当前场景(立即切换)
|
|
7995
|
+
*
|
|
7996
|
+
* 会自动处理旧场景的结束和新场景的初始化。
|
|
7997
|
+
*
|
|
7998
|
+
* @param scene - 要设置的场景实例
|
|
7999
|
+
* @returns 返回设置的场景实例,便于链式调用
|
|
8000
|
+
*
|
|
8001
|
+
* @example
|
|
8002
|
+
* ```typescript
|
|
8003
|
+
* const gameScene = sceneManager.setScene(new GameScene());
|
|
8004
|
+
* console.log(gameScene.name); // 可以立即使用返回的场景
|
|
8005
|
+
* ```
|
|
8006
|
+
*/
|
|
8007
|
+
setScene<T extends IScene>(scene: T): T;
|
|
8008
|
+
/**
|
|
8009
|
+
* 延迟加载场景(下一帧切换)
|
|
8010
|
+
*
|
|
8011
|
+
* 场景不会立即切换,而是在下一次调用 update() 时切换。
|
|
8012
|
+
* 这对于避免在当前帧的中途切换场景很有用。
|
|
8013
|
+
*
|
|
8014
|
+
* @param scene - 要加载的场景实例
|
|
8015
|
+
*
|
|
8016
|
+
* @example
|
|
8017
|
+
* ```typescript
|
|
8018
|
+
* // 在某个System中触发场景切换
|
|
8019
|
+
* class GameOverSystem extends EntitySystem {
|
|
8020
|
+
* process(entities: readonly Entity[]) {
|
|
8021
|
+
* if (playerHealth <= 0) {
|
|
8022
|
+
* sceneManager.loadScene(new GameOverScene());
|
|
8023
|
+
* // 当前帧继续执行,场景将在下一帧切换
|
|
8024
|
+
* }
|
|
8025
|
+
* }
|
|
8026
|
+
* }
|
|
8027
|
+
* ```
|
|
8028
|
+
*/
|
|
8029
|
+
loadScene<T extends IScene>(scene: T): void;
|
|
8030
|
+
/**
|
|
8031
|
+
* 获取当前活跃的场景
|
|
8032
|
+
*
|
|
8033
|
+
* @returns 当前场景实例,如果没有场景则返回null
|
|
8034
|
+
*/
|
|
8035
|
+
get currentScene(): IScene | null;
|
|
8036
|
+
/**
|
|
8037
|
+
* 获取ECS流式API
|
|
8038
|
+
*
|
|
8039
|
+
* 提供便捷的实体查询、事件发射等功能。
|
|
8040
|
+
*
|
|
8041
|
+
* @returns ECS API实例,如果当前没有场景则返回null
|
|
8042
|
+
*
|
|
8043
|
+
* @example
|
|
8044
|
+
* ```typescript
|
|
8045
|
+
* const api = sceneManager.api;
|
|
8046
|
+
* if (api) {
|
|
8047
|
+
* // 查询所有敌人
|
|
8048
|
+
* const enemies = api.find(Enemy, Transform);
|
|
8049
|
+
*
|
|
8050
|
+
* // 发射事件
|
|
8051
|
+
* api.emit('game:start', { level: 1 });
|
|
8052
|
+
* }
|
|
8053
|
+
* ```
|
|
8054
|
+
*/
|
|
8055
|
+
get api(): ECSFluentAPI | null;
|
|
8056
|
+
/**
|
|
8057
|
+
* 更新场景
|
|
8058
|
+
*
|
|
8059
|
+
* 应该在每帧的游戏循环中调用。
|
|
8060
|
+
* 会自动处理延迟场景切换。
|
|
8061
|
+
*
|
|
8062
|
+
* @example
|
|
8063
|
+
* ```typescript
|
|
8064
|
+
* function gameLoop(deltaTime: number) {
|
|
8065
|
+
* Core.update(deltaTime);
|
|
8066
|
+
* sceneManager.update(); // 每帧调用
|
|
8067
|
+
* }
|
|
8068
|
+
* ```
|
|
8069
|
+
*/
|
|
8070
|
+
update(): void;
|
|
8071
|
+
/**
|
|
8072
|
+
* 销毁场景管理器
|
|
8073
|
+
*
|
|
8074
|
+
* 会自动结束当前场景并清理所有资源。
|
|
8075
|
+
* 通常在应用程序关闭时调用。
|
|
8076
|
+
*/
|
|
8077
|
+
destroy(): void;
|
|
8078
|
+
/**
|
|
8079
|
+
* 检查是否有活跃场景
|
|
8080
|
+
*
|
|
8081
|
+
* @returns 如果有活跃场景返回true,否则返回false
|
|
8082
|
+
*/
|
|
8083
|
+
get hasScene(): boolean;
|
|
8084
|
+
/**
|
|
8085
|
+
* 检查是否有待切换的场景
|
|
8086
|
+
*
|
|
8087
|
+
* @returns 如果有待切换场景返回true,否则返回false
|
|
8088
|
+
*/
|
|
8089
|
+
get hasPendingScene(): boolean;
|
|
8090
|
+
/**
|
|
8091
|
+
* 释放资源(IService接口)
|
|
8092
|
+
*/
|
|
8093
|
+
dispose(): void;
|
|
8094
|
+
}
|
|
8095
|
+
|
|
8057
8096
|
/**
|
|
8058
8097
|
* 组件对象池,用于复用组件实例以减少内存分配
|
|
8059
8098
|
*/
|
|
@@ -9396,6 +9435,24 @@ declare class Core {
|
|
|
9396
9435
|
* ```
|
|
9397
9436
|
*/
|
|
9398
9437
|
static get services(): ServiceContainer;
|
|
9438
|
+
/**
|
|
9439
|
+
* 获取World管理器
|
|
9440
|
+
*
|
|
9441
|
+
* 用于管理多个独立的World实例(高级用户)。
|
|
9442
|
+
*
|
|
9443
|
+
* @returns WorldManager实例
|
|
9444
|
+
* @throws 如果Core实例未创建
|
|
9445
|
+
*
|
|
9446
|
+
* @example
|
|
9447
|
+
* ```typescript
|
|
9448
|
+
* // 创建多个游戏房间
|
|
9449
|
+
* const wm = Core.worldManager;
|
|
9450
|
+
* const room1 = wm.createWorld('room_001');
|
|
9451
|
+
* room1.createScene('game', new GameScene());
|
|
9452
|
+
* room1.start();
|
|
9453
|
+
* ```
|
|
9454
|
+
*/
|
|
9455
|
+
static get worldManager(): WorldManager;
|
|
9399
9456
|
/**
|
|
9400
9457
|
* 创建Core实例
|
|
9401
9458
|
*
|