Last updated: 2023-09-25 11:00:53Download PDF
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:
Custom video rendering
Device management and music/audio effects
For details about the APIs and their parameters, see Overview.
Unity 2020.2.1f1c1 is recommended.
Supported platforms: Android, iOS, Windows, macOS (alpha testing)
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
Step 1. Create an application
1. Log in to the TRTC console and select RTC Engine on the left sidebar.
2. Click Start now, enter an application name such as
APIExample. If you already have an application, click link existing application.
3. Add or edit tags according to your actual business needs and click Create application.
step 2. Get your SDKAppId and SecretKey
After your application created, you can get your SDKAppID and SecretKey on Basic informaction. SDKAppID and SecrentKey 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
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
SECRETKEY: A placeholder by default. Set it to the actual key.
The method for generating
UserSigdescribed in this document involves configuring
SECRETKEYin the client code. In this method,
SECRETKEYmay 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
UserSiginto your server and provide an application-oriented API. When
UserSigis needed, your application can send a request to your server for a dynamic
UserSig. For more information, see How do I calculate
Step 5. Compile and run the demo
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.
enterRoomfirst 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.
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 –
SoundTouch.xcframework, and click Embed & Sign.
5. Connect to a real iOS device to debug the project.
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.
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.
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.
The UI of the latest version of the demo may look different.
├─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