NetworkRunner - cheona-thousand-man/Unity-myBasics-Wiki GitHub Wiki
๊ฐ์
- Fusion Network์์ Peer(or Client)๋ฅผ ๋ํ๋ด๋ Unity ์ปดํฌ๋ํธ
- ํต์ ํญ๋ชฉ messasing, matchmaking, connecting, spawning, simulation, state replication
- ํ๋์ Unity ์ธ์คํด์ค์์ ์ฌ๋ฌ ๊ฐ์ NetworkRunner ์ธ์คํด์ค ์คํ ๊ฐ๋ฅ
์ฌ์ฉ๋ฒ
1. ์์ฑ
- ๋ฐํ์ ์ Prefab์์ ์ธ์คํด์คํ
- ์ฌ ์ค๋ธ์ ํธ๋ก ๋ก๋
- ๋ฐํ์ ์ ๊ฒ์ ์ค๋ธ์ ํธ์ NetworkRunner ์ปดํฌ๋ํธ ๋์ ์ผ๋ก ์ถ๊ฐ
2. ์์ ๋ฐ ์ฐ๊ฒฐ
ํ ๋ฒ ์์ฑ๋ NetworkRunner ์ธ์คํด์ค๋ matchmaking์ ์ฐ๊ฒฐ or ๋ฐฉ(๋ฃธ) ์์ฑ/์ฐธ๊ฐ ๊ฐ๋ฅ
3. ๋ฐฉ(๋ฃธ) ์์ฑ ๋๋ ์ฐธ๊ฐ
- StartGame(StartGameArgs args) ํธ์ถ ์ args์ ๋ฐ๋ผ, Peer๊ฐ ๋ฐฉ ์์ฑํ๊ฑฐ๋ ์ฐธ๊ฐ(์ฑ๊ธ ํ๋ ์ด์ด ๋ชจ๋์์๋ X)
- ์ฐธ๊ณ
- ๋คํธ์ํฌ์ ์ฐ๊ฒฐ๋ Peer๋ ํ๋์ NetworkRunner ์ธ์คํด์ค ์ฌ์ฉ
- ๊ฒ์ ์ธ์ ์์ ์ฐ๊ฒฐ ํด์ or ์ฐ๊ฒฐ ์คํจ ์ ํด๋น NetworkRunner๋ ํ๊ดด ํ์
- ์๋ก์ด ๊ฒ์ ์ธ์ ์ ์์ํ๊ธฐ ์ํด ์๋ก์ด NetworkRunner ์ธ์คํด์ค ์์ฑ
์ฃผ์ ํ๋กํผํฐ/๋ฉ์๋
1. ํ๋กํผํฐ
- Config[get] Returns the NetworkProjectConfig reference.
- Instances[get] A list of all NetworkRunners.
- DeltaTime[get] Returns the fixed tick time interval. Derived from the SimulationConfig.TickRate.
- IsClient[get] / IsServer[get] / IsPlayer[get] / IsSinglePlayer[get] / IsSharedModeMasterClient[get]
- IsRunning[get] Returns if this Fusion.Simulation is valid and running.
- LocalPlayer[get] Returns a PlayerRef for the local simulation. For a dedicated server PlayerRef.IsValid will equal false. PlayerRefs are assigned in order from 0 to MaxPlayers-1 and are re-used as players join and leave. The only caveat is that the server player (if one exists), always gets the last index no matter how many clients are connected.
- Tick[get] The tick associated with the current state of networked objects, or the current simulation tick being processed (when evaluated during FixedUpdateNetwork).
- State[get] The current state of the runner, if it's Starting, Running, Shutdown.
- DeltaTime[get] Returns the fixed tick time interval. Derived from the SimulationConfig.TickRate.
2. ๋ฉ์๋
- Despawn (NetworkObject networkObject, bool allowPredicted=false) Destroys a NetworkObject.
- Disconnect (PlayerRef player) Disconnect a player from the server.
- Exists (NetworkId id) Returns if the Fusion.Simulation contains a NetworkObject with given id in the current State SimulationSnapshot.
- Exists (NetworkObject obj) Returns if the Fusion.Simulation contains a reference to a NetworkObject in the current State SimulationSnapshot.
- FindObject (NetworkId oref) Get the NetworkObject instance for this NetworkRunner from a NetworkId.
- GetPlayerObject (PlayerRef player) Gets the network object associated with a specific player.
- GetPlayerUserId (PlayerRef player=default) Gets Player's UserID.
- HasAnyActiveConnections ()
- IsPlayerActive (PlayerRef player) / IsPlayerValid (PlayerRef player)
- SendRpc (SimulationMessage message {, out RpcSendResult info}) Sends RPC message. Not meant to be used directly, ILWeaver calls this.
- SetPlayerObject (PlayerRef player, NetworkObject networkObject) Sets the network object associated with this player.
- Shutdown (bool destroyGameObject=true, ShutdownReason shutdownReason=ShutdownReason.Ok, bool forceShutdownProcedure=false)
- Spawn (GameObject prefab, Vector3? position=null, Quaternion? rotation=null, PlayerRef? inputAuthority=null, OnBeforeSpawned onBeforeSpawned=null, NetworkObjectPredictionKey? predictionKey=null, bool syncPhysics=true) Attempts to network instantiate a NetworkObject using a GameObject. The supplied GameObject must have a NetworkObject component.
- StartGame (StartGameArgs args) Starts the local Fusion Runner and takes care of all major setup necessary.
- TryFindBehaviour (NetworkBehaviourId bref, out NetworkBehaviour behaviour) Get the NetworkBehaviour instance for this NetworkRunner from a NetworkBehaviourId.
์์ธ
Runner ์ง์ ์ปดํฌ๋ํธ
- NetworkRunner ์ปดํฌ๋ํธ ์์ ์, ๋ชจ๋ ์์ SimulationBehaviour ์ปดํฌ๋ํธ ๋ฑ๋ก
โ FixedUpdateNetwork(), Render() ์ฝ๋ฐฑ - INetworkRunnerCallback ์ธํฐํ์ด์ค๋ฅผ ๊ตฌํํ๋ ๋ชจ๋ ์์ ์ปดํฌ๋ํธ ์ฝ๋ฐฑ ๋ฑ๋ก
1. ๋ด์ฅ Fusion Runner ์ปดํฌ๋ํธ
- HitBoxManager ๋ฐํ์์ ์๋์ผ๋ก ์ถ๊ฐ / ํํธ๋ฐ์ค์ ํํธ๋ฐ์ค ํ์คํ ๋ฆฌ ๊ด๋ฆฌ
- RunnerLagCompensationGizmos ์ง์ฐ ๋ณด์ ๊ธฐ์ฆ๋ชจ ํ์ฑํ
- RunnerAOIGizmos ๊ด์ฌ์์ญ(Area Of Interest) ๊ธฐ์ฆ๋ชจ ํ์ฑํ
- RunnerEnableVisibility
- ๋ค์ค Peer ๋ชจ๋์์ Runner ๊ฐ์์ฑ ํ์ฑํ
- ๋ชจ๋ Scene ๋ฐ ์คํฐ๋ ๊ฒ์ ์ค๋ธ์ ํธ๊ฐ ๊ฐ์์ฑ ์ฒ๋ฆฌ๋ฅผ ์ํด ๋ฑ๋ก
- Runner Visibility Controls ์ฐฝ ์๋์ ํ์
์ฌ์ฉ์ ์ ์ SimulationBehaviour Runner ์ปดํฌ๋ํธ
NetworkRunner ๊ฒ์ ์ค๋ธ์ ํธ์ ์ถ๊ฐ(๋ ์ค ํ๋)
- SimulationBehaviour ์์๋ฐ๋ ์ปดํฌ๋ํธ
- INetworkRunnerCallbacks ๊ตฌํํ๋ ์ปดํฌ๋ํธ
โ NetworkRunner.StartGame() ํธ์ถ ์ NetworkRunner ์ธ์คํด์ค์ ์๋ ๋ฑ๋ก ํ, ์ ์ ํ ์์ ์ ๊ด๋ จ ์ฝ๋ฐฑ ํธ์ถ
Player / PlayerRef ๊ตฌ์กฐ์ฒด
- [์ ์ฉ ์๋ฒ/๊ณต์ ๋ชจ๋ ๊ฒ์ ์๋ฒ ์ ์ธ] ๋ชจ๋ Peer๋ ์ ๋ ฅ์ ์ ๊ณตํ๋ ์ฌ์ฉ์๋ก ๊ฐ์ฃผ
- NetworkRunner์๋ ๊ด๋ จ๋ PlayerRef ๊ตฌ์กฐ์ฒด ๊ฐ ๋ณด์
- ๋ก์ปฌ(ํด๋ผ์ด์ธํธ) PlayerRef = Runner.LocalPlayer
- ์๋ฒ PlayerRef.None
- PlayerRef
- ๋คํธ์ํฌ ์ค๋ธ์ ํธ์ ๋ํ Peer์ ์ ๋ ฅ/์ํ ๊ถํ ๋ณด์ ์ฌ๋ถ
- RPC(Remote Procedure Calls)์ Peer์ ์ง์ ํ๋ ๋ฐ ์ฌ์ฉ
๋คํธ์ํฌ ์ฐ๊ฒฐ
- Peer ์ฐ๊ฒฐ ๋ฐ ์ ์ก ์ฒ๋ฆฌ
- ๋งค์น๋ฉ์ดํน ์๋ฒ, ๋ฃธ ์๋ฒ, ๊ฒ์ ์๋ฒ์ ๋ํ ์ฐ๊ฒฐ ๊ด๋ฆฌ
Tick ๊ด๋ฆฌ
- Tick simulation, re-simulation ๊ฒฐ์
- Tick simulation ์ FixedUpdateNetwork(), simulation ๊ด๋ จ๋ ์ด๋ฒคํธ ํธ์ถ
๋คํธ์ํฌ ์ค๋ธ์ ํธ ๊ด๋ฆฌ
๋คํธ์ํฌ ์ค๋ธ์ ํธ Lifecycle(spawn, despawn etc), replication, Scene management, all networking, ๊ด๋ จ ์ฝ๋ฐฑ ๊ด๋ฆฌ
Phycis Scene, ๊ด์ฌ (์์ญ) ๊ด๋ฆฌ
์ด๋ฒคํธ ํจ์
๋ชจ๋ NetworkBehaviour ์ด๋ฒคํธ์ ํ์ด๋ฐ ์ธ๊ทธ๋จผํธ๋ NetworkRunner ์ปดํฌ๋ํธ์์ ์์
- SimulationBehabiour ๊ฐ์ ์ด๋ฒคํธ ์ฝ๋ฐฑ ํจ์
- FixedUpdateNetwork()
- Render()
- NetworkBehaviour ๊ฐ์ ์ด๋ฒคํธ ์ฝ๋ฐฑ ํจ์
- Spawned()
- Despawned()
- ์ถ๊ฐ์ ์ผ๋ก ์ด๋ฒคํธ ์ฝ๋ฐฑ์ ๊ตฌํ ๊ฐ๋ฅํ๊ฒ ํด ์ฃผ๋ ์ธํฐํ์ด์ค
- IAfterSpawned
- IBeforeAllTicks
- IAfterAllTicks
- IBeforeTick
- IAfterTick
- IPlayerJoined
- IPlayerLeft