This project is a fully-featured VR multiplayer game designed to run on a local area network (LAN) without any reliance on an internet connection. It leverages Unity's powerful engine, Netcode for GameObjects for networking, and the XR Interaction Toolkit for immersive VR interactions. This documentation outlines the core scripts and systems that work together to create a seamless, synchronized, and interactive offline experience.
LAN Network Discovery
The foundation of the offline experience is the ability for players to find each other on the same local network. This is achieved through a UDP broadcast-based discovery system.
- Server Advertisement: A host server periodically sends out a UDP broadcast message, announcing its presence on the LAN.
- Client Discovery: Clients listen for these broadcasts or can send out their own request to find active servers.
- Direct Connection: Once a server is discovered, the client receives the necessary connection info (IP address) to establish a direct connection using the primary network transport.
- Internet-Free: This entire process is confined to the local network, meaning no internet connection is required for players to connect and play together.
Network Managers
A suite of manager scripts orchestrates the entire network session, from initial connection to in-game state management.
AuthenticationManager
Handles player authentication, supporting anonymous sign-in and unique identification through command-line arguments for multi-instance testing.
LobbyManager
Manages lobby creation, joining, and data synchronization. It acts as the bridge between the lobby service, relay, and the underlying Unity Transport layer.
NetworkManagerVRMultiplayer
The core network manager, inheriting from Unity's `NetworkManager`. It's configured specifically for this VR project, handling logging and ensuring the app can run in the background.
VoiceChatManager
Integrates Vivox services for in-game voice chat, managing microphone permissions, channel connections, and spatialized audio settings.
XRINetworkGameManager
A high-level singleton that oversees the entire game session, managing connection states, matchmaking, and player data, tying all other managers together.
LocalLobbyManager
Extends `LobbyManager` to provide functionality for local testing by allowing the creation of mock lobbies without a full network setup.
XR Player & Avatar System
This system handles the representation and synchronization of players in the virtual world, ensuring movements and actions are seen by everyone.
XRINetworkPlayer
The core player script. It manages essential player data like name, color, and voice ID. It synchronizes this data and handles player-specific events like spawning and disconnecting.
XRAvatarIK
Manages the avatar's Inverse Kinematics (IK). It realistically positions the head and body, ensuring the avatar's movements follow the player's head tracking data smoothly.
XRAvatarVisuals
Controls the visual appearance of the avatar. It handles rendering the head, swapping materials for the local player (so they don't see their own avatar's head), and displaying special visuals for the host.
XRHandPoseReplicator
Synchronizes detailed hand and finger movements. It offers multiple fidelity levels to balance visual accuracy with network bandwidth, supporting both hand tracking and controller inputs.
Networked XR Interactions
These scripts extend Unity's XR Interaction Toolkit to ensure that interactions with objects are synchronized across all clients.
NetworkBaseInteractable
The foundational script for all networked interactables. It synchronizes core events like hover, select, and activate, and manages object ownership to prevent conflicts between players.
NetworkPhysicsInteractable
Extends the base interactable for physics-based objects. It handles synchronizing forces and velocities. A key feature is collision-based ownership, allowing players to intuitively grab objects by touching them.
NetworkSocketInteractor
Synchronizes the behavior of `XRSocketInteractor` components. This ensures that when one player snaps an object into a socket, all other players see the object correctly placed.
Synchronized UI Elements
A set of scripts to ensure that standard UI elements are synchronized for all players, creating a shared interface experience.
NetworkedButton
Propagates button clicks across the network, ensuring a single click triggers the event for everyone.
NetworkedDropdown
Synchronizes the selected value of a dropdown menu using a `NetworkVariable`.
NetworkedSlider
Keeps a slider's value consistent across all clients, perfect for shared settings.
NetworkedToggle
Synchronizes the on/off state of a toggle switch for all players.
Network Utilities
A collection of utility scripts that provide essential, reusable networking functionality for various in-game objects and scenarios.
ClientNetworkTransform
A flexible extension of `NetworkTransform` that allows specifying client or server authority for object movement.
NetworkBillboard
Makes a 2D object always face the player who owns it, ideal for nameplates or dynamic info displays.
NetworkProjectileLauncher
Manages the spawning and firing of projectiles, synchronizing their path and effects across the network.
NetworkTrigger
Synchronizes trigger events, allowing an action to be invoked on all clients when one player enters a specific area.
NetworkXRKnob & NetworkXRLever
Synchronize the state of interactive XR controls like knobs and levers, ensuring all players see the same state.