Files
2nd/10_Wiki/Topics/Domain_Programming/Backend/Unity.md
T
Antigravity Agent c24165b8bc refactor(topics): 멀티 에이전트용 지식 재편 — _Common(공통 기본기) + Domain_* 구조
에이전트 8종(대화형/프로그래머 C·S/디자이너/설계자/기획자/QA/PD/PM)에게
[공통 기본 능력 + 롤별 Specialty] 2층으로 지식을 주입하기 위한 재분류.
문서 내용·포맷은 무수정, 폴더 이동만 (6,372개 문서 수 보존 확인).

- Topic_Programming → Domain_Programming (내부 구조 보존)
- Topic_Graphic → Domain_Design
- Topic_Business → Domain_Product
- Topic_General → Domain_General
- _Common 신설: Math(구 Topic_Math_Specialty), Reasoning(구 General/From_Thinking & Reasoning),
  Reasoning_Creativity(구 General/From_창의성), Communication(Poetic_Blog_Writing + From_writing)
- 타 도메인의 From_* 폴더는 유지 (출처 표기일 뿐, 이미 도메인에 맞게 분류된 문서)
- 빈 폴더 정리 (memory/procedures)
- 에이전트→폴더 매핑은 workspace의 .astra/agent-knowledge-map.json (9개 에이전트)

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-11 11:05:56 +09:00

163 lines
4.9 KiB
Markdown

---
id: wiki-2026-0508-unity
title: Unity
category: 10_Wiki/Topics
status: verified
canonical_id: self
aliases: [Unity Engine, Unity3D, Unity 6]
duplicate_of: none
source_trust_level: A
confidence_score: 0.9
verification_status: applied
tags: [game-engine, c-sharp, realtime, multiplayer, dots]
raw_sources: []
last_reinforced: 2026-05-10
github_commit: pending
tech_stack:
language: C#
framework: Unity 6 (DOTS, Netcode for GameObjects)
---
# Unity
## 매 한 줄
> **"매 cross-platform realtime engine 의 component 기반 scene graph + 매 C# scripting 의 ECS hybrid"**. 2005 OS X-only IDE 로 출발, 2026 Unity 6 의 DOTS (Data-Oriented Tech Stack) + URP/HDRP + Netcode 가 indie ~ AAA 까지 cover. 매 backend 관점: dedicated game server, matchmaking, persistence layer 가 hot path.
## 매 핵심
### 매 GameObject + Component
- `GameObject` = container, `MonoBehaviour` 매 lifecycle hook (`Awake → Start → Update → FixedUpdate → LateUpdate`).
- 매 inheritance 보다 composition 우선 — 매 `RequireComponent` 의 사용.
### 매 ECS / DOTS
- `Entity` (ID) + `IComponentData` (struct) + `SystemBase` (logic). 매 Burst compiler + Job system 의 SIMD/multi-thread.
- 100k+ entities @ 60fps 가 mobile 에서도 가능.
### 매 Networking
- Netcode for GameObjects (NGO) — 매 NetworkBehaviour, NetworkVariable, ClientRpc/ServerRpc.
- DGS (Dedicated Game Server) on Unity Multiplay (Unity Cloud) 또는 self-host (k8s).
### 매 응용
1. 매 mobile/PC/console game (Genshin-style live ops 포함).
2. 매 AR/VR (XR Interaction Toolkit, visionOS).
3. 매 digital twin / BIM 시각화 (non-game enterprise).
## 💻 패턴
### MonoBehaviour 기본
```csharp
using UnityEngine;
public class PlayerController : MonoBehaviour
{
[SerializeField] float speed = 5f;
Rigidbody rb;
void Awake() => rb = GetComponent<Rigidbody>();
void FixedUpdate()
{
var input = new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical"));
rb.MovePosition(rb.position + input * speed * Time.fixedDeltaTime);
}
}
```
### DOTS / ECS System
```csharp
using Unity.Burst;
using Unity.Entities;
using Unity.Mathematics;
using Unity.Transforms;
[BurstCompile]
public partial struct MoveSystem : ISystem
{
public void OnUpdate(ref SystemState state)
{
float dt = SystemAPI.Time.DeltaTime;
foreach (var (transform, vel) in SystemAPI.Query<RefRW<LocalTransform>, RefRO<Velocity>>())
transform.ValueRW.Position += vel.ValueRO.Value * dt;
}
}
```
### Netcode RPC
```csharp
public class PlayerNet : NetworkBehaviour
{
[ServerRpc] public void FireServerRpc(Vector3 dir) {
// server-authoritative damage
SpawnProjectileClientRpc(dir);
}
[ClientRpc] void SpawnProjectileClientRpc(Vector3 dir) { /* visual only */ }
}
```
### Addressables (async asset load)
```csharp
var handle = Addressables.LoadAssetAsync<GameObject>("Boss/FinalBoss");
var prefab = await handle.Task;
Instantiate(prefab, spawnPoint.position, Quaternion.identity);
```
### ScriptableObject (data-driven)
```csharp
[CreateAssetMenu(menuName="Game/WeaponDef")]
public class WeaponDef : ScriptableObject {
public int damage; public float fireRate; public AudioClip sfx;
}
```
### UniTask (struct-based async)
```csharp
async UniTaskVoid LoadScene() {
await SceneManager.LoadSceneAsync("Boss").ToUniTask();
await UniTask.Delay(500);
BossUI.Show();
}
```
### Dedicated Server build
```bash
# Linux server build via CLI
Unity -batchmode -nographics -quit \
-buildTarget LinuxServer \
-executeMethod Builder.BuildServer \
-projectPath . -logFile build.log
```
## 매 결정 기준
| 상황 | Approach |
|---|---|
| Indie 2D/3D, fast iteration | MonoBehaviour + URP |
| 10k+ units (RTS, swarm) | DOTS + Burst |
| Authoritative multiplayer | Netcode + DGS on Multiplay |
| Cross-platform UI tool | UI Toolkit (UXML/USS) |
| 매 cinematic | Timeline + Cinemachine |
**기본값**: MonoBehaviour + URP + Addressables. Scale 한계 도달 시 hot path 만 DOTS 로 migrate.
## 🔗 Graph
## 🤖 LLM 활용
**언제**: boilerplate MonoBehaviour, shader scaffolding, editor tool script, ECS conversion outline.
**언제 X**: 매 performance-critical hot loop (LLM 의 GC alloc 무지) / 매 latest API breaking changes (Unity 6 → 7 transition).
## ❌ 안티패턴
- **Update() everywhere**: 매 frame 의 `GetComponent` / `Find` 호출. Cache in Awake.
- **String-based GameObject.Find**: 매 fragile + slow. Use serialized refs.
- **Coroutine for heavy work**: 매 main thread block. Use Job system or async.
- **Resources/ folder abuse**: 매 build size bloat. Use Addressables.
- **No object pooling**: 매 bullet/particle spam → GC spike. Pool everything reusable.
## 🧪 검증 / 중복
- Verified (Unity 6 docs, Unite 2025 sessions).
- 신뢰도 A.
## 🕓 Changelog
| 날짜 | 변경 |
|---|---|
| 2026-05-08 | Phase 1 |
| 2026-05-10 | Manual cleanup — Unity 6 + DOTS + Netcode 패턴 정리 |