Unity Integration Examples

Complete C# examples for Unity with HTTP client and JSON handling

Available Examples

Download and integrate these C# scripts into your Unity project to quickly get started with the IDCGames API.

ExampleUsage

8.1 KB

Subscribe to events

ExampleUsage.cs Sep 15, 2025
Download Script

LoginResponse

25.9 KB

Main API manager for IDCGames integration in Unity

IDCGamesAPIManager.cs Sep 27, 2025
Download Script

IDCGamesGamingPanelExample

11.4 KB

Example implementation showing how to use IDCGamesAPIManager

IDCGamesGamingPanelExample.cs Sep 25, 2025
Download Script

Prerequisites

Unity Requirements

  • • Unity Version: 2020.3 LTS or newer
  • • Platform: Windows, macOS, or Linux
  • • Scripting Backend: IL2CPP or Mono

Required Packages

Install the following package from Unity Package Manager:

Newtonsoft.Json

Required for JSON serialization/deserialization

Installation steps:

  1. Open Unity Package Manager (Window → Package Manager)
  2. Click the "+" button in the top-left corner
  3. Select "Add package by name..."
  4. Enter: com.unity.nuget.newtonsoft-json
  5. Click "Add" to install

Alternative: Manual Installation

If Package Manager doesn't work, add to your manifest.json:

{
  "dependencies": {
    "com.unity.nuget.newtonsoft-json": "3.2.1"
  }
}

API Configuration

Before using the API, configure these values in the inspector:

  • • Base URL: https://gamepanel.idcgames.com/api/v1
  • • Game Secret: Your game's secret token
  • • Game ID: Your game's unique identifier

Integration Guide

1

Install Prerequisites

Make sure you have installed Newtonsoft.Json package (see Prerequisites above)

Package Name: com.unity.nuget.newtonsoft-json
Version: 3.2.1 or newer
2

Download Scripts

Download the C# scripts from the examples above

IDCGamesAPIManager.cs - Main API manager script
IDCGamesGamingPanelExample.cs - Example implementation with UI
3

Add to Unity Project

Place the scripts in your Unity project's Scripts folder

Assets/Scripts/IDCGames/
Create the folder structure if it doesn't exist
4

Configure API Settings

Set up the API configuration in the inspector

Base URL: https://gamepanel.idcgames.com/api/v1
Game Secret: Your game's secret token
Game ID: Your game's unique identifier
5

Start Using the API

Use the API manager in your scripts

var api = IDCGamesAPIManager.Instance;

// Simple sandbox login (default parameters)
api.Login();

// Or with custom parameters
api.Login("sandbox", null, null, "MyPlayer", "player@example.com");

api.OnLoginComplete += (success) => {
    if (success) {
        api.GetUserStats();
    }
};

Code Examples

Authentication

// Login using third-party authentication
public void Login()
{
    var api = IDCGamesAPIManager.Instance;
    api.OnLoginComplete += (success) => {
        if (success) {
            Debug.Log("Login successful!");
            // Tokens are automatically saved
        }
    };
    
    // Example 1: Simple sandbox login (default parameters)
    api.Login();
    
    // Example 2: Sandbox with custom username
    api.Login("sandbox", null, null, "MyCustomPlayer");
    
    // Example 3: Real platform login (Steam)
    api.Login("steam", "steam_token_123", "steam_user_456", "SteamPlayer", "player@example.com");
    
    // Example 4: IDC platform with full customization
    api.Login("idc", "idc_token_789", "idc_user_101", "IDCPlayer", "player@idc.com", "US", "en");
}

// Refresh token when needed
public void RefreshToken()
{
    var api = IDCGamesAPIManager.Instance;
    api.RefreshToken();
}

Shop Integration

// Get shop items
public void GetShopItems()
{
    var api = IDCGamesAPIManager.Instance;
    api.GetShopItems((items) => {
        foreach (var item in items) {
            Debug.Log($"Item: {item.Name} - Price: {item.Price}");
        }
    });
}

// Buy shop item
public void BuyItem(int itemId, int quantity = 1)
{
    var api = IDCGamesAPIManager.Instance;
    api.BuyShopItem(itemId, quantity, (success) => {
        if (success) {
            Debug.Log("Item purchased successfully!");
        }
    });
}

Stats Submission

// Submit game statistics
public void SubmitGameStats()
{
    var api = IDCGamesAPIManager.Instance;
    
    var sessionStats = new Dictionary {
        {"kills", 5},
        {"deaths", 2},
        {"assists", 3},
        {"wins", 1},
        {"score", 1500}
    };
    
    var eventProgress = new Dictionary {
        {"event_1", 10},
        {"event_2", 5}
    };
    
    api.SubmitGameStats(sessionStats, eventProgress, (success) => {
        if (success) {
            Debug.Log("Stats submitted successfully!");
        }
    });
}

Inventory Management

// Get player inventory
public void GetInventory()
{
    var api = IDCGamesAPIManager.Instance;
    api.GetInventory((inventoryResponse) => {
        if (inventoryResponse.success) {
            Debug.Log($"Total items: {inventoryResponse.stats.total_items}");
            Debug.Log($"Unique items: {inventoryResponse.stats.unique_items}");
            
            // Display category statistics
            foreach (var category in inventoryResponse.category_stats) {
                Debug.Log($"{category.Key}: {category.Value.count} items");
            }
            
            // Display inventory items
            foreach (var item in inventoryResponse.inventory) {
                Debug.Log($"Item: {item.shop_object.name}");
                Debug.Log($"Quantity: {item.quantity}");
                Debug.Log($"Status: {item.attributes.status}");
                Debug.Log($"Purchased: {item.attributes.purchased_at}");
                
                // Display item properties
                if (item.shop_object.content != null) {
                    foreach (var prop in item.shop_object.content) {
                        Debug.Log($"{prop.Key}: {prop.Value}");
                    }
                }
            }
        }
    });
}

// Example JSON Response Structure:
/*
{
    "success": true,
    "inventory": [
        {
            "shop_object": {
                "id": 19,
                "name": "AK-47",
                "soft_coin_cost": 2700,
                "currency_type": "gold",
                "content": {
                    "damage": "36",
                    "accuracy": "73",
                    "rarity": "epic"
                }
            },
            "quantity": 1,
            "attributes": {
                "shop_item_price_id": 1,
                "status": "active",
                "purchased_at": "2025-09-25 11:25:21",
                "purchase_price": 0
            }
        }
    ],
    "category_stats": {
        "Principal": {"count": 1, "total_quantity": 1}
    },
    "stats": {
        "total_items": 1,
        "unique_items": 1,
        "total_value": 0
    }
}
*/

Features

Core Features

  • • Singleton Pattern: Easy access from anywhere
  • • Event System: Subscribe to API events
  • • Auto Token Management: Automatic refresh
  • • Error Handling: Comprehensive error management
  • • JSON Parsing: Automatic response parsing

API Support

  • • Authentication: Login, refresh, validate
  • • Shop System: Browse, buy items
  • • Inventory System: Get inventory with detailed stats
  • • Stats System: Submit and retrieve
  • • Rewards System: Daily rewards
  • • User Management: Profile updates