Files
Northbound/Assets/Scripts/NETWORK_CONNECTION_README.md

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 Manager or press Ctrl+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:

  1. Add NetworkConnectionHelper component to any GameObject in your scene
  2. Configure settings in Inspector:
    • Server IP (for client mode)
    • Port
    • Auto-start options
  3. Use inspector buttons to:
    • Start Host
    • Start Server
    • Start Client
    • Disconnect
  4. 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:

  1. Create UI elements:
    • InputField for IP address
    • InputField for port
    • Buttons: Join, Host, Disconnect
    • Text for status display
  2. Add NetworkJoinUI component to a GameObject
  3. Assign UI references in Inspector
  4. Press J key (default) to toggle the UI panel
  5. Connect using the UI buttons

4. AutoHost Component (Updated)

Auto-starts as host in editor mode (configurable).

How to Use:

  • Add AutoHost component to any GameObject
  • Settings:
    • Enable Auto Host: Enable/disable auto-start
    • Only In Editor: Only auto-start in editor (not in standalone builds)

Setup Instructions

For Editor Testing:

Option A: Using Editor Window (Recommended)

  1. Open Window > Network > Connection Manager
  2. Select mode: Host or Client
  3. Enter IP/port if needed
  4. Click Start or Connect

Option B: Using NetworkConnectionHelper

  1. Add NetworkConnectionHelper component to your scene
  2. Use Inspector buttons to control connections
  3. For auto-start on play, enable Auto Start As Host

Option C: Using AutoHost (Original Behavior)

  1. Keep or add AutoHost component
  2. It will auto-start as host when playing in editor

For Standalone Builds:

Option A: Using NetworkJoinUI (In-Game UI)

  1. Add NetworkJoinUI component with UI references
  2. Build and run
  3. Press J to open connection panel
  4. Enter IP and connect

Option B: Using NetworkConnectionHelper

  1. Add NetworkConnectionHelper component
  2. Set Auto Start As Host = true and Only In Editor = false
  3. 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

  1. Testing Multiplayer Locally:

    • Use 127.0.0.1 or localhost for local testing
    • Or use your local IP for testing on same network
  2. Default Port:

    • Default port is 7777
    • Change in any connection component's settings
  3. Firewall:

    • Ensure port is open for network connections
    • Windows Firewall may block connections
  4. Multiple Editor Instances:

    • Use Unity's ParrelSync or run multiple standalone builds
    • Each instance needs different settings

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