MCPcopy Create free account
hub / github.com/esengine/esengine / dispose

Function dispose

packages/core/src/ECS/Systems/EntitySystem.ts:1144–1170  ·  view source on GitHub ↗

* 释放系统资源 * * 实现IService接口要求的dispose方法。 * 当系统从Scene中移除或Scene销毁时调用。 * * 默认行为: * - 移除所有事件监听器 * - 调用 onDestroy 回调(仅首次) * - 清空所有缓存 * - 重置初始化状态 * * 子类可以重写此方法来清理自定义资源,但应该调用super.dispose()。

()

Source from the content-addressed store, hash-verified

1142 * 子类可以重写此方法来清理自定义资源,但应该调用super.dispose()。
1143 */
1144 public dispose(): void {
1145 // 防止重复销毁
1146 if (this._destroyed) {
1147 return;
1148 }
1149
1150 // 移除所有事件监听器
1151 this.cleanupManualEventListeners();
1152
1153 // 调用用户销毁回调
1154 this.onDestroy();
1155
1156 // 清空所有缓存
1157 this._entityCache.clearAll();
1158 this._entityIdMap = null;
1159
1160 // 清理命令缓冲区
1161 // Clear command buffer
1162 this.commands.dispose();
1163
1164 // 重置状态
1165 this._initialized = false;
1166 this._scene = null;
1167 this._destroyed = true;
1168
1169 this.logger.debug(`System ${this._systemName} disposed`);
1170 }
1171
1172 /**
1173 * 添加事件监听器

Callers

nothing calls this directly

Calls 4

onDestroyMethod · 0.65
disposeMethod · 0.65
clearAllMethod · 0.45
debugMethod · 0.45

Tested by

no test coverage detected