3.9 KiB
Network Connection Features
This project provides multiple ways to connect to multiplayer servers by IP address, both in the editor and in standalone builds.
Features
1. Editor Window (NetworkConnectionWindow)
A dedicated Editor window for managing network connections with a GUI.
How to Use:
- Open via:
Window > Network > Connection Manageror pressCtrl+Shift+N/Cmd+Shift+N - Features:
- Select connection mode (Host/Client/Server)
- Enter server IP and port
- Start/Stop network connections
- View connection status
- Save/load connection settings
2. NetworkConnectionHelper Component
A MonoBehaviour component with custom inspector for quick network control.
How to Use:
- Add
NetworkConnectionHelpercomponent to any GameObject in your scene - Configure settings in Inspector:
- Server IP (for client mode)
- Port
- Auto-start options
- Use inspector buttons to:
- Start Host
- Start Server
- Start Client
- Disconnect
- View real-time connection status and network info
3. NetworkJoinUI Component
In-game UI for connecting to servers by IP (works in both editor and standalone builds).
How to Use:
- Create UI elements:
- InputField for IP address
- InputField for port
- Buttons: Join, Host, Disconnect
- Text for status display
- Add
NetworkJoinUIcomponent to a GameObject - Assign UI references in Inspector
- Press
Jkey (default) to toggle the UI panel - Connect using the UI buttons
4. AutoHost Component (Updated)
Auto-starts as host in editor mode (configurable).
How to Use:
- Add
AutoHostcomponent to any GameObject - Settings:
Enable Auto Host: Enable/disable auto-startOnly In Editor: Only auto-start in editor (not in standalone builds)
Setup Instructions
For Editor Testing:
Option A: Using Editor Window (Recommended)
- Open
Window > Network > Connection Manager - Select mode:
HostorClient - Enter IP/port if needed
- Click
StartorConnect
Option B: Using NetworkConnectionHelper
- Add
NetworkConnectionHelpercomponent to your scene - Use Inspector buttons to control connections
- For auto-start on play, enable
Auto Start As Host
Option C: Using AutoHost (Original Behavior)
- Keep or add
AutoHostcomponent - It will auto-start as host when playing in editor
For Standalone Builds:
Option A: Using NetworkJoinUI (In-Game UI)
- Add
NetworkJoinUIcomponent with UI references - Build and run
- Press
Jto open connection panel - Enter IP and connect
Option B: Using NetworkConnectionHelper
- Add
NetworkConnectionHelpercomponent - Set
Auto Start As Host = trueandOnly In Editor = false - Build - it will auto-start as host
Connection Modes
Host
- Acts as both server and client
- Can host multiplayer games
- Players connect to your IP
Client
- Connects to an existing server
- Requires server IP address
Server
- Server-only mode (no player)
- Used for dedicated servers
Network Info Display
All connection methods display:
- Current mode (Host/Client/Server)
- Connection status
- IP address and port
- Number of connected clients
- Local Client ID
Tips
-
Testing Multiplayer Locally:
- Use
127.0.0.1orlocalhostfor local testing - Or use your local IP for testing on same network
- Use
-
Default Port:
- Default port is
7777 - Change in any connection component's settings
- Default port is
-
Firewall:
- Ensure port is open for network connections
- Windows Firewall may block connections
-
Multiple Editor Instances:
- Use Unity's
ParrelSyncor run multiple standalone builds - Each instance needs different settings
- Use Unity's
Integration
All features integrate with existing NetworkManager and NetworkConnectionHandler:
- Player spawning is handled automatically
- Connection approval is handled by
NetworkConnectionHandler - Compatible with existing multiplayer systems