@esengine/ecs-framework 2.1.28 → 2.1.30

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.
Files changed (290) hide show
  1. package/bin/Core.d.ts +279 -0
  2. package/bin/Core.d.ts.map +1 -0
  3. package/bin/Core.js +400 -0
  4. package/bin/Core.js.map +1 -0
  5. package/bin/ECS/Component.d.ts +120 -0
  6. package/bin/ECS/Component.d.ts.map +1 -0
  7. package/bin/ECS/Component.js +129 -0
  8. package/bin/ECS/Component.js.map +1 -0
  9. package/bin/ECS/Components/IUpdatable.d.ts +22 -0
  10. package/bin/ECS/Components/IUpdatable.d.ts.map +1 -0
  11. package/bin/ECS/Components/IUpdatable.js +17 -0
  12. package/bin/ECS/Components/IUpdatable.js.map +1 -0
  13. package/bin/ECS/Components/SceneComponent.d.ts +40 -0
  14. package/bin/ECS/Components/SceneComponent.d.ts.map +1 -0
  15. package/bin/ECS/Components/SceneComponent.js +57 -0
  16. package/bin/ECS/Components/SceneComponent.js.map +1 -0
  17. package/bin/ECS/Core/ArchetypeSystem.d.ts +100 -0
  18. package/bin/ECS/Core/ArchetypeSystem.d.ts.map +1 -0
  19. package/bin/ECS/Core/ArchetypeSystem.js +193 -0
  20. package/bin/ECS/Core/ArchetypeSystem.js.map +1 -0
  21. package/bin/ECS/Core/ComponentIndex.d.ts +151 -0
  22. package/bin/ECS/Core/ComponentIndex.d.ts.map +1 -0
  23. package/bin/ECS/Core/ComponentIndex.js +405 -0
  24. package/bin/ECS/Core/ComponentIndex.js.map +1 -0
  25. package/bin/ECS/Core/ComponentPool.d.ts +88 -0
  26. package/bin/ECS/Core/ComponentPool.d.ts.map +1 -0
  27. package/bin/ECS/Core/ComponentPool.js +159 -0
  28. package/bin/ECS/Core/ComponentPool.js.map +1 -0
  29. package/bin/ECS/Core/ComponentStorage/ComponentRegistry.d.ts +92 -0
  30. package/bin/ECS/Core/ComponentStorage/ComponentRegistry.d.ts.map +1 -0
  31. package/bin/ECS/Core/ComponentStorage/ComponentRegistry.js +167 -0
  32. package/bin/ECS/Core/ComponentStorage/ComponentRegistry.js.map +1 -0
  33. package/bin/ECS/Core/ComponentStorage.d.ts +233 -0
  34. package/bin/ECS/Core/ComponentStorage.d.ts.map +1 -0
  35. package/bin/ECS/Core/ComponentStorage.js +463 -0
  36. package/bin/ECS/Core/ComponentStorage.js.map +1 -0
  37. package/bin/ECS/Core/DirtyTrackingSystem.d.ts +197 -0
  38. package/bin/ECS/Core/DirtyTrackingSystem.d.ts.map +1 -0
  39. package/bin/ECS/Core/DirtyTrackingSystem.js +297 -0
  40. package/bin/ECS/Core/DirtyTrackingSystem.js.map +1 -0
  41. package/bin/ECS/Core/EntityManager.d.ts +379 -0
  42. package/bin/ECS/Core/EntityManager.d.ts.map +1 -0
  43. package/bin/ECS/Core/EntityManager.js +686 -0
  44. package/bin/ECS/Core/EntityManager.js.map +1 -0
  45. package/bin/ECS/Core/EventBus.d.ts +218 -0
  46. package/bin/ECS/Core/EventBus.d.ts.map +1 -0
  47. package/bin/ECS/Core/EventBus.js +402 -0
  48. package/bin/ECS/Core/EventBus.js.map +1 -0
  49. package/bin/ECS/Core/EventSystem.d.ts +237 -0
  50. package/bin/ECS/Core/EventSystem.d.ts.map +1 -0
  51. package/bin/ECS/Core/EventSystem.js +478 -0
  52. package/bin/ECS/Core/EventSystem.js.map +1 -0
  53. package/bin/ECS/Core/Events/index.d.ts +3 -0
  54. package/bin/ECS/Core/Events/index.d.ts.map +1 -0
  55. package/bin/ECS/Core/Events/index.js +3 -0
  56. package/bin/ECS/Core/Events/index.js.map +1 -0
  57. package/bin/ECS/Core/FluentAPI/ComponentBuilder.d.ts +35 -0
  58. package/bin/ECS/Core/FluentAPI/ComponentBuilder.d.ts.map +1 -0
  59. package/bin/ECS/Core/FluentAPI/ComponentBuilder.js +48 -0
  60. package/bin/ECS/Core/FluentAPI/ComponentBuilder.js.map +1 -0
  61. package/bin/ECS/Core/FluentAPI/ECSFluentAPI.d.ts +135 -0
  62. package/bin/ECS/Core/FluentAPI/ECSFluentAPI.d.ts.map +1 -0
  63. package/bin/ECS/Core/FluentAPI/ECSFluentAPI.js +166 -0
  64. package/bin/ECS/Core/FluentAPI/ECSFluentAPI.js.map +1 -0
  65. package/bin/ECS/Core/FluentAPI/EntityBatchOperator.d.ts +58 -0
  66. package/bin/ECS/Core/FluentAPI/EntityBatchOperator.d.ts.map +1 -0
  67. package/bin/ECS/Core/FluentAPI/EntityBatchOperator.js +85 -0
  68. package/bin/ECS/Core/FluentAPI/EntityBatchOperator.js.map +1 -0
  69. package/bin/ECS/Core/FluentAPI/EntityBuilder.d.ts +110 -0
  70. package/bin/ECS/Core/FluentAPI/EntityBuilder.d.ts.map +1 -0
  71. package/bin/ECS/Core/FluentAPI/EntityBuilder.js +174 -0
  72. package/bin/ECS/Core/FluentAPI/EntityBuilder.js.map +1 -0
  73. package/bin/ECS/Core/FluentAPI/SceneBuilder.d.ts +53 -0
  74. package/bin/ECS/Core/FluentAPI/SceneBuilder.d.ts.map +1 -0
  75. package/bin/ECS/Core/FluentAPI/SceneBuilder.js +79 -0
  76. package/bin/ECS/Core/FluentAPI/SceneBuilder.js.map +1 -0
  77. package/bin/ECS/Core/FluentAPI/index.d.ts +6 -0
  78. package/bin/ECS/Core/FluentAPI/index.d.ts.map +1 -0
  79. package/bin/ECS/Core/FluentAPI/index.js +6 -0
  80. package/bin/ECS/Core/FluentAPI/index.js.map +1 -0
  81. package/bin/ECS/Core/FluentAPI.d.ts +2 -0
  82. package/bin/ECS/Core/FluentAPI.d.ts.map +1 -0
  83. package/bin/ECS/Core/FluentAPI.js +3 -0
  84. package/bin/ECS/Core/FluentAPI.js.map +1 -0
  85. package/bin/ECS/Core/Performance/index.d.ts +4 -0
  86. package/bin/ECS/Core/Performance/index.d.ts.map +1 -0
  87. package/bin/ECS/Core/Performance/index.js +4 -0
  88. package/bin/ECS/Core/Performance/index.js.map +1 -0
  89. package/bin/ECS/Core/Query/index.d.ts +4 -0
  90. package/bin/ECS/Core/Query/index.d.ts.map +1 -0
  91. package/bin/ECS/Core/Query/index.js +4 -0
  92. package/bin/ECS/Core/Query/index.js.map +1 -0
  93. package/bin/ECS/Core/QuerySystem.d.ts +438 -0
  94. package/bin/ECS/Core/QuerySystem.d.ts.map +1 -0
  95. package/bin/ECS/Core/QuerySystem.js +974 -0
  96. package/bin/ECS/Core/QuerySystem.js.map +1 -0
  97. package/bin/ECS/Core/SoAStorage.d.ts +97 -0
  98. package/bin/ECS/Core/SoAStorage.d.ts.map +1 -0
  99. package/bin/ECS/Core/SoAStorage.js +548 -0
  100. package/bin/ECS/Core/SoAStorage.js.map +1 -0
  101. package/bin/ECS/Core/Storage/index.d.ts +4 -0
  102. package/bin/ECS/Core/Storage/index.d.ts.map +1 -0
  103. package/bin/ECS/Core/Storage/index.js +4 -0
  104. package/bin/ECS/Core/Storage/index.js.map +1 -0
  105. package/bin/ECS/CoreEvents.d.ts +131 -0
  106. package/bin/ECS/CoreEvents.d.ts.map +1 -0
  107. package/bin/ECS/CoreEvents.js +163 -0
  108. package/bin/ECS/CoreEvents.js.map +1 -0
  109. package/bin/ECS/Entity.d.ts +455 -0
  110. package/bin/ECS/Entity.d.ts.map +1 -0
  111. package/bin/ECS/Entity.js +837 -0
  112. package/bin/ECS/Entity.js.map +1 -0
  113. package/bin/ECS/Scene.d.ts +225 -0
  114. package/bin/ECS/Scene.d.ts.map +1 -0
  115. package/bin/ECS/Scene.js +325 -0
  116. package/bin/ECS/Scene.js.map +1 -0
  117. package/bin/ECS/Systems/EntitySystem.d.ts +200 -0
  118. package/bin/ECS/Systems/EntitySystem.d.ts.map +1 -0
  119. package/bin/ECS/Systems/EntitySystem.js +431 -0
  120. package/bin/ECS/Systems/EntitySystem.js.map +1 -0
  121. package/bin/ECS/Systems/IntervalSystem.d.ts +33 -0
  122. package/bin/ECS/Systems/IntervalSystem.d.ts.map +1 -0
  123. package/bin/ECS/Systems/IntervalSystem.js +50 -0
  124. package/bin/ECS/Systems/IntervalSystem.js.map +1 -0
  125. package/bin/ECS/Systems/PassiveSystem.d.ts +17 -0
  126. package/bin/ECS/Systems/PassiveSystem.d.ts.map +1 -0
  127. package/bin/ECS/Systems/PassiveSystem.js +19 -0
  128. package/bin/ECS/Systems/PassiveSystem.js.map +1 -0
  129. package/bin/ECS/Systems/ProcessingSystem.d.ts +21 -0
  130. package/bin/ECS/Systems/ProcessingSystem.d.ts.map +1 -0
  131. package/bin/ECS/Systems/ProcessingSystem.js +20 -0
  132. package/bin/ECS/Systems/ProcessingSystem.js.map +1 -0
  133. package/bin/ECS/Systems/index.d.ts +5 -0
  134. package/bin/ECS/Systems/index.d.ts.map +1 -0
  135. package/bin/ECS/Systems/index.js +6 -0
  136. package/bin/ECS/Systems/index.js.map +1 -0
  137. package/bin/ECS/Utils/BigIntCompatibility.d.ts +164 -0
  138. package/bin/ECS/Utils/BigIntCompatibility.d.ts.map +1 -0
  139. package/bin/ECS/Utils/BigIntCompatibility.js +578 -0
  140. package/bin/ECS/Utils/BigIntCompatibility.js.map +1 -0
  141. package/bin/ECS/Utils/Bits.d.ts +163 -0
  142. package/bin/ECS/Utils/Bits.d.ts.map +1 -0
  143. package/bin/ECS/Utils/Bits.js +286 -0
  144. package/bin/ECS/Utils/Bits.js.map +1 -0
  145. package/bin/ECS/Utils/ComponentTypeManager.d.ts +50 -0
  146. package/bin/ECS/Utils/ComponentTypeManager.d.ts.map +1 -0
  147. package/bin/ECS/Utils/ComponentTypeManager.js +84 -0
  148. package/bin/ECS/Utils/ComponentTypeManager.js.map +1 -0
  149. package/bin/ECS/Utils/EntityList.d.ts +108 -0
  150. package/bin/ECS/Utils/EntityList.d.ts.map +1 -0
  151. package/bin/ECS/Utils/EntityList.js +262 -0
  152. package/bin/ECS/Utils/EntityList.js.map +1 -0
  153. package/bin/ECS/Utils/EntityProcessorList.d.ts +56 -0
  154. package/bin/ECS/Utils/EntityProcessorList.d.ts.map +1 -0
  155. package/bin/ECS/Utils/EntityProcessorList.js +102 -0
  156. package/bin/ECS/Utils/EntityProcessorList.js.map +1 -0
  157. package/bin/ECS/Utils/IdentifierPool.d.ts +203 -0
  158. package/bin/ECS/Utils/IdentifierPool.d.ts.map +1 -0
  159. package/bin/ECS/Utils/IdentifierPool.js +325 -0
  160. package/bin/ECS/Utils/IdentifierPool.js.map +1 -0
  161. package/bin/ECS/Utils/Matcher.d.ts +143 -0
  162. package/bin/ECS/Utils/Matcher.d.ts.map +1 -0
  163. package/bin/ECS/Utils/Matcher.js +249 -0
  164. package/bin/ECS/Utils/Matcher.js.map +1 -0
  165. package/bin/ECS/Utils/index.d.ts +8 -0
  166. package/bin/ECS/Utils/index.d.ts.map +1 -0
  167. package/bin/ECS/Utils/index.js +9 -0
  168. package/bin/ECS/Utils/index.js.map +1 -0
  169. package/bin/ECS/index.d.ts +12 -0
  170. package/bin/ECS/index.d.ts.map +1 -0
  171. package/bin/ECS/index.js +12 -0
  172. package/bin/ECS/index.js.map +1 -0
  173. package/bin/Types/index.d.ts +471 -0
  174. package/bin/Types/index.d.ts.map +1 -0
  175. package/bin/Types/index.js +5 -0
  176. package/bin/Types/index.js.map +1 -0
  177. package/bin/Utils/Debug/ComponentDataCollector.d.ts +28 -0
  178. package/bin/Utils/Debug/ComponentDataCollector.d.ts.map +1 -0
  179. package/bin/Utils/Debug/ComponentDataCollector.js +248 -0
  180. package/bin/Utils/Debug/ComponentDataCollector.js.map +1 -0
  181. package/bin/Utils/Debug/DebugDataFormatter.d.ts +22 -0
  182. package/bin/Utils/Debug/DebugDataFormatter.d.ts.map +1 -0
  183. package/bin/Utils/Debug/DebugDataFormatter.js +117 -0
  184. package/bin/Utils/Debug/DebugDataFormatter.js.map +1 -0
  185. package/bin/Utils/Debug/DebugManager.d.ts +104 -0
  186. package/bin/Utils/Debug/DebugManager.d.ts.map +1 -0
  187. package/bin/Utils/Debug/DebugManager.js +647 -0
  188. package/bin/Utils/Debug/DebugManager.js.map +1 -0
  189. package/bin/Utils/Debug/EntityDataCollector.d.ts +92 -0
  190. package/bin/Utils/Debug/EntityDataCollector.d.ts.map +1 -0
  191. package/bin/Utils/Debug/EntityDataCollector.js +864 -0
  192. package/bin/Utils/Debug/EntityDataCollector.js.map +1 -0
  193. package/bin/Utils/Debug/PerformanceDataCollector.d.ts +32 -0
  194. package/bin/Utils/Debug/PerformanceDataCollector.d.ts.map +1 -0
  195. package/bin/Utils/Debug/PerformanceDataCollector.js +217 -0
  196. package/bin/Utils/Debug/PerformanceDataCollector.js.map +1 -0
  197. package/bin/Utils/Debug/SceneDataCollector.d.ts +16 -0
  198. package/bin/Utils/Debug/SceneDataCollector.d.ts.map +1 -0
  199. package/bin/Utils/Debug/SceneDataCollector.js +46 -0
  200. package/bin/Utils/Debug/SceneDataCollector.js.map +1 -0
  201. package/bin/Utils/Debug/SystemDataCollector.d.ts +11 -0
  202. package/bin/Utils/Debug/SystemDataCollector.d.ts.map +1 -0
  203. package/bin/Utils/Debug/SystemDataCollector.js +59 -0
  204. package/bin/Utils/Debug/SystemDataCollector.js.map +1 -0
  205. package/bin/Utils/Debug/WebSocketManager.d.ts +59 -0
  206. package/bin/Utils/Debug/WebSocketManager.d.ts.map +1 -0
  207. package/bin/Utils/Debug/WebSocketManager.js +148 -0
  208. package/bin/Utils/Debug/WebSocketManager.js.map +1 -0
  209. package/bin/Utils/Debug/index.d.ts +8 -0
  210. package/bin/Utils/Debug/index.d.ts.map +1 -0
  211. package/bin/Utils/Debug/index.js +8 -0
  212. package/bin/Utils/Debug/index.js.map +1 -0
  213. package/bin/Utils/Emitter.d.ts +43 -0
  214. package/bin/Utils/Emitter.d.ts.map +1 -0
  215. package/bin/Utils/Emitter.js +69 -0
  216. package/bin/Utils/Emitter.js.map +1 -0
  217. package/bin/Utils/Extensions/NumberExtension.d.ts +13 -0
  218. package/bin/Utils/Extensions/NumberExtension.d.ts.map +1 -0
  219. package/bin/Utils/Extensions/NumberExtension.js +17 -0
  220. package/bin/Utils/Extensions/NumberExtension.js.map +1 -0
  221. package/bin/Utils/Extensions/TypeUtils.d.ts +13 -0
  222. package/bin/Utils/Extensions/TypeUtils.d.ts.map +1 -0
  223. package/bin/Utils/Extensions/TypeUtils.js +15 -0
  224. package/bin/Utils/Extensions/TypeUtils.js.map +1 -0
  225. package/bin/Utils/Extensions/index.d.ts +3 -0
  226. package/bin/Utils/Extensions/index.d.ts.map +1 -0
  227. package/bin/Utils/Extensions/index.js +4 -0
  228. package/bin/Utils/Extensions/index.js.map +1 -0
  229. package/bin/Utils/GlobalManager.d.ts +32 -0
  230. package/bin/Utils/GlobalManager.d.ts.map +1 -0
  231. package/bin/Utils/GlobalManager.js +53 -0
  232. package/bin/Utils/GlobalManager.js.map +1 -0
  233. package/bin/Utils/Logger.d.ts +156 -0
  234. package/bin/Utils/Logger.d.ts.map +1 -0
  235. package/bin/Utils/Logger.js +256 -0
  236. package/bin/Utils/Logger.js.map +1 -0
  237. package/bin/Utils/PerformanceMonitor.d.ts +211 -0
  238. package/bin/Utils/PerformanceMonitor.d.ts.map +1 -0
  239. package/bin/Utils/PerformanceMonitor.js +270 -0
  240. package/bin/Utils/PerformanceMonitor.js.map +1 -0
  241. package/bin/Utils/Pool/IPoolable.d.ts +29 -0
  242. package/bin/Utils/Pool/IPoolable.d.ts.map +1 -0
  243. package/bin/Utils/Pool/IPoolable.js +2 -0
  244. package/bin/Utils/Pool/IPoolable.js.map +1 -0
  245. package/bin/Utils/Pool/Pool.d.ts +109 -0
  246. package/bin/Utils/Pool/Pool.d.ts.map +1 -0
  247. package/bin/Utils/Pool/Pool.js +238 -0
  248. package/bin/Utils/Pool/Pool.js.map +1 -0
  249. package/bin/Utils/Pool/PoolManager.d.ts +91 -0
  250. package/bin/Utils/Pool/PoolManager.d.ts.map +1 -0
  251. package/bin/Utils/Pool/PoolManager.js +197 -0
  252. package/bin/Utils/Pool/PoolManager.js.map +1 -0
  253. package/bin/Utils/Pool/index.d.ts +4 -0
  254. package/bin/Utils/Pool/index.d.ts.map +1 -0
  255. package/bin/Utils/Pool/index.js +4 -0
  256. package/bin/Utils/Pool/index.js.map +1 -0
  257. package/bin/Utils/Time.d.ts +47 -0
  258. package/bin/Utils/Time.d.ts.map +1 -0
  259. package/bin/Utils/Time.js +64 -0
  260. package/bin/Utils/Time.js.map +1 -0
  261. package/bin/Utils/Timers/ITimer.d.ts +16 -0
  262. package/bin/Utils/Timers/ITimer.d.ts.map +1 -0
  263. package/bin/Utils/Timers/ITimer.js +2 -0
  264. package/bin/Utils/Timers/ITimer.js.map +1 -0
  265. package/bin/Utils/Timers/Timer.d.ts +30 -0
  266. package/bin/Utils/Timers/Timer.d.ts.map +1 -0
  267. package/bin/Utils/Timers/Timer.js +58 -0
  268. package/bin/Utils/Timers/Timer.js.map +1 -0
  269. package/bin/Utils/Timers/TimerManager.d.ts +19 -0
  270. package/bin/Utils/Timers/TimerManager.d.ts.map +1 -0
  271. package/bin/Utils/Timers/TimerManager.js +33 -0
  272. package/bin/Utils/Timers/TimerManager.js.map +1 -0
  273. package/bin/Utils/index.d.ts +9 -0
  274. package/bin/Utils/index.d.ts.map +1 -0
  275. package/bin/Utils/index.js +9 -0
  276. package/bin/Utils/index.js.map +1 -0
  277. package/bin/index.d.ts +16 -0
  278. package/bin/index.d.ts.map +1 -0
  279. package/bin/index.js +19 -0
  280. package/bin/index.js.map +1 -0
  281. package/package.json +52 -25
  282. package/.npmignore +0 -40
  283. package/LICENSE +0 -201
  284. package/README.md +0 -438
  285. package/SECURITY.md +0 -53
  286. package/index.cjs +0 -2
  287. package/index.cjs.map +0 -1
  288. package/index.d.ts +0 -6383
  289. package/index.mjs +0 -2
  290. package/index.mjs.map +0 -1
@@ -0,0 +1,864 @@
1
+ import { Core } from '../../Core';
2
+ /**
3
+ * 实体数据收集器
4
+ */
5
+ export class EntityDataCollector {
6
+ collectEntityData() {
7
+ const scene = Core.scene;
8
+ if (!scene) {
9
+ return this.getEmptyEntityDebugData();
10
+ }
11
+ const entityList = scene.entities;
12
+ if (!entityList) {
13
+ return this.getEmptyEntityDebugData();
14
+ }
15
+ let stats;
16
+ try {
17
+ stats = entityList.getStats ? entityList.getStats() : this.calculateFallbackEntityStats(entityList);
18
+ }
19
+ catch (error) {
20
+ return {
21
+ totalEntities: 0,
22
+ activeEntities: 0,
23
+ pendingAdd: 0,
24
+ pendingRemove: 0,
25
+ entitiesPerArchetype: [],
26
+ topEntitiesByComponents: [],
27
+ entityHierarchy: [],
28
+ entityDetailsMap: {}
29
+ };
30
+ }
31
+ const archetypeData = this.collectArchetypeData(scene);
32
+ return {
33
+ totalEntities: stats.totalEntities,
34
+ activeEntities: stats.activeEntities,
35
+ pendingAdd: stats.pendingAdd || 0,
36
+ pendingRemove: stats.pendingRemove || 0,
37
+ entitiesPerArchetype: archetypeData.distribution,
38
+ topEntitiesByComponents: archetypeData.topEntities,
39
+ entityHierarchy: [],
40
+ entityDetailsMap: {}
41
+ };
42
+ }
43
+ getRawEntityList() {
44
+ const scene = Core.scene;
45
+ if (!scene)
46
+ return [];
47
+ const entityList = scene.entities;
48
+ if (!entityList?.buffer)
49
+ return [];
50
+ return entityList.buffer.map((entity) => ({
51
+ id: entity.id,
52
+ name: entity.name || `Entity_${entity.id}`,
53
+ active: entity.active !== false,
54
+ enabled: entity.enabled !== false,
55
+ activeInHierarchy: entity.activeInHierarchy !== false,
56
+ componentCount: entity.components.length,
57
+ componentTypes: entity.components.map((component) => component.constructor.name),
58
+ parentId: entity.parent?.id || null,
59
+ childIds: entity.children?.map((child) => child.id) || [],
60
+ depth: entity.getDepth ? entity.getDepth() : 0,
61
+ tag: entity.tag || 0,
62
+ updateOrder: entity.updateOrder || 0
63
+ }));
64
+ }
65
+ getEntityDetails(entityId) {
66
+ try {
67
+ const scene = Core.scene;
68
+ if (!scene)
69
+ return null;
70
+ const entityList = scene.entities;
71
+ if (!entityList?.buffer)
72
+ return null;
73
+ const entity = entityList.buffer.find((e) => e.id === entityId);
74
+ if (!entity)
75
+ return null;
76
+ const baseDebugInfo = entity.getDebugInfo ?
77
+ entity.getDebugInfo() :
78
+ this.buildFallbackEntityInfo(entity);
79
+ const componentDetails = this.extractComponentDetails(entity.components);
80
+ const sceneInfo = this.getSceneInfo(scene);
81
+ return {
82
+ ...baseDebugInfo,
83
+ scene: sceneInfo.name,
84
+ sceneName: sceneInfo.name,
85
+ sceneType: sceneInfo.type,
86
+ parentName: entity.parent?.name || null,
87
+ components: componentDetails || [],
88
+ componentCount: entity.components?.length || 0,
89
+ componentTypes: entity.components?.map((comp) => comp.constructor.name) || []
90
+ };
91
+ }
92
+ catch (error) {
93
+ return {
94
+ error: `获取实体详情失败: ${error instanceof Error ? error.message : String(error)}`,
95
+ scene: '获取失败',
96
+ components: [],
97
+ componentCount: 0,
98
+ componentTypes: []
99
+ };
100
+ }
101
+ }
102
+ getSceneInfo(scene) {
103
+ let sceneName = '当前场景';
104
+ let sceneType = 'Scene';
105
+ try {
106
+ if (scene.name && typeof scene.name === 'string' && scene.name.trim()) {
107
+ sceneName = scene.name.trim();
108
+ }
109
+ else if (scene.constructor && scene.constructor.name) {
110
+ sceneName = scene.constructor.name;
111
+ sceneType = scene.constructor.name;
112
+ }
113
+ else if (scene._name && typeof scene._name === 'string' && scene._name.trim()) {
114
+ sceneName = scene._name.trim();
115
+ }
116
+ else {
117
+ const sceneClassName = Object.getPrototypeOf(scene)?.constructor?.name;
118
+ if (sceneClassName && sceneClassName !== 'Object') {
119
+ sceneName = sceneClassName;
120
+ sceneType = sceneClassName;
121
+ }
122
+ }
123
+ }
124
+ catch (error) {
125
+ sceneName = '场景名获取失败';
126
+ }
127
+ return { name: sceneName, type: sceneType };
128
+ }
129
+ collectEntityDataWithMemory() {
130
+ const scene = Core.scene;
131
+ if (!scene) {
132
+ return this.getEmptyEntityDebugData();
133
+ }
134
+ const entityList = scene.entities;
135
+ if (!entityList) {
136
+ return this.getEmptyEntityDebugData();
137
+ }
138
+ let stats;
139
+ try {
140
+ stats = entityList.getStats ? entityList.getStats() : this.calculateFallbackEntityStats(entityList);
141
+ }
142
+ catch (error) {
143
+ return {
144
+ totalEntities: 0,
145
+ activeEntities: 0,
146
+ pendingAdd: 0,
147
+ pendingRemove: 0,
148
+ entitiesPerArchetype: [],
149
+ topEntitiesByComponents: [],
150
+ entityHierarchy: [],
151
+ entityDetailsMap: {}
152
+ };
153
+ }
154
+ const archetypeData = this.collectArchetypeDataWithMemory(scene);
155
+ return {
156
+ totalEntities: stats.totalEntities,
157
+ activeEntities: stats.activeEntities,
158
+ pendingAdd: stats.pendingAdd || 0,
159
+ pendingRemove: stats.pendingRemove || 0,
160
+ entitiesPerArchetype: archetypeData.distribution,
161
+ topEntitiesByComponents: archetypeData.topEntities,
162
+ entityHierarchy: this.buildEntityHierarchyTree(entityList),
163
+ entityDetailsMap: this.buildEntityDetailsMap(entityList)
164
+ };
165
+ }
166
+ collectArchetypeData(scene) {
167
+ if (scene && scene.archetypeSystem && typeof scene.archetypeSystem.getAllArchetypes === 'function') {
168
+ return this.extractArchetypeStatistics(scene.archetypeSystem);
169
+ }
170
+ const entityContainer = { entities: scene.entities?.buffer || [] };
171
+ return {
172
+ distribution: this.getArchetypeDistributionFast(entityContainer),
173
+ topEntities: this.getTopEntitiesByComponentsFast(entityContainer)
174
+ };
175
+ }
176
+ getArchetypeDistributionFast(entityContainer) {
177
+ const distribution = new Map();
178
+ if (entityContainer && entityContainer.entities) {
179
+ entityContainer.entities.forEach((entity) => {
180
+ const componentTypes = entity.components?.map((comp) => comp.constructor.name) || [];
181
+ const signature = componentTypes.length > 0 ? componentTypes.sort().join(', ') : '无组件';
182
+ const existing = distribution.get(signature);
183
+ if (existing) {
184
+ existing.count++;
185
+ }
186
+ else {
187
+ distribution.set(signature, { count: 1, componentTypes });
188
+ }
189
+ });
190
+ }
191
+ return Array.from(distribution.entries())
192
+ .map(([signature, data]) => ({
193
+ signature,
194
+ count: data.count,
195
+ memory: 0
196
+ }))
197
+ .sort((a, b) => b.count - a.count)
198
+ .slice(0, 20);
199
+ }
200
+ getTopEntitiesByComponentsFast(entityContainer) {
201
+ if (!entityContainer || !entityContainer.entities) {
202
+ return [];
203
+ }
204
+ return entityContainer.entities
205
+ .map((entity) => ({
206
+ id: entity.id.toString(),
207
+ name: entity.name || `Entity_${entity.id}`,
208
+ componentCount: entity.components?.length || 0,
209
+ memory: 0
210
+ }))
211
+ .sort((a, b) => b.componentCount - a.componentCount)
212
+ .slice(0, 10);
213
+ }
214
+ collectArchetypeDataWithMemory(scene) {
215
+ if (scene && scene.archetypeSystem && typeof scene.archetypeSystem.getAllArchetypes === 'function') {
216
+ return this.extractArchetypeStatisticsWithMemory(scene.archetypeSystem);
217
+ }
218
+ const entityContainer = { entities: scene.entities?.buffer || [] };
219
+ return {
220
+ distribution: this.getArchetypeDistributionWithMemory(entityContainer),
221
+ topEntities: this.getTopEntitiesByComponentsWithMemory(entityContainer)
222
+ };
223
+ }
224
+ extractArchetypeStatistics(archetypeSystem) {
225
+ const archetypes = archetypeSystem.getAllArchetypes();
226
+ const distribution = [];
227
+ const topEntities = [];
228
+ archetypes.forEach((archetype) => {
229
+ const signature = archetype.componentTypes?.map((type) => type.name).join(',') || 'Unknown';
230
+ const entityCount = archetype.entities?.length || 0;
231
+ distribution.push({
232
+ signature,
233
+ count: entityCount,
234
+ memory: 0
235
+ });
236
+ if (archetype.entities) {
237
+ archetype.entities.slice(0, 5).forEach((entity) => {
238
+ topEntities.push({
239
+ id: entity.id.toString(),
240
+ name: entity.name || `Entity_${entity.id}`,
241
+ componentCount: entity.components?.length || 0,
242
+ memory: 0
243
+ });
244
+ });
245
+ }
246
+ });
247
+ distribution.sort((a, b) => b.count - a.count);
248
+ topEntities.sort((a, b) => b.componentCount - a.componentCount);
249
+ return { distribution, topEntities };
250
+ }
251
+ extractArchetypeStatisticsWithMemory(archetypeSystem) {
252
+ const archetypes = archetypeSystem.getAllArchetypes();
253
+ const distribution = [];
254
+ const topEntities = [];
255
+ archetypes.forEach((archetype) => {
256
+ const signature = archetype.componentTypes?.map((type) => type.name).join(',') || 'Unknown';
257
+ const entityCount = archetype.entities?.length || 0;
258
+ let actualMemory = 0;
259
+ if (archetype.entities && archetype.entities.length > 0) {
260
+ const sampleSize = Math.min(5, archetype.entities.length);
261
+ let sampleMemory = 0;
262
+ for (let i = 0; i < sampleSize; i++) {
263
+ sampleMemory += this.estimateEntityMemoryUsage(archetype.entities[i]);
264
+ }
265
+ actualMemory = (sampleMemory / sampleSize) * entityCount;
266
+ }
267
+ distribution.push({
268
+ signature,
269
+ count: entityCount,
270
+ memory: actualMemory
271
+ });
272
+ if (archetype.entities) {
273
+ archetype.entities.slice(0, 5).forEach((entity) => {
274
+ topEntities.push({
275
+ id: entity.id.toString(),
276
+ name: entity.name || `Entity_${entity.id}`,
277
+ componentCount: entity.components?.length || 0,
278
+ memory: this.estimateEntityMemoryUsage(entity)
279
+ });
280
+ });
281
+ }
282
+ });
283
+ distribution.sort((a, b) => b.count - a.count);
284
+ topEntities.sort((a, b) => b.componentCount - a.componentCount);
285
+ return { distribution, topEntities };
286
+ }
287
+ getArchetypeDistribution(entityContainer) {
288
+ const distribution = new Map();
289
+ if (entityContainer && entityContainer.entities) {
290
+ entityContainer.entities.forEach((entity) => {
291
+ const signature = entity.componentMask?.toString() || '0';
292
+ const existing = distribution.get(signature);
293
+ distribution.set(signature, (existing || 0) + 1);
294
+ });
295
+ }
296
+ return Array.from(distribution.entries())
297
+ .map(([signature, count]) => ({ signature, count, memory: 0 }))
298
+ .sort((a, b) => b.count - a.count);
299
+ }
300
+ getArchetypeDistributionWithMemory(entityContainer) {
301
+ const distribution = new Map();
302
+ if (entityContainer && entityContainer.entities) {
303
+ entityContainer.entities.forEach((entity) => {
304
+ const componentTypes = entity.components?.map((comp) => comp.constructor.name) || [];
305
+ const signature = componentTypes.length > 0 ? componentTypes.sort().join(', ') : '无组件';
306
+ const existing = distribution.get(signature);
307
+ let memory = this.estimateEntityMemoryUsage(entity);
308
+ if (isNaN(memory) || memory < 0) {
309
+ memory = 0;
310
+ }
311
+ if (existing) {
312
+ existing.count++;
313
+ existing.memory += memory;
314
+ }
315
+ else {
316
+ distribution.set(signature, { count: 1, memory, componentTypes });
317
+ }
318
+ });
319
+ }
320
+ return Array.from(distribution.entries())
321
+ .map(([signature, data]) => ({
322
+ signature,
323
+ count: data.count,
324
+ memory: isNaN(data.memory) ? 0 : data.memory
325
+ }))
326
+ .sort((a, b) => b.count - a.count);
327
+ }
328
+ getTopEntitiesByComponents(entityContainer) {
329
+ if (!entityContainer || !entityContainer.entities) {
330
+ return [];
331
+ }
332
+ return entityContainer.entities
333
+ .map((entity) => ({
334
+ id: entity.id.toString(),
335
+ name: entity.name || `Entity_${entity.id}`,
336
+ componentCount: entity.components?.length || 0,
337
+ memory: 0
338
+ }))
339
+ .sort((a, b) => b.componentCount - a.componentCount);
340
+ }
341
+ getTopEntitiesByComponentsWithMemory(entityContainer) {
342
+ if (!entityContainer || !entityContainer.entities) {
343
+ return [];
344
+ }
345
+ return entityContainer.entities
346
+ .map((entity) => ({
347
+ id: entity.id.toString(),
348
+ name: entity.name || `Entity_${entity.id}`,
349
+ componentCount: entity.components?.length || 0,
350
+ memory: this.estimateEntityMemoryUsage(entity)
351
+ }))
352
+ .sort((a, b) => b.componentCount - a.componentCount);
353
+ }
354
+ getEmptyEntityDebugData() {
355
+ return {
356
+ totalEntities: 0,
357
+ activeEntities: 0,
358
+ pendingAdd: 0,
359
+ pendingRemove: 0,
360
+ entitiesPerArchetype: [],
361
+ topEntitiesByComponents: [],
362
+ entityHierarchy: [],
363
+ entityDetailsMap: {}
364
+ };
365
+ }
366
+ calculateFallbackEntityStats(entityList) {
367
+ const allEntities = entityList.buffer || [];
368
+ const activeEntities = allEntities.filter((entity) => entity.enabled && !entity._isDestroyed);
369
+ return {
370
+ totalEntities: allEntities.length,
371
+ activeEntities: activeEntities.length,
372
+ pendingAdd: 0,
373
+ pendingRemove: 0,
374
+ averageComponentsPerEntity: activeEntities.length > 0 ?
375
+ allEntities.reduce((sum, e) => sum + (e.components?.length || 0), 0) / activeEntities.length : 0
376
+ };
377
+ }
378
+ estimateEntityMemoryUsage(entity) {
379
+ try {
380
+ let totalSize = 0;
381
+ const entitySize = this.calculateObjectSize(entity, ['components', 'children', 'parent']);
382
+ if (!isNaN(entitySize) && entitySize > 0) {
383
+ totalSize += entitySize;
384
+ }
385
+ if (entity.components && Array.isArray(entity.components)) {
386
+ entity.components.forEach((component) => {
387
+ const componentSize = this.calculateObjectSize(component, ['entity']);
388
+ if (!isNaN(componentSize) && componentSize > 0) {
389
+ totalSize += componentSize;
390
+ }
391
+ });
392
+ }
393
+ return isNaN(totalSize) || totalSize < 0 ? 0 : totalSize;
394
+ }
395
+ catch (error) {
396
+ return 0;
397
+ }
398
+ }
399
+ calculateObjectSize(obj, excludeKeys = []) {
400
+ if (!obj || typeof obj !== 'object')
401
+ return 0;
402
+ const visited = new WeakSet();
403
+ const maxDepth = 2;
404
+ const calculate = (item, depth = 0) => {
405
+ if (!item || typeof item !== 'object' || depth >= maxDepth) {
406
+ return 0;
407
+ }
408
+ if (visited.has(item))
409
+ return 0;
410
+ visited.add(item);
411
+ let itemSize = 32;
412
+ try {
413
+ const keys = Object.keys(item);
414
+ const maxKeys = Math.min(keys.length, 20);
415
+ for (let i = 0; i < maxKeys; i++) {
416
+ const key = keys[i];
417
+ if (excludeKeys.includes(key) ||
418
+ key === 'constructor' ||
419
+ key === '__proto__' ||
420
+ key.startsWith('_cc_') ||
421
+ key.startsWith('__')) {
422
+ continue;
423
+ }
424
+ const value = item[key];
425
+ itemSize += key.length * 2;
426
+ if (typeof value === 'string') {
427
+ itemSize += Math.min(value.length * 2, 200);
428
+ }
429
+ else if (typeof value === 'number') {
430
+ itemSize += 8;
431
+ }
432
+ else if (typeof value === 'boolean') {
433
+ itemSize += 4;
434
+ }
435
+ else if (Array.isArray(value)) {
436
+ itemSize += 40 + Math.min(value.length * 8, 160);
437
+ }
438
+ else if (typeof value === 'object' && value !== null) {
439
+ itemSize += calculate(value, depth + 1);
440
+ }
441
+ }
442
+ }
443
+ catch (error) {
444
+ return 64;
445
+ }
446
+ return itemSize;
447
+ };
448
+ try {
449
+ const size = calculate(obj);
450
+ return Math.max(size, 32);
451
+ }
452
+ catch (error) {
453
+ return 64;
454
+ }
455
+ }
456
+ buildEntityHierarchyTree(entityList) {
457
+ if (!entityList?.buffer)
458
+ return [];
459
+ const rootEntities = [];
460
+ entityList.buffer.forEach((entity) => {
461
+ if (!entity.parent) {
462
+ const hierarchyNode = this.buildEntityHierarchyNode(entity);
463
+ rootEntities.push(hierarchyNode);
464
+ }
465
+ });
466
+ // 按实体名称排序,提供一致的显示顺序
467
+ rootEntities.sort((nodeA, nodeB) => {
468
+ if (nodeA.name < nodeB.name)
469
+ return -1;
470
+ if (nodeA.name > nodeB.name)
471
+ return 1;
472
+ return nodeA.id - nodeB.id;
473
+ });
474
+ return rootEntities;
475
+ }
476
+ /**
477
+ * 构建实体层次结构节点
478
+ */
479
+ buildEntityHierarchyNode(entity) {
480
+ let node = {
481
+ id: entity.id,
482
+ name: entity.name || `Entity_${entity.id}`,
483
+ active: entity.active !== false,
484
+ enabled: entity.enabled !== false,
485
+ activeInHierarchy: entity.activeInHierarchy !== false,
486
+ componentCount: entity.components.length,
487
+ componentTypes: entity.components.map((component) => component.constructor.name),
488
+ parentId: entity.parent?.id || null,
489
+ children: [],
490
+ depth: entity.getDepth ? entity.getDepth() : 0,
491
+ tag: entity.tag || 0,
492
+ updateOrder: entity.updateOrder || 0
493
+ };
494
+ // 递归构建子实体节点
495
+ if (entity.children && entity.children.length > 0) {
496
+ node.children = entity.children.map((child) => this.buildEntityHierarchyNode(child));
497
+ }
498
+ // 优先使用Entity的getDebugInfo方法
499
+ if (typeof entity.getDebugInfo === 'function') {
500
+ const debugInfo = entity.getDebugInfo();
501
+ node = {
502
+ ...node,
503
+ ...debugInfo
504
+ };
505
+ }
506
+ // 收集所有组件详细属性信息
507
+ if (entity.components && entity.components.length > 0) {
508
+ node.componentDetails = this.extractComponentDetails(entity.components);
509
+ }
510
+ return node;
511
+ }
512
+ /**
513
+ * 构建实体详情映射
514
+ */
515
+ buildEntityDetailsMap(entityList) {
516
+ if (!entityList?.buffer)
517
+ return {};
518
+ const entityDetailsMap = {};
519
+ const entities = entityList.buffer;
520
+ const batchSize = 100;
521
+ for (let i = 0; i < entities.length; i += batchSize) {
522
+ const batch = entities.slice(i, i + batchSize);
523
+ batch.forEach((entity) => {
524
+ const baseDebugInfo = entity.getDebugInfo ?
525
+ entity.getDebugInfo() :
526
+ this.buildFallbackEntityInfo(entity);
527
+ const componentCacheStats = entity.getComponentCacheStats ?
528
+ entity.getComponentCacheStats() : null;
529
+ const componentDetails = this.extractComponentDetails(entity.components);
530
+ entityDetailsMap[entity.id] = {
531
+ ...baseDebugInfo,
532
+ parentName: entity.parent?.name || null,
533
+ components: componentDetails,
534
+ componentTypes: baseDebugInfo.componentTypes ||
535
+ componentDetails.map((comp) => comp.typeName),
536
+ cachePerformance: componentCacheStats ? {
537
+ hitRate: componentCacheStats.cacheStats.hitRate,
538
+ size: componentCacheStats.cacheStats.size,
539
+ maxSize: componentCacheStats.cacheStats.maxSize
540
+ } : null
541
+ };
542
+ });
543
+ }
544
+ return entityDetailsMap;
545
+ }
546
+ /**
547
+ * 构建实体基础信息
548
+ */
549
+ buildFallbackEntityInfo(entity) {
550
+ const scene = Core.scene;
551
+ const sceneInfo = this.getSceneInfo(scene);
552
+ return {
553
+ name: entity.name || `Entity_${entity.id}`,
554
+ id: entity.id,
555
+ enabled: entity.enabled !== false,
556
+ active: entity.active !== false,
557
+ activeInHierarchy: entity.activeInHierarchy !== false,
558
+ destroyed: entity.isDestroyed || false,
559
+ scene: sceneInfo.name,
560
+ sceneName: sceneInfo.name,
561
+ sceneType: sceneInfo.type,
562
+ componentCount: entity.components.length,
563
+ componentTypes: entity.components.map((component) => component.constructor.name),
564
+ componentMask: entity.componentMask?.toString() || '0',
565
+ parentId: entity.parent?.id || null,
566
+ childCount: entity.children?.length || 0,
567
+ childIds: entity.children.map((child) => child.id) || [],
568
+ depth: entity.getDepth ? entity.getDepth() : 0,
569
+ tag: entity.tag || 0,
570
+ updateOrder: entity.updateOrder || 0
571
+ };
572
+ }
573
+ /**
574
+ * 提取组件详细信息
575
+ */
576
+ extractComponentDetails(components) {
577
+ return components.map((component) => {
578
+ let typeName = component.constructor.name;
579
+ if (!typeName || typeName === 'Object' || typeName === 'Function') {
580
+ try {
581
+ const { ComponentTypeManager } = require('../../ECS/Utils/ComponentTypeManager');
582
+ const typeManager = ComponentTypeManager.instance;
583
+ const componentType = component.constructor;
584
+ const typeId = typeManager.getTypeId(componentType);
585
+ typeName = typeManager.getTypeName(typeId);
586
+ }
587
+ catch (error) {
588
+ typeName = 'UnknownComponent';
589
+ }
590
+ }
591
+ // 提取实际的组件属性
592
+ const properties = {};
593
+ try {
594
+ const propertyKeys = Object.keys(component);
595
+ propertyKeys.forEach(propertyKey => {
596
+ if (!propertyKey.startsWith('_') && propertyKey !== 'entity' && propertyKey !== 'constructor') {
597
+ const propertyValue = component[propertyKey];
598
+ if (propertyValue !== undefined && propertyValue !== null) {
599
+ properties[propertyKey] = this.formatPropertyValue(propertyValue);
600
+ }
601
+ }
602
+ });
603
+ // 如果没有找到任何属性,添加一些调试信息
604
+ if (Object.keys(properties).length === 0) {
605
+ properties._info = '该组件没有公开属性';
606
+ properties._componentId = component.constructor.name;
607
+ }
608
+ }
609
+ catch (error) {
610
+ properties._error = '属性提取失败';
611
+ properties._componentId = component.constructor.name;
612
+ }
613
+ return {
614
+ typeName: typeName,
615
+ properties: properties
616
+ };
617
+ });
618
+ }
619
+ /**
620
+ * 获取组件的完整属性信息(仅在需要时调用)
621
+ */
622
+ getComponentProperties(entityId, componentIndex) {
623
+ try {
624
+ const scene = Core.scene;
625
+ if (!scene)
626
+ return {};
627
+ const entityList = scene.entities;
628
+ if (!entityList?.buffer)
629
+ return {};
630
+ const entity = entityList.buffer.find((e) => e.id === entityId);
631
+ if (!entity || componentIndex >= entity.components.length)
632
+ return {};
633
+ const component = entity.components[componentIndex];
634
+ const properties = {};
635
+ const propertyKeys = Object.keys(component);
636
+ propertyKeys.forEach(propertyKey => {
637
+ if (!propertyKey.startsWith('_') && propertyKey !== 'entity') {
638
+ const propertyValue = component[propertyKey];
639
+ if (propertyValue !== undefined && propertyValue !== null) {
640
+ properties[propertyKey] = this.formatPropertyValue(propertyValue);
641
+ }
642
+ }
643
+ });
644
+ return properties;
645
+ }
646
+ catch (error) {
647
+ return { _error: '属性提取失败' };
648
+ }
649
+ }
650
+ /**
651
+ * 格式化属性值
652
+ */
653
+ formatPropertyValue(value, depth = 0) {
654
+ if (value === null || value === undefined) {
655
+ return value;
656
+ }
657
+ if (typeof value !== 'object') {
658
+ if (typeof value === 'string' && value.length > 200) {
659
+ return `[长字符串: ${value.length}字符] ${value.substring(0, 100)}...`;
660
+ }
661
+ return value;
662
+ }
663
+ if (depth === 0) {
664
+ return this.formatObjectFirstLevel(value);
665
+ }
666
+ else {
667
+ return this.createLazyLoadPlaceholder(value);
668
+ }
669
+ }
670
+ /**
671
+ * 格式化对象第一层
672
+ */
673
+ formatObjectFirstLevel(obj) {
674
+ try {
675
+ if (Array.isArray(obj)) {
676
+ if (obj.length === 0)
677
+ return [];
678
+ if (obj.length > 10) {
679
+ const sample = obj.slice(0, 3).map(item => this.formatPropertyValue(item, 1));
680
+ return {
681
+ _isLazyArray: true,
682
+ _arrayLength: obj.length,
683
+ _sample: sample,
684
+ _summary: `数组[${obj.length}个元素]`
685
+ };
686
+ }
687
+ return obj.map(item => this.formatPropertyValue(item, 1));
688
+ }
689
+ const keys = Object.keys(obj);
690
+ if (keys.length === 0)
691
+ return {};
692
+ const result = {};
693
+ let processedCount = 0;
694
+ const maxProperties = 15;
695
+ for (const key of keys) {
696
+ if (processedCount >= maxProperties) {
697
+ result._hasMoreProperties = true;
698
+ result._totalProperties = keys.length;
699
+ result._hiddenCount = keys.length - processedCount;
700
+ break;
701
+ }
702
+ if (key.startsWith('_') || key.startsWith('$') || typeof obj[key] === 'function') {
703
+ continue;
704
+ }
705
+ try {
706
+ const value = obj[key];
707
+ if (value !== null && value !== undefined) {
708
+ result[key] = this.formatPropertyValue(value, 1);
709
+ processedCount++;
710
+ }
711
+ }
712
+ catch (error) {
713
+ result[key] = `[访问失败: ${error instanceof Error ? error.message : String(error)}]`;
714
+ processedCount++;
715
+ }
716
+ }
717
+ return result;
718
+ }
719
+ catch (error) {
720
+ return `[对象解析失败: ${error instanceof Error ? error.message : String(error)}]`;
721
+ }
722
+ }
723
+ /**
724
+ * 创建懒加载占位符
725
+ */
726
+ createLazyLoadPlaceholder(obj) {
727
+ try {
728
+ const typeName = obj.constructor?.name || 'Object';
729
+ const summary = this.getObjectSummary(obj, typeName);
730
+ return {
731
+ _isLazyObject: true,
732
+ _typeName: typeName,
733
+ _summary: summary,
734
+ _objectId: this.generateObjectId(obj)
735
+ };
736
+ }
737
+ catch (error) {
738
+ return {
739
+ _isLazyObject: true,
740
+ _typeName: 'Unknown',
741
+ _summary: `无法分析的对象: ${error instanceof Error ? error.message : String(error)}`,
742
+ _objectId: Math.random().toString(36).substr(2, 9)
743
+ };
744
+ }
745
+ }
746
+ /**
747
+ * 获取对象摘要信息
748
+ */
749
+ getObjectSummary(obj, typeName) {
750
+ try {
751
+ if (typeName.toLowerCase().includes('vec') || typeName.toLowerCase().includes('vector')) {
752
+ if (obj.x !== undefined && obj.y !== undefined) {
753
+ const z = obj.z !== undefined ? obj.z : '';
754
+ return `${typeName}(${obj.x}, ${obj.y}${z ? ', ' + z : ''})`;
755
+ }
756
+ }
757
+ if (typeName.toLowerCase().includes('color')) {
758
+ if (obj.r !== undefined && obj.g !== undefined && obj.b !== undefined) {
759
+ const a = obj.a !== undefined ? obj.a : 1;
760
+ return `${typeName}(${obj.r}, ${obj.g}, ${obj.b}, ${a})`;
761
+ }
762
+ }
763
+ if (typeName.toLowerCase().includes('node')) {
764
+ const name = obj.name || obj._name || '未命名';
765
+ return `${typeName}: ${name}`;
766
+ }
767
+ if (typeName.toLowerCase().includes('component')) {
768
+ const nodeName = obj.node?.name || obj.node?._name || '';
769
+ return `${typeName}${nodeName ? ` on ${nodeName}` : ''}`;
770
+ }
771
+ const keys = Object.keys(obj);
772
+ if (keys.length === 0) {
773
+ return `${typeName} (空对象)`;
774
+ }
775
+ return `${typeName} (${keys.length}个属性)`;
776
+ }
777
+ catch (error) {
778
+ return `${typeName} (无法分析)`;
779
+ }
780
+ }
781
+ /**
782
+ * 生成对象ID
783
+ */
784
+ generateObjectId(obj) {
785
+ try {
786
+ if (obj.id !== undefined)
787
+ return `obj_${obj.id}`;
788
+ if (obj._id !== undefined)
789
+ return `obj_${obj._id}`;
790
+ if (obj.uuid !== undefined)
791
+ return `obj_${obj.uuid}`;
792
+ if (obj._uuid !== undefined)
793
+ return `obj_${obj._uuid}`;
794
+ return `obj_${Math.random().toString(36).substr(2, 9)}`;
795
+ }
796
+ catch {
797
+ return `obj_${Math.random().toString(36).substr(2, 9)}`;
798
+ }
799
+ }
800
+ /**
801
+ * 展开懒加载对象(供调试面板调用)
802
+ */
803
+ expandLazyObject(entityId, componentIndex, propertyPath) {
804
+ try {
805
+ const scene = Core.scene;
806
+ if (!scene)
807
+ return null;
808
+ const entityList = scene.entities;
809
+ if (!entityList?.buffer)
810
+ return null;
811
+ // 找到对应的实体
812
+ const entity = entityList.buffer.find((e) => e.id === entityId);
813
+ if (!entity)
814
+ return null;
815
+ // 找到对应的组件
816
+ if (componentIndex >= entity.components.length)
817
+ return null;
818
+ const component = entity.components[componentIndex];
819
+ // 根据属性路径找到对象
820
+ const targetObject = this.getObjectByPath(component, propertyPath);
821
+ if (!targetObject)
822
+ return null;
823
+ // 展开这个对象的第一层属性
824
+ return this.formatObjectFirstLevel(targetObject);
825
+ }
826
+ catch (error) {
827
+ return {
828
+ error: `展开失败: ${error instanceof Error ? error.message : String(error)}`
829
+ };
830
+ }
831
+ }
832
+ /**
833
+ * 根据路径获取对象
834
+ */
835
+ getObjectByPath(root, path) {
836
+ if (!path)
837
+ return root;
838
+ const parts = path.split('.');
839
+ let current = root;
840
+ for (const part of parts) {
841
+ if (current === null || current === undefined)
842
+ return null;
843
+ // 处理数组索引
844
+ if (part.includes('[') && part.includes(']')) {
845
+ const arrayName = part.substring(0, part.indexOf('['));
846
+ const index = parseInt(part.substring(part.indexOf('[') + 1, part.indexOf(']')));
847
+ if (arrayName) {
848
+ current = current[arrayName];
849
+ }
850
+ if (Array.isArray(current) && index >= 0 && index < current.length) {
851
+ current = current[index];
852
+ }
853
+ else {
854
+ return null;
855
+ }
856
+ }
857
+ else {
858
+ current = current[part];
859
+ }
860
+ }
861
+ return current;
862
+ }
863
+ }
864
+ //# sourceMappingURL=EntityDataCollector.js.map