A multiplayer tank game Unity client implementation using ProudNet networking library, built upon Unity's official tank tutorial template with enhanced multiplayer and chat functionality.
Before building this Unity client project, you must have completed the Tank Server Setup from the previous documentation and have the following components installed.
project_root/ โโโ tank_server/ # Server project (from previous setup) โ โโโ Common/ โ โโโ Server/ โ โโโ Client/ โ โโโ Server_CPP/ โโโ ProudNet/ # Required: Files from ProudNet installation โ โโโ doc/ โ โโโ include/ โ โโโ lib/ โ โโโ Sample/ โ โโโ util/ โโโ tank_unity_client/ # This Unity project (to be created) โโโ Assets/ โโโ Packages/ โโโ ProjectSettings/
The ProudNet Unity Tank Client Sample Package can be downloaded from:
https://github.com/Nettention/proudnet_sample_tank_server/releases/tag/0.99 File: tank_unity_client_proudnet_sample.unitypackage
For those who prefer to skip the manual setup process, a complete Unity 6 sample project with all integration steps already completed is available at:
GitHub Repository: https://github.com/Nettention/proudnet_sample_tank_unity_client
This complete sample repository includes:
Quick Start with Complete Sample:
git clone https://github.com/Nettention/proudnet_sample_tank_unity_client.git
Assets/Proundnet_Demo/DemoScene/Demo_Networkd_Game_Desert.unity
This option is recommended for developers who want to quickly test the multiplayer functionality without going through the complete integration process described in this documentation.
Experience the ProudNet Tank Game directly in your browser! This is a live WebGL build of the Unity client connecting to a real multiplayer server hosted on AWS.
Game Features Demonstrated:
Technical Details:
Contains Unity-specific game assets and ProudNet integration components.
Contents:
Key Components:
Plugins/
- ProudNet DLL files for UnityScripts/Network/
- ProudNet integration scriptsProudnet_Demo/
- Sample game scenes with multiplayer supportUnity client implementation with ProudNet networking.
Features:
Supported Platforms:
Uses identical protocol definitions from the tank server project.
Shared Components:
Before starting, ensure you have:
Create a new Unity project for the tank client:
Using Unity Hub:
Tank Unity Client
project_root/tank_unity_client/
Expected Project Structure:
tank_unity_client/ โโโ Assets/ โโโ Packages/ โโโ ProjectSettings/ โโโ UserSettings/
Import Unity's official tank tutorial project as the base template:
Via Unity Asset Store:
Import Options:
Unity Tank Complete Project Import
Verify the imported tank template works correctly:
unity_tank_client\Assets\_Tanks\Tutorial_Demo\Demo_Scenes\Demo_Game_Desert.unity
Unity Tank Demo Scene
Expected Single-Player Behavior:
Import the ProudNet Unity Tank Client Sample Package to add networking capabilities:
Expected Package File:
tank_unity_client_proudnet_sample.unitypackage
Import Package in Unity:
tank_unity_client_proudnet_sample.unitypackage
from the GitHub releasetank_unity_client_proudnet_sample.unitypackage
ProudNet Unity Tank Client Sample Package Import
Check that ProudNet components are properly integrated:
Sample Assets Installation Verification:
Assets/ โโโ Plugins/ โ โโโ ProudNet/ # Contains ProudNet DLLs โ โโโ ProudNetClientUnity.dll โ โโโ Andorid/ โ โโโ WebGL/ โ โโโ x86_64/ โโโ ProudNet_Demo/ # Demo scene and scripts โ โโโ DemoScene/ โ โโโ ProudNetScripts/ โโโ Scripts/ โโโ Network/ # Network-related scripts
Platform Settings Verification:
Assets/Plugins/
Set up basic network configuration for tank game:
Create Network Configuration:
TankNetworkConfig
127.0.0.1
(localhost for testing)33334
(matches tank server port)Network Configuration Details:
TankNetworkConfig Connection Settings:
Note: We will use port 33334 for standalone builds initially. Later for WebGL builds, we'll use the WebSocket port 33335 which is only available in the C++ server implementation (the C# server does not support WebSocket connections).
If you completed the server setup from the previous documentation, you can reuse the generated PIDL files:
Option A: Copy from Server Project (Recommended)
If you have the tank server project available, use the convenience batch script:
# Navigate to tank_server directory cd tank_server # Run the copy script copy_client_generated_to_unity.bat
What the script does:
Copies from tank_server/: โโโ Server/Tank_stub.cs โ unity_tank_client/Assets/Proundnet_Demo/ProudNetScripts/Generated/ โโโ Server/Tank_proxy.cs โ unity_tank_client/Assets/Proundnet_Demo/ProudNetScripts/Generated/ โโโ Server/Tank_common.cs โ unity_tank_client/Assets/Proundnet_Demo/ProudNetScripts/Generated/ โโโ Common/Vars.cs โ unity_tank_client/Assets/Proundnet_Demo/ProudNetScripts/Common/
Expected Output:
===== ProudNet Generated Files Unity Copy Script ===== Copying PIDL generated files... 1 file(s) copied. 1 file(s) copied. 1 file(s) copied. Copying common files... 1 file(s) copied. Copy completed! The following files have been copied to Unity project: - ..\unity_tank_client\Assets\Proundnet_Demo\ProudNetScripts\Generated\Tank_stub.cs - ..\unity_tank_client\Assets\Proundnet_Demo\ProudNetScripts\Generated\Tank_proxy.cs - ..\unity_tank_client\Assets\Proundnet_Demo\ProudNetScripts\Generated\Tank_common.cs - ..\unity_tank_client\Assets\Proundnet_Demo\ProudNetScripts\Common\Vars.cs Press any key to continue...
Option B: Manual PIDL Generation (If no server project)
If you don't have the server project, you would need to:
Tank.PIDL
file from the Common folderProudNet/util/PIDL.exe -cs Tank.PIDL -outdir Generated
Protocol Compatibility Benefits:
The tank Unity client uses a comprehensive networking system built on ProudNet RMI (Remote Method Invocation). Here's the actual script structure:
Core Network Scripts:
Assets/ โโโ Scripts/Network/ โ โโโ GameNetworkManager.cs # Main network manager (Singleton) โ โโโ NetworkTank.cs # Individual tank network synchronization โโโ Proundnet_Demo/ProudNetScripts/ โ โโโ Common/ โ โ โโโ Vars.cs # Protocol version and server configuration โ โโโ Generated/ # Auto-generated from Tank.PIDL โ โโโ Tank_common.cs # RMI message IDs and constants โ โโโ Tank_proxy.cs # Client-to-server RMI calls โ โโโ Tank_stub.cs # Server-to-client RMI handlers
GameNetworkManager.cs - Main Features:
NetworkTank.cs - Individual Tank Features:
Generated RMI Classes (from Tank.PIDL):
SendMove
, SendFire
, SendTankHealthUpdated
)OnTankPositionUpdated
, OnSpawnBullet
, OnPlayerJoined
)Important Note: The files in Generated/
folder are the exact same files generated during the C# server implementation in the previous documentation. This ensures 100% protocol compatibility between the server and Unity client. The Unity client reuses the identical PIDL-generated networking code.
Key Network Features Implemented:
The Unity tank client includes a pre-configured multiplayer scene with ProudNet integration:
Open the Network-Ready Scene:
Assets\Proundnet_Demo\DemoScene\
Demo_Networkd_Game_Desert.unity
sceneProudNet Network Demo Scene
The scene is pre-configured, but you can verify or modify the network settings if needed:
GameNetworkManager Settings (Already Configured):
127.0.0.1
(localhost for testing)33334
(TCP for standalone builds)33335
(for WebGL builds only) [Note: This setting is hidden in the inspector for standalone builds but will be used later when building for WebGL]GameNetworkManager Inspector
Customization Options:
Before testing the Unity client, ensure your tank server is running:
C++ Server
cd tank_server/Server_CPP run.bat
Expected Server Output:
========== Tank Server Started ========== TCP Server listening on 0.0.0.0:33334 WebSocket Server listening on 0.0.0.0:33335/ws Ready to accept connections from all network interfaces ========================================== Server is running. Commands: status: Show connected clients
Test the Unity client connection to the tank server:
Unity Editor Testing:
Expected Server Response:
Client connected: Host ID = 6 New tank created for client 6 with tank type -1 and health 100.000000/100.000000 Not enough clients to create P2P group (need at least 2) ========== SendTankType Received ========== From client 6: tankType=-1 ========== SendTankType Processing Completed ==========
Unity Game View:
Unity Game Initial Screen
Test multiplayer functionality with multiple Unity clients:
Second Unity Instance:
Demo_Networkd_Game_Desert.unity
sceneBuild/unity_tank_client.exe
)Windows Standalone Build Settings
Build Completed
Multi-Client Gameplay
Alternative Testing Method:
Expected Multi-Client Behavior:
Unity Client 1 (Editor): [ProudNet] Connected to server successfully [ProudNet] Assigned Client ID: 6 [P2P] Other player joined: Client ID 7 [TankGame] Tank Type Selected: 1 (health: 225) [TankGame] Remote tank spawned for player 7 (Type: 0, health: 150) Unity Client 2 (Standalone): [ProudNet] Connected to server successfully [ProudNet] Assigned Client ID: 7 [P2P] Other player joined: Client ID 6 [TankGame] Tank Type Selected: 0 (health: 150) [TankGame] Remote tank spawned for player 6 (Type: 1, health: 225)
Server Log with Multiple Clients:
Client connected: Host ID = 6 New tank created for client 6 with tank type -1 and health 100.000000/100.000000 Not enough clients to create P2P group (need at least 2) Client connected: Host ID = 7 New tank created for client 7 with tank type -1 and health 100.000000/100.000000 Sending existing player info to new client: ID=6, Type=-1, Health=100.000000/100.000000 P2P group created with 2 members, Group ID: 8 ========== Tank Selection and Spawning ========== ========== SendTankSpawned Received ========== From client 6: position=(20.959999,11.930000), direction=212.665558, tankType=1, health=225.000000 Tank spawned for client 6 at (20.959999,11.930000) ========== SendTankSpawned Received ========== From client 7: position=(20.959999,11.930000), direction=212.665558, tankType=0, health=150.000000 Tank spawned for client 7 at (20.959999,11.930000)
Test real-time tank movement across multiple clients:
Client 1 Actions:
Client 2 Observations:
Expected Network Messages:
Client 1 โ Server: SendMove(posX: 15.2, posY: 30.1, direction: 45) Server โ Client 2: OnTankPositionUpdated(clientId: 3, posX: 15.2, posY: 30.1, direction: 45)
Test shell firing synchronization:
Client 1 Actions:
Client 2 Observations:
Expected Network Messages:
Client 1 โ Server: SendFire(shooterId: 3, direction: 180, launchForce: 25, posX: 15.2, posY: 30.1) Server โ Client 2: OnSpawnBullet(clientId: 3, shooterId: 3, direction: 180, force: 25, ...) Server โ All: OnTankHealthUpdated(clientId: 4, health: 85, maxHealth: 100)
Test real-time messaging between players:
Client 1 Actions:
"Hello from Client 1!"
Client 2 Observations:
"Player: Hello from Client 1!"
Test health synchronization and damage effects:
Damage Scenario:
Expected Results:
Deploy the Unity tank client as a web application:
Build Settings:
Demo_Networkd_Game_Desert.unity
is includedWebGL Build Settings
After switching to WebGL platform, you must configure ProudNet plugin settings:
Important WebGL Limitation: ProudNet does not support in-editor play mode when the WebGL platform is selected. You must build and deploy the WebGL version to test networking functionality. Editor play mode will not work for network testing on WebGL platform.
Step 1: Disable Editor for .NET DLL
Assets/Plugins/ProudNet/
ProudDotNetClientUnity.dll
ProudNet .NET DLL Platform Settings
Step 2: Disable Editor for x86_64 DLLs
Assets/Plugins/ProudNet/x86_64/
ProudNetClient.dll
:
ProudNetClientPlugin.dll
:
ProudNet x86_64 DLL Platform Settings
Step 3: Enable Editor for WebGL Files
Assets/Plugins/ProudNet/WebGL/
JSClient.jslib
:
NewJSClient.jslib
:
ProudNetClientPlugin-webgl.dll
:
ProudNet WebGL Files Platform Settings
Critical: If these settings are not configured correctly, the WebGL build will fail or the networking will not function properly.
Configure Unity's WebGL-specific settings for optimal local testing:
Publishing Settings (Critical for Local Testing):
WebGL Publishing Settings
Recommended WebGL Settings:
Publishing Settings: โโโ Compression Format: Disabled (for local testing) โโโ Name Files As Hashes: โ (unchecked) โโโ Data Caching: โ (unchecked) โโโ Debug Symbols: Off โโโ Power Preference: High Performance Memory Settings: โโโ Initial Memory Size (MB): 32 โโโ Maximum Memory Size (MB): 2048 โโโ Memory Growth Mode: Geometric โโโ Geometric Memory Growth Cap (MB): 96
Tip: For production deployment, you can enable Gzip compression format to reduce download sizes, but disable it for local testing to avoid server compatibility issues.
Network Configuration for WebGL:
ws://localhost:33335/ws
(local testing)ws://your-server.com:33335/ws
WebGL Network Configuration
Test the web version of the tank client:
Note: Remember that ProudNet networking does not function in Unity Editor play mode when WebGL platform is selected. You must complete the full build process to test networking features.
Build Process:
WebGL_Build/
Local Web Server Setup:
Important: WebGL builds must be hosted on a web server and cannot be played by directly opening the HTML file locally.
Method 1: Python HTTP Server
# Navigate to WebGL build folder cd WebGL_Build/ # Python 3 (recommended) python -m http.server 8000 # Python 2 (if Python 3 not available) python -m SimpleHTTPServer 8000 # Custom port example python -m http.server 3000
Expected Python Output:
Serving HTTP on 0.0.0.0 port 8000 (http://0.0.0.0:8000/) ... 127.0.0.1 - - [23/May/2024 10:30:15] "GET / HTTP/1.1" 200 - 127.0.0.1 - - [23/May/2024 10:30:15] "GET /Build/unity_tank_client.wasm HTTP/1.1" 200 -
Method 2: VS Code Live Server Extension
1. Open WebGL_Build/ folder in VS Code 2. Right-click on index.html 3. Select "Open with Live Server" 4. Browser opens automatically at http://127.0.0.1:5500
Method 3: Node.js http-server (Alternative)
# Install globally (one-time setup) npm install -g http-server # Navigate to build folder and serve cd WebGL_Build/ http-server -p 8000 # With CORS enabled (if needed) http-server -p 8000 --cors
Access URLs:
Web Browser Testing:
http://localhost:8000
Expected WebGL Behavior:
WebGL Browser Gameplay
Common Issues and Solutions:
Assets/Plugins/
folderDebugging Tools:
Getting Help:
ProudNet/doc/
folder