简体中文 | English
This document shows 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/voice effects
For details about API features and parameters, please see Client APIs > Unity > Overview.
- Unity 2020.2.1f1 is recommended.
- Supported platforms: Android, iOS, Windows, macOS
- 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 above
- A valid developer signature for your project
- Log in to the TRTC console and select Application Management > Create application.
- Click Create Application and enter the application name such as
APIExample
. If you have already created an application, click Select Existing Application. - Add or edit tags according to your actual business needs and click Create.
An application name can contain up to 15 characters. Only digits, letters, Chinese characters, and underscores are allowed.
Tags are used to identify and organize your Tencent Cloud resources. For example, an enterprise may have multiple business units, each of which has one or more TRTC applications. In this case, the enterprise can tag TRTC applications to mark out the unit information. Tags are optional and can be added or edited according to your actual business needs.
- Download the SDK and demo source code for your platform.
- Click Next.
- In the Modify Configuration step, select the development platform in line with the source package downloaded.
- Find and open
TRTC-Simple-Demo/Assets/TRTCSDK/Demo/Tools/GenerateTestUserSig.cs
. - Set parameters in
GenerateTestUserSig.cs
as follows: - Click Next to complete the creation.
- After compilation, click Return to Overview Page.
- Open Unity Editor, go to File > Build Settings, and select Android for Platform.
- Connect to a real Android device and click Build And Run to run the demo.
- 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.
- Open
TRTC Build Configuration
(You can find it in the navigation bar at the top of the unity editor) - Click
IOS
,Wait for project generation to complete - Use Xcode to open the generated 'Unity-iPhone.xcodeproj' project
- Download TRTC SDK.You need to manually add the dynamic libraries. Click General, expand Frameworks, Libraries, and Embedded Content, and click the + icon at the bottom to add the dynamic libraries required in turn: FFmpeg.xcframework, and SoundTouch.xcframework. Click Embed & Sign.
- Connects IOS device for debugging
- Open Unity Editor, go to File > Build Settings, and select PC, Mac & Linux Standalone for Platform and Windows for Target Platform.
- Click Build And Run to run the demo.
- Open Unity Editor, go to File > Build Settings, and select PC, Mac & Linux Standalone for Platform, and macOS for Target Platform.
- Open Player Setting , change Scripting Backend to IL2CPP
- Click Build And Run to run the 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.
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