@sylix/coworker 2.0.11 → 2.0.14

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 (169) hide show
  1. package/dist/commands/slash/config.d.ts.map +1 -1
  2. package/dist/commands/slash/config.js +22 -4
  3. package/dist/commands/slash/config.js.map +1 -1
  4. package/dist/core/CoWorkerAgent.d.ts.map +1 -1
  5. package/dist/core/CoWorkerAgent.js +6 -3
  6. package/dist/core/CoWorkerAgent.js.map +1 -1
  7. package/dist/skills/defaults/accessibility/screen-reader-testing.md +545 -0
  8. package/dist/skills/defaults/accessibility/wcag-audit-patterns.md +555 -0
  9. package/dist/skills/defaults/ai-ml/rag.md +276 -0
  10. package/dist/skills/defaults/backend-development/api-design-principles.md +528 -0
  11. package/dist/skills/defaults/backend-development/api-design.md +285 -0
  12. package/dist/skills/defaults/backend-development/architecture-patterns.md +494 -0
  13. package/dist/skills/defaults/backend-development/async-python.md +237 -0
  14. package/dist/skills/defaults/backend-development/auth-implementation-patterns.md +638 -0
  15. package/dist/skills/defaults/backend-development/bazel-build-optimization.md +387 -0
  16. package/dist/skills/defaults/backend-development/billing-automation/SKILL.md +566 -0
  17. package/dist/skills/defaults/backend-development/code-review-excellence.md +538 -0
  18. package/dist/skills/defaults/backend-development/cqrs-implementation.md +554 -0
  19. package/dist/skills/defaults/backend-development/database-design.md +305 -0
  20. package/dist/skills/defaults/backend-development/debugging-strategies.md +536 -0
  21. package/dist/skills/defaults/backend-development/e2e-testing-patterns.md +544 -0
  22. package/dist/skills/defaults/backend-development/error-handling-patterns.md +641 -0
  23. package/dist/skills/defaults/backend-development/fastapi-templates.md +559 -0
  24. package/dist/skills/defaults/backend-development/fastapi.md +309 -0
  25. package/dist/skills/defaults/backend-development/git-advanced-workflows.md +405 -0
  26. package/dist/skills/defaults/backend-development/microservices-patterns.md +595 -0
  27. package/dist/skills/defaults/backend-development/microservices.md +284 -0
  28. package/dist/skills/defaults/backend-development/monorepo-management.md +623 -0
  29. package/dist/skills/defaults/backend-development/nodejs-backend-patterns.md +1048 -0
  30. package/dist/skills/defaults/backend-development/nx-workspace-patterns.md +457 -0
  31. package/dist/skills/defaults/backend-development/paypal-integration/SKILL.md +478 -0
  32. package/dist/skills/defaults/backend-development/pci-compliance/SKILL.md +480 -0
  33. package/dist/skills/defaults/backend-development/python-anti-patterns.md +349 -0
  34. package/dist/skills/defaults/backend-development/python-background-jobs.md +364 -0
  35. package/dist/skills/defaults/backend-development/python-code-style.md +360 -0
  36. package/dist/skills/defaults/backend-development/python-configuration.md +368 -0
  37. package/dist/skills/defaults/backend-development/python-design-patterns.md +296 -0
  38. package/dist/skills/defaults/backend-development/python-error-handling.md +323 -0
  39. package/dist/skills/defaults/backend-development/python-packaging.md +887 -0
  40. package/dist/skills/defaults/backend-development/python-performance-optimization.md +874 -0
  41. package/dist/skills/defaults/backend-development/python-project-structure.md +252 -0
  42. package/dist/skills/defaults/backend-development/python-resilience.md +376 -0
  43. package/dist/skills/defaults/backend-development/python-resource-management.md +421 -0
  44. package/dist/skills/defaults/backend-development/python-type-safety.md +428 -0
  45. package/dist/skills/defaults/backend-development/sql-optimization-patterns.md +509 -0
  46. package/dist/skills/defaults/backend-development/stripe-integration/SKILL.md +522 -0
  47. package/dist/skills/defaults/backend-development/turborepo-caching.md +376 -0
  48. package/dist/skills/defaults/blockchain/defi-protocol-templates.md +430 -0
  49. package/dist/skills/defaults/blockchain/nft-standards.md +364 -0
  50. package/dist/skills/defaults/blockchain/solidity-security.md +514 -0
  51. package/dist/skills/defaults/blockchain/web3-testing.md +360 -0
  52. package/dist/skills/defaults/business/competitive-landscape/SKILL.md +527 -0
  53. package/dist/skills/defaults/business/market-sizing-analysis/SKILL.md +451 -0
  54. package/dist/skills/defaults/business/startup-financial-modeling/SKILL.md +494 -0
  55. package/dist/skills/defaults/business/startup-metrics-framework/SKILL.md +564 -0
  56. package/dist/skills/defaults/business/team-composition-analysis.md +437 -0
  57. package/dist/skills/defaults/compliance/employment-contract-templates/SKILL.md +527 -0
  58. package/dist/skills/defaults/compliance/gdpr-data-handling/SKILL.md +630 -0
  59. package/dist/skills/defaults/data-engineering/airflow-dag-patterns.md +436 -0
  60. package/dist/skills/defaults/data-engineering/airflow.md +519 -0
  61. package/dist/skills/defaults/data-engineering/data-quality.md +583 -0
  62. package/dist/skills/defaults/data-engineering/dbt-transformation-patterns.md +482 -0
  63. package/dist/skills/defaults/data-engineering/dbt.md +556 -0
  64. package/dist/skills/defaults/data-engineering/ml-pipeline-workflow/SKILL.md +247 -0
  65. package/dist/skills/defaults/data-engineering/spark-optimization.md +348 -0
  66. package/dist/skills/defaults/data-engineering/spark.md +411 -0
  67. package/dist/skills/defaults/database/postgresql.md +202 -0
  68. package/dist/skills/defaults/debugging/systematic-debugging.md +249 -0
  69. package/dist/skills/defaults/devops/architecture-decision-records.md +448 -0
  70. package/dist/skills/defaults/devops/changelog-automation.md +580 -0
  71. package/dist/skills/defaults/devops/cicd.md +314 -0
  72. package/dist/skills/defaults/devops/cloud.md +263 -0
  73. package/dist/skills/defaults/devops/code-review-excellence.md +299 -0
  74. package/dist/skills/defaults/devops/cost-optimization.md +295 -0
  75. package/dist/skills/defaults/devops/deployment-pipeline-design.md +356 -0
  76. package/dist/skills/defaults/devops/docker.md +281 -0
  77. package/dist/skills/defaults/devops/git-workflows.md +205 -0
  78. package/dist/skills/defaults/devops/github-actions.md +311 -0
  79. package/dist/skills/defaults/devops/gitlab-ci-patterns.md +266 -0
  80. package/dist/skills/defaults/devops/hybrid-cloud-networking.md +241 -0
  81. package/dist/skills/defaults/devops/istio-traffic-management.md +327 -0
  82. package/dist/skills/defaults/devops/kubernetes.md +339 -0
  83. package/dist/skills/defaults/devops/linkerd-patterns.md +311 -0
  84. package/dist/skills/defaults/devops/multi-cloud-architecture.md +181 -0
  85. package/dist/skills/defaults/devops/observability.md +243 -0
  86. package/dist/skills/defaults/devops/openapi-spec-generation.md +1024 -0
  87. package/dist/skills/defaults/devops/postmortem-writing.md +396 -0
  88. package/dist/skills/defaults/devops/prometheus-configuration.md +265 -0
  89. package/dist/skills/defaults/devops/secrets-management.md +341 -0
  90. package/dist/skills/defaults/devops/service-mesh-observability.md +385 -0
  91. package/dist/skills/defaults/devops/terraform-module-library.md +244 -0
  92. package/dist/skills/defaults/finance/backtesting-frameworks/SKILL.md +663 -0
  93. package/dist/skills/defaults/finance/risk-metrics-calculation/SKILL.md +557 -0
  94. package/dist/skills/defaults/frontend/accessibility-compliance.md +420 -0
  95. package/dist/skills/defaults/frontend/design-system-patterns.md +337 -0
  96. package/dist/skills/defaults/frontend/interaction-design.md +327 -0
  97. package/dist/skills/defaults/frontend/javascript.md +311 -0
  98. package/dist/skills/defaults/frontend/modern-javascript-patterns.md +927 -0
  99. package/dist/skills/defaults/frontend/react-native-design.md +440 -0
  100. package/dist/skills/defaults/frontend/react.md +345 -0
  101. package/dist/skills/defaults/frontend/responsive-design.md +472 -0
  102. package/dist/skills/defaults/frontend/tailwind-design-system.md +337 -0
  103. package/dist/skills/defaults/frontend/typescript-advanced-types.md +724 -0
  104. package/dist/skills/defaults/frontend/typescript.md +334 -0
  105. package/dist/skills/defaults/frontend/visual-design-foundations.md +326 -0
  106. package/dist/skills/defaults/frontend/web-component-design.md +279 -0
  107. package/dist/skills/defaults/game-development/godot-gdscript-patterns.md +188 -0
  108. package/dist/skills/defaults/game-development/unity-ecs-patterns.md +594 -0
  109. package/dist/skills/defaults/kubernetes/gitops-workflow.md +285 -0
  110. package/dist/skills/defaults/kubernetes/gitops.md +280 -0
  111. package/dist/skills/defaults/kubernetes/helm-chart-scaffolding.md +553 -0
  112. package/dist/skills/defaults/kubernetes/helm.md +343 -0
  113. package/dist/skills/defaults/kubernetes/k8s-manifest-generator.md +501 -0
  114. package/dist/skills/defaults/kubernetes/k8s-security-policies.md +342 -0
  115. package/dist/skills/defaults/kubernetes/manifests.md +330 -0
  116. package/dist/skills/defaults/kubernetes/security.md +337 -0
  117. package/dist/skills/defaults/llm-application/embedding-strategies.md +608 -0
  118. package/dist/skills/defaults/llm-application/hybrid-search-implementation.md +570 -0
  119. package/dist/skills/defaults/llm-application/hybrid-search.md +570 -0
  120. package/dist/skills/defaults/llm-application/langchain-architecture.md +666 -0
  121. package/dist/skills/defaults/llm-application/langchain.md +259 -0
  122. package/dist/skills/defaults/llm-application/llm-evaluation.md +695 -0
  123. package/dist/skills/defaults/llm-application/prompt-engineering-patterns.md +449 -0
  124. package/dist/skills/defaults/llm-application/prompt-engineering.md +219 -0
  125. package/dist/skills/defaults/llm-application/rag-implementation.md +434 -0
  126. package/dist/skills/defaults/llm-application/similarity-search-patterns.md +560 -0
  127. package/dist/skills/defaults/llm-application/similarity-search.md +560 -0
  128. package/dist/skills/defaults/llm-application/vector-index-tuning.md +523 -0
  129. package/dist/skills/defaults/mobile/mobile-android-design.md +440 -0
  130. package/dist/skills/defaults/mobile/mobile-ios-design.md +266 -0
  131. package/dist/skills/defaults/monitoring/distributed-tracing.md +436 -0
  132. package/dist/skills/defaults/monitoring/grafana-dashboards.md +370 -0
  133. package/dist/skills/defaults/monitoring/prometheus-configuration.md +379 -0
  134. package/dist/skills/defaults/monitoring/slo-implementation.md +323 -0
  135. package/dist/skills/defaults/refactoring/code-refactoring.md +349 -0
  136. package/dist/skills/defaults/security/anti-reversing-techniques/SKILL.md +559 -0
  137. package/dist/skills/defaults/security/auditor.md +168 -0
  138. package/dist/skills/defaults/security/binary-analysis-patterns/SKILL.md +438 -0
  139. package/dist/skills/defaults/security/memory-forensics/SKILL.md +483 -0
  140. package/dist/skills/defaults/security/mtls-configuration.md +349 -0
  141. package/dist/skills/defaults/security/protocol-reverse-engineering/SKILL.md +520 -0
  142. package/dist/skills/defaults/security/sast-configuration.md +182 -0
  143. package/dist/skills/defaults/security/security.md +313 -0
  144. package/dist/skills/defaults/security/stride-analysis.md +273 -0
  145. package/dist/skills/defaults/security/threat-mitigation-mapping.md +290 -0
  146. package/dist/skills/defaults/systems/bash-defensive-patterns/SKILL.md +539 -0
  147. package/dist/skills/defaults/systems/bats-testing-patterns/SKILL.md +631 -0
  148. package/dist/skills/defaults/systems/go-concurrency-patterns.md +657 -0
  149. package/dist/skills/defaults/systems/memory-safety-patterns.md +605 -0
  150. package/dist/skills/defaults/systems/rust-async-patterns.md +519 -0
  151. package/dist/skills/defaults/systems/shellcheck-configuration/SKILL.md +456 -0
  152. package/dist/skills/defaults/team-collaboration/multi-reviewer-patterns.md +126 -0
  153. package/dist/skills/defaults/team-collaboration/parallel-feature-development.md +151 -0
  154. package/dist/skills/defaults/testing/javascript-testing-patterns.md +1021 -0
  155. package/dist/skills/defaults/testing/python-testing-patterns.md +351 -0
  156. package/dist/skills/defaults/testing/testing.md +332 -0
  157. package/dist/skills/defaults/workflows/context-driven-development.md +384 -0
  158. package/dist/skills/defaults/workflows/track-management.md +592 -0
  159. package/dist/skills/defaults/workflows/workflow-patterns.md +622 -0
  160. package/dist/skills/index.d.ts +11 -0
  161. package/dist/skills/index.d.ts.map +1 -0
  162. package/dist/skills/index.js +129 -0
  163. package/dist/skills/index.js.map +1 -0
  164. package/dist/utils/character.js +4 -4
  165. package/dist/utils/character.js.map +1 -1
  166. package/dist/utils/inputbar.d.ts.map +1 -1
  167. package/dist/utils/inputbar.js +7 -0
  168. package/dist/utils/inputbar.js.map +1 -1
  169. package/package.json +1 -1
@@ -0,0 +1,594 @@
1
+ ---
2
+ name: unity-ecs-patterns
3
+ description: Master Unity ECS (Entity Component System) with DOTS, Jobs, and Burst for high-performance game development
4
+ ---
5
+
6
+ # Unity ECS Patterns
7
+
8
+ Production patterns for Unity's Data-Oriented Technology Stack (DOTS) including Entity Component System, Job System, and Burst Compiler.
9
+
10
+ ## When to Use This Skill
11
+
12
+ - Building high-performance Unity games
13
+ - Managing thousands of entities efficiently
14
+ - Implementing data-oriented game systems
15
+ - Optimizing CPU-bound game logic
16
+ - Converting OOP game code to ECS
17
+ - Using Jobs and Burst for parallelization
18
+
19
+ ## Core Concepts
20
+
21
+ ### ECS vs OOP
22
+
23
+ | Aspect | Traditional OOP | ECS/DOTS |
24
+ | ----------- | ----------------- | --------------- |
25
+ | Data layout | Object-oriented | Data-oriented |
26
+ | Memory | Scattered | Contiguous |
27
+ | Processing | Per-object | Batched |
28
+ | Scaling | Poor with count | Linear scaling |
29
+ | Best for | Complex behaviors | Mass simulation |
30
+
31
+ ### DOTS Components
32
+
33
+ ```
34
+ Entity: Lightweight ID (no data)
35
+ Component: Pure data (no behavior)
36
+ System: Logic that processes components
37
+ World: Container for entities
38
+ Archetype: Unique combination of components
39
+ Chunk: Memory block for same-archetype entities
40
+ ```
41
+
42
+ ## Patterns
43
+
44
+ ### Pattern 1: Basic ECS Setup
45
+
46
+ ```csharp
47
+ using Unity.Entities;
48
+ using Unity.Mathematics;
49
+ using Unity.Transforms;
50
+ using Unity.Burst;
51
+ using Unity.Collections;
52
+
53
+ // Component: Pure data, no methods
54
+ public struct Speed : IComponentData
55
+ {
56
+ public float Value;
57
+ }
58
+
59
+ public struct Health : IComponentData
60
+ {
61
+ public float Current;
62
+ public float Max;
63
+ }
64
+
65
+ public struct Target : IComponentData
66
+ {
67
+ public Entity Value;
68
+ }
69
+
70
+ // Tag component (zero-size marker)
71
+ public struct EnemyTag : IComponentData { }
72
+ public struct PlayerTag : IComponentData { }
73
+
74
+ // Buffer component (variable-size array)
75
+ [InternalBufferCapacity(8)]
76
+ public struct InventoryItem : IBufferElementData
77
+ {
78
+ public int ItemId;
79
+ public int Quantity;
80
+ }
81
+
82
+ // Shared component (grouped entities)
83
+ public struct TeamId : ISharedComponentData
84
+ {
85
+ public int Value;
86
+ }
87
+ ```
88
+
89
+ ### Pattern 2: Systems with ISystem (Recommended)
90
+
91
+ ```csharp
92
+ using Unity.Entities;
93
+ using Unity.Transforms;
94
+ using Unity.Mathematics;
95
+ using Unity.Burst;
96
+
97
+ // ISystem: Unmanaged, Burst-compatible, highest performance
98
+ [BurstCompile]
99
+ public partial struct MovementSystem : ISystem
100
+ {
101
+ [BurstCompile]
102
+ public void OnCreate(ref SystemState state)
103
+ {
104
+ state.RequireForUpdate<Speed>();
105
+ }
106
+
107
+ [BurstCompile]
108
+ public void OnUpdate(ref SystemState state)
109
+ {
110
+ float deltaTime = SystemAPI.Time.DeltaTime;
111
+
112
+ foreach (var (transform, speed) in
113
+ SystemAPI.Query<RefRW<LocalTransform>, RefRO<Speed>>())
114
+ {
115
+ transform.ValueRW.Position +=
116
+ new float3(0, 0, speed.ValueRO.Value * deltaTime);
117
+ }
118
+ }
119
+
120
+ [BurstCompile]
121
+ public void OnDestroy(ref SystemState state) { }
122
+ }
123
+
124
+ // With explicit job for more control
125
+ [BurstCompile]
126
+ public partial struct MovementJobSystem : ISystem
127
+ {
128
+ [BurstCompile]
129
+ public void OnUpdate(ref SystemState state)
130
+ {
131
+ var job = new MoveJob
132
+ {
133
+ DeltaTime = SystemAPI.Time.DeltaTime
134
+ };
135
+
136
+ state.Dependency = job.ScheduleParallel(state.Dependency);
137
+ }
138
+ }
139
+
140
+ [BurstCompile]
141
+ public partial struct MoveJob : IJobEntity
142
+ {
143
+ public float DeltaTime;
144
+
145
+ void Execute(ref LocalTransform transform, in Speed speed)
146
+ {
147
+ transform.Position += new float3(0, 0, speed.Value * DeltaTime);
148
+ }
149
+ }
150
+ ```
151
+
152
+ ### Pattern 3: Entity Queries
153
+
154
+ ```csharp
155
+ [BurstCompile]
156
+ public partial struct QueryExamplesSystem : ISystem
157
+ {
158
+ private EntityQuery _enemyQuery;
159
+
160
+ public void OnCreate(ref SystemState state)
161
+ {
162
+ _enemyQuery = new EntityQueryBuilder(Allocator.Temp)
163
+ .WithAll<EnemyTag, Health, LocalTransform>()
164
+ .WithNone<Dead>()
165
+ .WithOptions(EntityQueryOptions.FilterWriteGroup)
166
+ .Build(ref state);
167
+ }
168
+
169
+ [BurstCompile]
170
+ public void OnUpdate(ref SystemState state)
171
+ {
172
+ foreach (var (health, entity) in
173
+ SystemAPI.Query<RefRW<Health>>()
174
+ .WithAll<EnemyTag>()
175
+ .WithEntityAccess())
176
+ {
177
+ if (health.ValueRO.Current <= 0)
178
+ {
179
+ SystemAPI.GetSingleton<EndSimulationEntityCommandBufferSystem.Singleton>()
180
+ .CreateCommandBuffer(state.WorldUnmanaged)
181
+ .DestroyEntity(entity);
182
+ }
183
+ }
184
+
185
+ int enemyCount = _enemyQuery.CalculateEntityCount();
186
+ var enemies = _enemyQuery.ToEntityArray(Allocator.Temp);
187
+ var healths = _enemyQuery.ToComponentDataArray<Health>(Allocator.Temp);
188
+ }
189
+ }
190
+ ```
191
+
192
+ ### Pattern 4: Entity Command Buffers (Structural Changes)
193
+
194
+ ```csharp
195
+ [BurstCompile]
196
+ [UpdateInGroup(typeof(SimulationSystemGroup))]
197
+ public partial struct SpawnSystem : ISystem
198
+ {
199
+ [BurstCompile]
200
+ public void OnUpdate(ref SystemState state)
201
+ {
202
+ var ecbSingleton = SystemAPI.GetSingleton<BeginSimulationEntityCommandBufferSystem.Singleton>();
203
+ var ecb = ecbSingleton.CreateCommandBuffer(state.WorldUnmanaged);
204
+
205
+ foreach (var (spawner, transform) in
206
+ SystemAPI.Query<RefRW<Spawner>, RefRO<LocalTransform>>())
207
+ {
208
+ spawner.ValueRW.Timer -= SystemAPI.Time.DeltaTime;
209
+
210
+ if (spawner.ValueRO.Timer <= 0)
211
+ {
212
+ spawner.ValueRW.Timer = spawner.ValueRO.Interval;
213
+
214
+ Entity newEntity = ecb.Instantiate(spawner.ValueRO.Prefab);
215
+
216
+ ecb.SetComponent(newEntity, new LocalTransform
217
+ {
218
+ Position = transform.ValueRO.Position,
219
+ Rotation = quaternion.identity,
220
+ Scale = 1f
221
+ });
222
+
223
+ ecb.AddComponent(newEntity, new Speed { Value = 5f });
224
+ }
225
+ }
226
+ }
227
+ }
228
+
229
+ // Parallel ECB usage
230
+ [BurstCompile]
231
+ public partial struct ParallelSpawnJob : IJobEntity
232
+ {
233
+ public EntityCommandBuffer.ParallelWriter ECB;
234
+
235
+ void Execute([EntityIndexInQuery] int index, in Spawner spawner)
236
+ {
237
+ Entity e = ECB.Instantiate(index, spawner.Prefab);
238
+ ECB.AddComponent(index, e, new Speed { Value = 5f });
239
+ }
240
+ }
241
+ ```
242
+
243
+ ### Pattern 5: Aspect (Grouping Components)
244
+
245
+ ```csharp
246
+ using Unity.Entities;
247
+ using Unity.Transforms;
248
+ using Unity.Mathematics;
249
+
250
+ public readonly partial struct CharacterAspect : IAspect
251
+ {
252
+ public readonly Entity Entity;
253
+
254
+ private readonly RefRW<LocalTransform> _transform;
255
+ private readonly RefRO<Speed> _speed;
256
+ private readonly RefRW<Health> _health;
257
+
258
+ [Optional]
259
+ private readonly RefRO<Shield> _shield;
260
+
261
+ private readonly DynamicBuffer<InventoryItem> _inventory;
262
+
263
+ public float3 Position
264
+ {
265
+ get => _transform.ValueRO.Position;
266
+ set => _transform.ValueRW.Position = value;
267
+ }
268
+
269
+ public float CurrentHealth => _health.ValueRO.Current;
270
+ public float MaxHealth => _health.ValueRO.Max;
271
+ public float MoveSpeed => _speed.ValueRO.Value;
272
+
273
+ public bool HasShield => _shield.IsValid;
274
+ public float ShieldAmount => HasShield ? _shield.ValueRO.Amount : 0f;
275
+
276
+ public void TakeDamage(float amount)
277
+ {
278
+ float remaining = amount;
279
+
280
+ if (HasShield && _shield.ValueRO.Amount > 0)
281
+ {
282
+ remaining = math.max(0, amount - _shield.ValueRO.Amount);
283
+ }
284
+
285
+ _health.ValueRW.Current = math.max(0, _health.ValueRO.Current - remaining);
286
+ }
287
+
288
+ public void Move(float3 direction, float deltaTime)
289
+ {
290
+ _transform.ValueRW.Position += direction * _speed.ValueRO.Value * deltaTime;
291
+ }
292
+
293
+ public void AddItem(int itemId, int quantity)
294
+ {
295
+ _inventory.Add(new InventoryItem { ItemId = itemId, Quantity = quantity });
296
+ }
297
+ }
298
+
299
+ [BurstCompile]
300
+ public partial struct CharacterSystem : ISystem
301
+ {
302
+ [BurstCompile]
303
+ public void OnUpdate(ref SystemState state)
304
+ {
305
+ float dt = SystemAPI.Time.DeltaTime;
306
+
307
+ foreach (var character in SystemAPI.Query<CharacterAspect>())
308
+ {
309
+ character.Move(new float3(1, 0, 0), dt);
310
+
311
+ if (character.CurrentHealth < character.MaxHealth * 0.5f)
312
+ {
313
+ // Low health logic
314
+ }
315
+ }
316
+ }
317
+ }
318
+ ```
319
+
320
+ ### Pattern 6: Singleton Components
321
+
322
+ ```csharp
323
+ public struct GameConfig : IComponentData
324
+ {
325
+ public float DifficultyMultiplier;
326
+ public int MaxEnemies;
327
+ public float SpawnRate;
328
+ }
329
+
330
+ public struct GameState : IComponentData
331
+ {
332
+ public int Score;
333
+ public int Wave;
334
+ public float TimeRemaining;
335
+ }
336
+
337
+ public partial struct GameInitSystem : ISystem
338
+ {
339
+ public void OnCreate(ref SystemState state)
340
+ {
341
+ var entity = state.EntityManager.CreateEntity();
342
+ state.EntityManager.AddComponentData(entity, new GameConfig
343
+ {
344
+ DifficultyMultiplier = 1.0f,
345
+ MaxEnemies = 100,
346
+ SpawnRate = 2.0f
347
+ });
348
+ state.EntityManager.AddComponentData(entity, new GameState
349
+ {
350
+ Score = 0,
351
+ Wave = 1,
352
+ TimeRemaining = 120f
353
+ });
354
+ }
355
+ }
356
+
357
+ [BurstCompile]
358
+ public partial struct ScoreSystem : ISystem
359
+ {
360
+ [BurstCompile]
361
+ public void OnUpdate(ref SystemState state)
362
+ {
363
+ var config = SystemAPI.GetSingleton<GameConfig>();
364
+
365
+ ref var gameState = ref SystemAPI.GetSingletonRW<GameState>().ValueRW;
366
+ gameState.TimeRemaining -= SystemAPI.Time.DeltaTime;
367
+
368
+ if (SystemAPI.HasSingleton<GameConfig>())
369
+ {
370
+ // ...
371
+ }
372
+ }
373
+ }
374
+ ```
375
+
376
+ ### Pattern 7: Baking (Converting GameObjects)
377
+
378
+ ```csharp
379
+ using Unity.Entities;
380
+ using UnityEngine;
381
+
382
+ public class EnemyAuthoring : MonoBehaviour
383
+ {
384
+ public float Speed = 5f;
385
+ public float Health = 100f;
386
+ public GameObject ProjectilePrefab;
387
+
388
+ class Baker : Baker<EnemyAuthoring>
389
+ {
390
+ public override void Bake(EnemyAuthoring authoring)
391
+ {
392
+ var entity = GetEntity(TransformUsageFlags.Dynamic);
393
+
394
+ AddComponent(entity, new Speed { Value = authoring.Speed });
395
+ AddComponent(entity, new Health
396
+ {
397
+ Current = authoring.Health,
398
+ Max = authoring.Health
399
+ });
400
+ AddComponent(entity, new EnemyTag());
401
+
402
+ if (authoring.ProjectilePrefab != null)
403
+ {
404
+ AddComponent(entity, new ProjectilePrefab
405
+ {
406
+ Value = GetEntity(authoring.ProjectilePrefab, TransformUsageFlags.Dynamic)
407
+ });
408
+ }
409
+ }
410
+ }
411
+ }
412
+
413
+ public class SpawnerAuthoring : MonoBehaviour
414
+ {
415
+ public GameObject[] Prefabs;
416
+ public float Interval = 1f;
417
+
418
+ class Baker : Baker<SpawnerAuthoring>
419
+ {
420
+ public override void Bake(SpawnerAuthoring authoring)
421
+ {
422
+ var entity = GetEntity(TransformUsageFlags.Dynamic);
423
+
424
+ AddComponent(entity, new Spawner
425
+ {
426
+ Interval = authoring.Interval,
427
+ Timer = 0f
428
+ });
429
+
430
+ var buffer = AddBuffer<SpawnPrefabElement>(entity);
431
+ foreach (var prefab in authoring.Prefabs)
432
+ {
433
+ buffer.Add(new SpawnPrefabElement
434
+ {
435
+ Prefab = GetEntity(prefab, TransformUsageFlags.Dynamic)
436
+ });
437
+ }
438
+
439
+ DependsOn(authoring.Prefabs);
440
+ }
441
+ }
442
+ }
443
+ ```
444
+
445
+ ### Pattern 8: Jobs with Native Collections
446
+
447
+ ```csharp
448
+ using Unity.Jobs;
449
+ using Unity.Collections;
450
+ using Unity.Burst;
451
+ using Unity.Mathematics;
452
+
453
+ [BurstCompile]
454
+ public struct SpatialHashJob : IJobParallelFor
455
+ {
456
+ [ReadOnly]
457
+ public NativeArray<float3> Positions;
458
+
459
+ public NativeParallelMultiHashMap<int, int>.ParallelWriter HashMap;
460
+
461
+ public float CellSize;
462
+
463
+ public void Execute(int index)
464
+ {
465
+ float3 pos = Positions[index];
466
+ int hash = GetHash(pos);
467
+ HashMap.Add(hash, index);
468
+ }
469
+
470
+ int GetHash(float3 pos)
471
+ {
472
+ int x = (int)math.floor(pos.x / CellSize);
473
+ int y = (int)math.floor(pos.y / CellSize);
474
+ int z = (int)math.floor(pos.z / CellSize);
475
+ return x * 73856093 ^ y * 19349663 ^ z * 83492791;
476
+ }
477
+ }
478
+
479
+ [BurstCompile]
480
+ public partial struct SpatialHashSystem : ISystem
481
+ {
482
+ private NativeParallelMultiHashMap<int, int> _hashMap;
483
+
484
+ public void OnCreate(ref SystemState state)
485
+ {
486
+ _hashMap = new NativeParallelMultiHashMap<int, int>(10000, Allocator.Persistent);
487
+ }
488
+
489
+ public void OnDestroy(ref SystemState state)
490
+ {
491
+ _hashMap.Dispose();
492
+ }
493
+
494
+ [BurstCompile]
495
+ public void OnUpdate(ref SystemState state)
496
+ {
497
+ var query = SystemAPI.QueryBuilder()
498
+ .WithAll<LocalTransform>()
499
+ .Build();
500
+
501
+ int count = query.CalculateEntityCount();
502
+
503
+ if (_hashMap.Capacity < count)
504
+ {
505
+ _hashMap.Capacity = count * 2;
506
+ }
507
+
508
+ _hashMap.Clear();
509
+
510
+ var positions = query.ToComponentDataArray<LocalTransform>(Allocator.TempJob);
511
+ var posFloat3 = new NativeArray<float3>(count, Allocator.TempJob);
512
+
513
+ for (int i = 0; i < count; i++)
514
+ {
515
+ posFloat3[i] = positions[i].Position;
516
+ }
517
+
518
+ var hashJob = new SpatialHashJob
519
+ {
520
+ Positions = posFloat3,
521
+ HashMap = _hashMap.AsParallelWriter(),
522
+ CellSize = 10f
523
+ };
524
+
525
+ state.Dependency = hashJob.Schedule(count, 64, state.Dependency);
526
+
527
+ positions.Dispose(state.Dependency);
528
+ posFloat3.Dispose(state.Dependency);
529
+ }
530
+ }
531
+ ```
532
+
533
+ ## Performance Tips
534
+
535
+ ```csharp
536
+ // 1. Use Burst everywhere
537
+ [BurstCompile]
538
+ public partial struct MySystem : ISystem { }
539
+
540
+ // 2. Prefer IJobEntity over manual iteration
541
+ [BurstCompile]
542
+ partial struct OptimizedJob : IJobEntity
543
+ {
544
+ void Execute(ref LocalTransform transform) { }
545
+ }
546
+
547
+ // 3. Schedule parallel when possible
548
+ state.Dependency = job.ScheduleParallel(state.Dependency);
549
+
550
+ // 4. Use ScheduleParallel with chunk iteration
551
+ [BurstCompile]
552
+ partial struct ChunkJob : IJobChunk
553
+ {
554
+ public ComponentTypeHandle<Health> HealthHandle;
555
+
556
+ public void Execute(in ArchetypeChunk chunk, int unfilteredChunkIndex,
557
+ bool useEnabledMask, in v128 chunkEnabledMask)
558
+ {
559
+ var healths = chunk.GetNativeArray(ref HealthHandle);
560
+ for (int i = 0; i < chunk.Count; i++)
561
+ {
562
+ // Process
563
+ }
564
+ }
565
+ }
566
+
567
+ // 5. Avoid structural changes in hot paths
568
+ // Use enableable components instead of add/remove
569
+ public struct Disabled : IComponentData, IEnableableComponent { }
570
+ ```
571
+
572
+ ## Best Practices
573
+
574
+ ### Do's
575
+
576
+ - **Use ISystem over SystemBase** - Better performance
577
+ - **Burst compile everything** - Massive speedup
578
+ - **Batch structural changes** - Use ECB
579
+ - **Profile with Profiler** - Identify bottlenecks
580
+ - **Use Aspects** - Clean component grouping
581
+
582
+ ### Don'ts
583
+
584
+ - **Don't use managed types** - Breaks Burst
585
+ - **Don't structural change in jobs** - Use ECB
586
+ - **Don't over-architect** - Start simple
587
+ - **Don't ignore chunk utilization** - Group similar entities
588
+ - **Don't forget disposal** - Native collections leak
589
+
590
+ ## Resources
591
+
592
+ - [Unity DOTS Documentation](https://docs.unity3d.com/Packages/com.unity.entities@latest)
593
+ - [Unity DOTS Samples](https://github.com/Unity-Technologies/EntityComponentSystemSamples)
594
+ - [Burst User Guide](https://docs.unity3d.com/Packages/com.unity.burst@latest)