tencent cloud

Feedback

Last updated: 2024-05-13 10:43:55
    This document shows you how to integrate the TRTC SDK in Unity to enable audio/video calls in games.
    The demo includes the following features:
    Room entry/exit
    Custom video rendering
    Device management and music/audio effects
    Note
    For details about the APIs and their parameters, see Overview.
    Unity 2020.2.1f1c1 is recommended.
    Supported platforms: Android, iOS, Windows, macOS (alpha testing)
    Modules required: Android Build Support, iOS Build Support, Windows Build Support, MacOS Build Support .
    If you are developing for iOS, you also need:
    Xcode 11.0 or later
    A valid developer signature for your project

    Directions

    Step 1. Create an application

    1. Log in to the TRTC console overview page, click Create Application.
    2. In the popup page, select RTC Engine, enter the application name, and then click Create.
    
    
    

    Step 2. Get your SDKAppId and SecretKey

    After your application created, you can get your SDKAppID and SDKSecretKey on Basic informaction. SDKAppID and SDKSecretKey is needed for running demo.
    
    
    

    Step 3. Download the sample code

    1. Go to GitHub to download the SDK and demo source code.
    git clone https://github.com/LiteAVSDK/TRTC_Unity.git
    2. The steps to import SDK can refer to Unity SDK import.

    Step 4. Configure the project

    1. Open the file downloaded previously, find and open TRTC-Simple-Demo/Assets/TRTCSDK/Demo/Tools/GenerateTestUserSig.cs, and set the following parameters:
    SDKAPPID: A placeholder by default. Set it to the actual SDKAppID.
    SDKSECRETKEY: A placeholder by default. Set it to the actual key.
    Note
    The method for generating UserSig described in this document involves configuring SDKSECRETKEY in the client code. In this method, SDKSECRETKEY may be easily decompiled and reversed, and if your key is disclosed, attackers can steal your Tencent Cloud traffic. Therefore, this method is only suitable for the local execution and debugging of TRTC-Simple-Demo.
    The best practice is to integrate the calculation code of UserSig into your server and provide an application-oriented API. When UserSig is needed, your application can send a request to your server for a dynamic UserSig. For more information, see How do I calculate UserSig during production?.

    Step 5. Compile and run the demo

    Android

    1. Open Unity Editor, go to File > Build Settings, and select Android for Platform.
    
    
    2. Connect to a real Android device and click Build And Run to run the demo.
    3. Call enterRoom first and go on to test other APIs. The data display window shows whether the call is successful, and the other window displays the callback information.

    iOS

    1. Open the TRTC build and configuration tool (from the menu at the top).
    2. Click Build & Configure iOS to generate a project.
    
    
    3. Open the project generated (Unity-iPhone.xcodeproj) with Xcode.
    4. Download the underlying TRTC SDK. Click General, select Frameworks, Libraries, and Embedded Content, click + at the bottom to add the dynamic libraries required – FFmpeg.xcframework and SoundTouch.xcframework, and click Embed & Sign.
    
    
    5. Connect to a real iOS device to debug the project.

    Windows

    1. Open Unity Editor, go to File > Build Settings, and select PC, Mac & Linux Standalone for Platform, and Windows for Target Platform.
    
    
    2. Click Build And Run to run the demo.

    macOS

    1. Open Unity Editor, go to File > Build Settings, and select PC, Mac & Linux Standalone for Platform, and macOS for Target Platform.
    
    
    2. Click Build And Run to run the demo.
    3. To use the simulator feature of Unity Editor, you must install Device Simulator Package.
    4. Click Windows > General > Device Simulator.
    
    

    Demo

    The demo integrates most of the APIs launched so far, which can be used for testing and as reference for API calls. For more information about APIs, see Client APIs > Unity > Overview.
    Note
    The UI of the latest version of the demo may look different.

    Directory Structure

    ├─Assets
    ├── Editor // Unity Editor script
    │ ├── BuildScript.cs // Unity Editor build menu
    │ ├── IosPostProcess.cs // Script for building iOS application in Unity Editor
    ├── Plugins
    │ ├── Android
    │ │ ├── AndroidManifest.xml //Android configuration file
    ├── StreamingAssets // Audio/Video stream files for the Unity demo
    ├── TRTCSDK
    ├── Demo // Unity demo
    ├── SDK // TRTC SDK for Unity
    ├── Implement // Implementation of TRTC SDK for Unity
    ├── Include // Header files of TRTC SDK for Unity
    └── Plugins // Underlying implementation of TRTC SDK for Unity for different platforms
    
    Contact Us

    Contact our sales team or business advisors to help your business.

    Technical Support

    Open a ticket if you're looking for further assistance. Our Ticket is 7x24 avaliable.

    7x24 Phone Support