Tank Game Unity Client Project

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.

๐Ÿ“‹ Table of Contents

Prerequisites

Before building this Unity client project, you must have completed the Tank Server Setup from the previous documentation and have the following components installed.

Required Directory Structure

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/

Required Software Installation

  1. Unity Hub and Unity Editor (2021.3 LTS or newer recommended)
  2. ProudNet Unity Tank Client Sample Package - Available from GitHub at https://github.com/Nettention/proudnet_sample_tank_server/releases/tag/0.99
  3. Completed Tank Server - From the previous server setup documentation

ProudNet Unity Tank Client Sample Package Location

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

Complete Unity 6 Sample Repository

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:

  1. Clone the repository: git clone https://github.com/Nettention/proudnet_sample_tank_unity_client.git
  2. Open the project in Unity 6 (or Unity 2021.3 LTS+)
  3. Open scene: Assets/Proundnet_Demo/DemoScene/Demo_Networkd_Game_Desert.unity
  4. Ensure tank server is running
  5. Click Play to test immediately

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.

Game WebGL Build Demo

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:

Project Structure

๐ŸŽฎ Unity Project Assets

Contains Unity-specific game assets and ProudNet integration components.

Contents:

Key Components:

๐ŸŒ Network Features

Unity client implementation with ProudNet networking.

Features:

Supported Platforms:

๐Ÿ”„ Protocol Compatibility

Uses identical protocol definitions from the tank server project.

Shared Components:

Development Notes

Getting Started

Prerequisites Verification

Before starting, ensure you have:

  1. Completed Tank Server Setup - Follow the server documentation to set up either C# or C++ server
  2. Running Tank Server - Have a tank server running and accessible
  3. ProudNet Installation - ProudNet folder with Unity package available
  4. Unity Hub and Editor - Unity 2021.3 LTS or newer installed

1. Unity Project Creation and Setup

Step 1: Create New Unity Project

Create a new Unity project for the tank client:

Using Unity Hub:

  1. Open Unity Hub
  2. Click "New Project"
  3. Select "3D" template
  4. Set Project Name: Tank Unity Client
  5. Set Location: project_root/tank_unity_client/
  6. Click "Create project"

Expected Project Structure:

tank_unity_client/
โ”œโ”€โ”€ Assets/
โ”œโ”€โ”€ Packages/
โ”œโ”€โ”€ ProjectSettings/
โ””โ”€โ”€ UserSettings/

Step 2: Import Unity Tank Template

Import Unity's official tank tutorial project as the base template:

Via Unity Asset Store:

  1. Open Window > Asset Store in Unity Editor
  2. Search for "Tanks! Complete Project"
  3. Navigate to: https://assetstore.unity.com/packages/essentials/tutorial-projects/tanks-complete-project-46209
  4. Click "Add to My Assets" (if not already owned)
  5. In Unity Editor, open Window > Package Manager
  6. Select "My Assets" from dropdown
  7. Find "Tanks! Complete Project"
  8. Click "Download" then "Import"

Import Options:

Unity Tank Complete Project Import

Unity Tank Complete Project Import

Step 3: Test Single-Player Template

Verify the imported tank template works correctly:

  1. Open Main Scene: Navigate to unity_tank_client\Assets\_Tanks\Tutorial_Demo\Demo_Scenes\Demo_Game_Desert.unity
Unity Tank Demo Scene

Unity Tank Demo Scene

  1. Enter Play Mode: Click the Play button in Unity Editor
  2. Test Controls:
    • WASD: Move tank
    • Space: Hold to charge shot power, release to fire shells

Expected Single-Player Behavior:

2. ProudNet Unity Integration

Step 1: Import ProudNet Unity Tank Client Sample Package

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:

  1. Download tank_unity_client_proudnet_sample.unitypackage from the GitHub release
  2. In Unity Editor, go to Assets > Import Package > Custom Package...
  3. Navigate to the downloaded tank_unity_client_proudnet_sample.unitypackage
  4. Select the package file and click "Open"
  5. In the import dialog, select "All" to import all components
  6. Click "Import" to add ProudNet to the project
ProudNet Unity Tank Client Sample Package Import

ProudNet Unity Tank Client Sample Package Import

Step 2: Verify ProudNet Installation

Check that ProudNet components are properly integrated:

Sample Assets Installation Verification:

  1. Verify the following folder structure exists:
    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:

  1. Select each DLL in Assets/Plugins/
  2. In Inspector, verify Platform settings:
    • Windows: Enabled for x86_64 (Standalone Windows)

Step 3: Configure Network Settings

Set up basic network configuration for tank game:

Create Network Configuration:

  1. Right-click in Project window
  2. Select Create > ProudNet > Network Config
  3. Name it TankNetworkConfig
  4. Configure the following settings:
    • Server IP: 127.0.0.1 (localhost for testing)
    • Server Port: 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).

2.5. PIDL Integration Workflow (Optional but Recommended)

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:

  1. Have access to the Tank.PIDL file from the Common folder
  2. Run ProudNet/util/PIDL.exe -cs Tank.PIDL -outdir Generated
  3. Manually copy the generated files to the Unity directories

Protocol Compatibility Benefits:

3. Tank Multiplayer Integration

Step 1: Network Scripts Overview

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):

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:

Step 2: Open Pre-configured Multiplayer Scene

The Unity tank client includes a pre-configured multiplayer scene with ProudNet integration:

Open the Network-Ready Scene:

  1. Navigate to Assets\Proundnet_Demo\DemoScene\
  2. Open Demo_Networkd_Game_Desert.unity scene
  3. This scene is already configured with all necessary networking components
ProudNet Network Demo Scene

ProudNet Network Demo Scene

Step 3: Verify Network Configuration (Optional)

The scene is pre-configured, but you can verify or modify the network settings if needed:

GameNetworkManager Settings (Already Configured):

  1. Select GameNetworkManager GameObject in hierarchy
  2. In Inspector, view GameNetworkManager component settings:
    • Server IP: 127.0.0.1 (localhost for testing)
    • Server Port: 33334 (TCP for standalone builds)
    • WebSocket Port: 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]
    • Auto Connect On Start: Enabled for automatic connection
GameNetworkManager Inspector

GameNetworkManager Inspector

Customization Options:

4. Testing Multiplayer Functionality

Step 1: Start Tank Server

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

Step 2: Test Unity Client Connection

Test the Unity client connection to the tank server:

Unity Editor Testing:

  1. Click Play button in Unity Editor
  2. Observe connection status in Unity Console and Game view

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

Unity Game Initial Screen

Step 3: Multi-Client Testing

Test multiplayer functionality with multiple Unity clients:

Second Unity Instance:

  1. Build Unity Project: Go to File > Build and Run
  2. Configure Build Settings:
    • Target Platform: PC, Mac & Linux Standalone
    • Architecture: x86_64
    • Scenes: Add Demo_Networkd_Game_Desert.unity scene
  3. Build: Click "Build and Run" to create standalone executable
  4. Run Standalone: This creates a second client instance. After successful build, you can run the game directly from the build location (e.g., Build/unity_tank_client.exe)
Windows Standalone Build Settings

Windows Standalone Build Settings

Build Completed

Build Completed

Multi-Client Gameplay

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)

5. Multiplayer Features Testing

Movement Synchronization Testing

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)

Firing and Projectile Testing

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)

P2P Chat System Testing

Test real-time messaging between players:

Client 1 Actions:

Client 2 Observations:

Health and Damage Testing

Test health synchronization and damage effects:

Damage Scenario:

Expected Results:

6. WebGL Deployment (Optional)

WebGL Build Configuration

Deploy the Unity tank client as a web application:

Build Settings:

  1. Go to File > Build Settings
  2. Select WebGL platform
  3. Click "Switch Platform"
  4. Add Scenes: Ensure Demo_Networkd_Game_Desert.unity is included
  5. Configure ProudNet Plugin Settings (Important!)
  6. Configure WebGL Player Settings (Important!)
WebGL Build Settings

WebGL Build Settings

ProudNet Plugin Configuration for WebGL

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

  1. Navigate to Assets/Plugins/ProudNet/
  2. Select ProudDotNetClientUnity.dll
  3. In Inspector โ†’ Platform settings:
    • Editor: โŒ (unchecked)
ProudNet .NET DLL Platform Settings

ProudNet .NET DLL Platform Settings

Step 2: Disable Editor for x86_64 DLLs

  1. Navigate to Assets/Plugins/ProudNet/x86_64/
  2. Select ProudNetClient.dll:
    • Editor: โŒ (unchecked)
  3. Select ProudNetClientPlugin.dll:
    • Editor: โŒ (unchecked)
ProudNet x86_64 DLL Platform Settings

ProudNet x86_64 DLL Platform Settings

Step 3: Enable Editor for WebGL Files

  1. Navigate to Assets/Plugins/ProudNet/WebGL/
  2. Select JSClient.jslib:
    • Editor: โœ“ (checked)
    • WebGL: โœ“ (checked)
  3. Select NewJSClient.jslib:
    • Editor: โœ“ (checked)
    • WebGL: โœ“ (checked)
  4. Select ProudNetClientPlugin-webgl.dll:
    • Editor: โœ“ (checked)
    • WebGL: โœ“ (checked)
ProudNet WebGL Files Platform Settings

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.

WebGL Player Settings Configuration

Configure Unity's WebGL-specific settings for optimal local testing:

Publishing Settings (Critical for Local Testing):

  1. Go to Edit > Project Settings > Player > WebGL Settings
  2. Expand Publishing Settings section
  3. Set Compression Format: Disabled
    • This is essential for local web server testing
    • Compressed builds may not work with simple HTTP servers
    • Can be re-enabled for production deployment
WebGL Publishing Settings

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:

WebGL Network Configuration

WebGL Network Configuration

WebGL Testing

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:

  1. Click "Build" in Build Settings
  2. Create or select any folder for output folder : eg- WebGL_Build/
  3. Wait for build completion (may take several minutes)

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. Install Extension:
    • Open VS Code
    • Go to Extensions (Ctrl+Shift+X)
    • Search for "Live Server" by Ritwick Dey
    • Click "Install"
  2. Host WebGL Build:
    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:

  1. Open web browser
  2. Navigate to http://localhost:8000
  3. Game loads in browser with WebGL
  4. Same multiplayer functionality as desktop version

Expected WebGL Behavior:

WebGL Browser Gameplay

WebGL Browser Gameplay

Troubleshooting

Common Issues and Solutions:

Connection Issues

ProudNet Integration Issues

Build Issues

WebGL Issues

Debugging Tools:

Getting Help: