44 lines
1.5 KiB
Markdown
44 lines
1.5 KiB
Markdown
---
|
||
title: "Netcode for GameObjects"
|
||
type: entity
|
||
tags: [unity, networking, framework]
|
||
sources: [unity-multiplayer-engineer]
|
||
last_updated: 2026-04-26
|
||
---
|
||
|
||
## Aliases
|
||
- NGO
|
||
- Netcode for GameObjects (NGO)
|
||
|
||
## Type
|
||
Unity 官方多人游戏网络框架
|
||
|
||
## Definition
|
||
Netcode for GameObjects(NGO)是 Unity 官方提供的多人游戏网络编程框架,提供 `NetworkObject`、`NetworkVariable<T>`、`ServerRpc`、`ClientRpc` 等核心网络原语,简化服务器权威多人游戏开发。
|
||
|
||
## Core Components
|
||
|
||
| 组件 | 类型 | 用途 |
|
||
|------|------|------|
|
||
| `NetworkObject` | 组件 | 挂载到 GameObject 使其可联网 |
|
||
| `NetworkVariable<T>` | 类型 | 持久化状态同步 |
|
||
| `ServerRpc` | 特性 | 客户端调用 → 服务器执行 |
|
||
| `ClientRpc` | 特性 | 服务器调用 → 所有客户端执行 |
|
||
| `NetworkManager` | 组件 | 网络管理器 |
|
||
| `UnityTransport` | 组件 | 底层传输层(支持直连/Relay) |
|
||
|
||
## Key Design Decisions
|
||
- **服务器权威**:所有 NetworkVariable write 权限默认为 Server
|
||
- **自动同步**:NetworkVariable 变化自动同步,无需手动调用
|
||
- **Prefabs 注册**:所有联网 Prefab 必须注册到 NetworkPrefabs 列表
|
||
|
||
## Related Concepts
|
||
- [[ServerAuthority]]: NGO 强制服务器权威
|
||
- [[NetworkVariable]]: 核心数据类型
|
||
- [[UnityRelay]]: 通过 UnityTransport 集成 Relay
|
||
- [[UnityMultiplayerEngineer]]: 使用 NGO 构建游戏的专家
|
||
|
||
## Related Entities
|
||
- [[UnityGamingServices]]: NGO 与 UGS 深度集成
|
||
- [[UnityTransport]]: NGO 的传输层实现
|