Skip to content

ECS Framework API v2.2.11


ECS Framework API / IncrementalSerializer

Class: IncrementalSerializer

Defined in: packages/core/src/ECS/Serialization/IncrementalSerializer.ts:166

增量序列化器类

Constructors

Constructor

new IncrementalSerializer(): IncrementalSerializer

Returns

IncrementalSerializer

Methods

createSnapshot()

static createSnapshot(scene, options?): SceneSnapshot

Defined in: packages/core/src/ECS/Serialization/IncrementalSerializer.ts:177

创建场景快照

Parameters

scene

IScene

要快照的场景

options?

IncrementalSerializationOptions

序列化选项

Returns

SceneSnapshot

场景快照对象


computeIncremental()

static computeIncremental(scene, baseSnapshot, options?): IncrementalSnapshot

Defined in: packages/core/src/ECS/Serialization/IncrementalSerializer.ts:249

计算增量变更

Parameters

scene

IScene

当前场景

baseSnapshot

SceneSnapshot

基础快照

options?

IncrementalSerializationOptions

序列化选项

Returns

IncrementalSnapshot

增量快照


applyIncremental()

static applyIncremental(scene, incremental, componentRegistry): void

Defined in: packages/core/src/ECS/Serialization/IncrementalSerializer.ts:467

应用增量变更到场景

Parameters

scene

IScene

目标场景

incremental

IncrementalSnapshot

增量快照

componentRegistry

Map<string, ComponentType>

组件类型注册表

Returns

void


serializeIncremental()

static serializeIncremental(incremental, options?): string | Uint8Array<ArrayBufferLike>

Defined in: packages/core/src/ECS/Serialization/IncrementalSerializer.ts:631

序列化增量快照

Parameters

incremental

IncrementalSnapshot

增量快照

options?

序列化选项

format?

IncrementalSerializationFormat

pretty?

boolean

Returns

string | Uint8Array<ArrayBufferLike>

序列化后的数据(JSON字符串或二进制Uint8Array)

Example

typescript
// JSON格式(默认)
const jsonData = IncrementalSerializer.serializeIncremental(snapshot);

// 二进制格式
const binaryData = IncrementalSerializer.serializeIncremental(snapshot, {
    format: 'binary'
});

// 美化JSON
const prettyJson = IncrementalSerializer.serializeIncremental(snapshot, {
    format: 'json',
    pretty: true
});

deserializeIncremental()

static deserializeIncremental(data): IncrementalSnapshot

Defined in: packages/core/src/ECS/Serialization/IncrementalSerializer.ts:665

反序列化增量快照

Parameters

data

序列化的数据(JSON字符串或二进制Uint8Array)

string | Uint8Array<ArrayBufferLike>

Returns

IncrementalSnapshot

增量快照

Example

typescript
// 从JSON反序列化
const snapshot = IncrementalSerializer.deserializeIncremental(jsonString);

// 从二进制反序列化
const snapshot = IncrementalSerializer.deserializeIncremental(buffer);

getIncrementalStats()

static getIncrementalStats(incremental): object

Defined in: packages/core/src/ECS/Serialization/IncrementalSerializer.ts:679

获取增量快照的统计信息

Parameters

incremental

IncrementalSnapshot

增量快照

Returns

object

统计信息

totalChanges

totalChanges: number

entityChanges

entityChanges: number

componentChanges

componentChanges: number

sceneDataChanges

sceneDataChanges: number

addedEntities

addedEntities: number

removedEntities

removedEntities: number

updatedEntities

updatedEntities: number

addedComponents

addedComponents: number

removedComponents

removedComponents: number

updatedComponents

updatedComponents: number


resetVersion()

static resetVersion(): void

Defined in: packages/core/src/ECS/Serialization/IncrementalSerializer.ts:723

重置快照版本号(用于测试)

Returns

void

Released under the MIT License.